Quantcast

iText IKVM C# stream to browser issues

classic Classic list List threaded Threaded
55 messages Options
123
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

iText IKVM C# stream to browser issues

henslecd
Until iTextSharp is in sync with iText, I am using iText with IKVM to get the dll's I need.

I just have a couple questions that should be straight forward.  I need to know what to change in the following code (where commented out) to get the pdf to stream to a browser.  

        //in iTextSharp, this line would be a MemoryStream
        //java.io.OutputStream newpdf; //new FileOutputStream("c:\\temp\\test.pdf");

        com.lowagie.text.pdf.PdfReader pdfReader = new com.lowagie.text.pdf.PdfReader("http://ServerURL/Oldpdf.pdf");
        com.lowagie.text.pdf.PdfStamper pdfStamper = new com.lowagie.text.pdf.PdfStamper(pdfReader, newpdf);
        com.lowagie.text.pdf.AcroFields pdfFormFields = pdfStamper.getAcroFields();// AcroFields;

        pdfFormFields.setField("NAME_FIRST", "Test");

        pdfStamper.setFormFlattening(true);
        pdfStamper.close();

        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=nameofpdf.pdf");
        Response.Buffer = true;
        Response.Clear();

        //There is no such method as GetBuffer in the java.io.OutputStream object
        //Response.OutputStream.Write(newpdf.GetBuffer(), 0, newpdf.GetBuffer().Length);

        Response.OutputStream.Flush();
        Response.End();

Thanks for any help you can provide.  

Chad
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: iText IKVM C# stream to browser issues

henslecd
I got the following to work, but it is still giving me this error.

"This document contained certain rights to enable special features in Adobe Reader. The document has been changed since it was created and these rights are no longer valid. Please contact the author for the original version of this document."

ByteArrayOutputStream baos = new ByteArrayOutputStream();

        com.lowagie.text.pdf.PdfReader pdfReader = new com.lowagie.text.pdf.PdfReader("http://ServerURL/newpdf.pdf");

        com.lowagie.text.pdf.PdfStamper pdfStamper = new com.lowagie.text.pdf.PdfStamper(pdfReader, baos);

        com.lowagie.text.pdf.AcroFields pdfFormFields = pdfStamper.getAcroFields();

        pdfFormFields.setField("NAME_FIRST", "Chad");
 
        //This doesn't seem to work
        //pdfStamper.setFormFlattening(false);

        pdfStamper.close();

        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=vha-10-2850-fill.pdf");
        Response.Buffer = true;
        Response.Clear();
        Response.OutputStream.Write(baos.toByteArray(), 0, baos.size());

        Response.OutputStream.Flush();
        Response.End();


From what I read, the latest iText was supposed to keep this error from happening in Adobe 9.   iTextSharp just hadn't caught up to it.

Will iText or iTextSharp ever allow us to fill a PDF template (written with the newest Adobe Designer), edit it in browser, and save it to desktop with those changes?  All the while being opened by Adobe 8, 9 and and up?

Thanks for your feedback.

Chad

henslecd wrote
Until iTextSharp is in sync with iText, I am using iText with IKVM to get the dll's I need.

I just have a couple questions that should be straight forward.  I need to know what to change in the following code (where commented out) to get the pdf to stream to a browser.  

        //in iTextSharp, this line would be a MemoryStream
        //java.io.OutputStream newpdf; //new FileOutputStream("c:\\temp\\test.pdf");

        com.lowagie.text.pdf.PdfReader pdfReader = new com.lowagie.text.pdf.PdfReader("http://ServerURL/Oldpdf.pdf");
        com.lowagie.text.pdf.PdfStamper pdfStamper = new com.lowagie.text.pdf.PdfStamper(pdfReader, newpdf);
        com.lowagie.text.pdf.AcroFields pdfFormFields = pdfStamper.getAcroFields();// AcroFields;

        pdfFormFields.setField("NAME_FIRST", "Test");

        pdfStamper.setFormFlattening(true);
        pdfStamper.close();

        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=nameofpdf.pdf");
        Response.Buffer = true;
        Response.Clear();

        //There is no such method as GetBuffer in the java.io.OutputStream object
        //Response.OutputStream.Write(newpdf.GetBuffer(), 0, newpdf.GetBuffer().Length);

        Response.OutputStream.Flush();
        Response.End();

Thanks for any help you can provide.  

Chad
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: iText IKVM C# stream to browser issues

iText Software
henslecd wrote:
> I got the following to work, but it is still giving me this error.
>
> "This document contained certain rights to enable special features in Adobe
> Reader. The document has been changed since it was created and these rights
> are no longer valid. Please contact the author for the original version of
> this document."

This is explained in the FAQ:
http://1t3xt.info/tutorials/faq.php?branch=faq.itext&node=enabled_form

--
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

The document has been changed since it was created and these rights are no longer valid

rajeev2012
I have checked the link and have implemented the suggested code, yet I get the same ...the document has been changed since it was created and these rights are no longer valid ....

Anybody has any clue, how to resolve this issue
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

iText Software
On 22/08/2010 18:00, rajeev2012 wrote:
>
> I have checked the link and have implemented the suggested code, yet I get
> the same ...the document has been changed since it was created and these
> rights are no longer valid ....
>
> Anybody has any clue, how to resolve this issue

Not if you don't show us the original PDF.
Also: some PDF forms have special features that make
it impossible to fill them out without breaking the
usage rights. In those rare cases, the original PDF
should be rebuild using Acrobat/Designer.

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

rajeev2012
Sir,

Form1B.PDF

Please find attached, the  file that we are getting from our Govt. and we need to fill in the relevant data in it and submit the same. If I insert data manually and opt for 'save/save as', it worked perfectly fine.

But, the same doesn't work and give above said message, if we try to fill data through .NET program (from database)


Regards
Rajeev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

iText Software
rajeev2012 wrote:

> Sir,
>
> http://itext-general.2136553.n4.nabble.com/file/n2334791/Form1B.PDF
> Form1B.PDF
>
> Please find attached, the  file that we are getting from our Govt. and we
> need to fill in the relevant data in it and submit the same. If I insert
> data manually and opt for 'save/save as', it worked perfectly fine.
>
> But, the same doesn't work and give above said message, if we try to fill
> data through .NET program (from database)
Please take a look at the attached file.
As a test, I've written a small iText app that has this line:
form.setField("Form1B_Dtls[0].page1[0].CompanyName_C[0]", "My Company");
As you can see, the "save/save as" is still active.

I think you didn't read the documentation. Please purchase the 2nd
edition of "iText in Action" and read section 8.6. DO NOT ASK for a code
sample, the code sample is in the book.

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

iTextFilledFile.pdf (223K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

rajeev2012
Sir,

I had checked the book and have written below code (with the line that you had put) to meet this requirement, but still I do get the same error message, when I try to open newly created file (Please see attached)newFile.pdf

try
          {
                string ip = @"C:\Documents and Settings\Raj\Desktop\Forms\Form1B.PDF";
                string op = @"C:\Documents and Settings\Raj\Desktop\Forms\newFile.pdf";
                iTextSharp.text.pdf.PdfReader pr = new iTextSharp.text.pdf.PdfReader(ip);
                System.IO.FileStream fs = new FileStream(op, System.IO.FileMode.CreateNew, FileAccess.ReadWrite);
                iTextSharp.text.pdf.PdfStamper ps = new iTextSharp.text.pdf.PdfStamper(pr, fs, '\0', true);
                iTextSharp.text.pdf.AcroFields pf = ps.AcroFields;
                pf.SetField("Form1B_Dtls[0].page1[0].CompanyName_C[0]", "My Company");
                ps.Close();
                fs.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception: " + ex.Message);
            }

What am I missing ? The version of iText ???

Regards
Rajeev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

iText Software
rajeev2012 wrote:
> Sir,
>
> I had checked the book and have written below code

That's almost exactly the code I have (but I have it in Java).

> (with the line that you
> had put) to meet this requirement, but still I do get the same error
> message,

The result I get was sent in attachment.

> when I try to open newly created file (Please see attached)
> http://itext-general.2136553.n4.nabble.com/file/n2334924/newFile.pdf
> newFile.pdf

I see the problem, but I can't reproduce it.

> What am I missing ? The version of iText ???

I don't know. You could try upgrading, but if I can't reproduce
a problem using iText, then I can't help.

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

rajeev2012
Ok sir,
I will check with upgraded iText and i hope this is not a platform (.NET) related issue.
In case, if it works fine in JAVA but not in .NET then do we we have any other option ?

Regards
Rajeev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

rajeev2012
Sir,

I have tried it with the latest iTextSharp (5.04) but still I am having the said issue :(

Regards
Rajeev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

iText Software
rajeev2012 wrote:
> Sir,
>
> I have tried it with the latest iTextSharp (5.04) but still I am having the
> said issue :(

One thing I noticed:
When you fill out one field in the form using iTextSharp,
your file is 149 KB.
When I fill out the same field in the form using iText,
the file is 163 KB.
That's a significant difference.

I think you should look at this difference, and fix the problem
in iTextSharp. If you have found the fix, please post it back to
this list so that other people can be helped too.

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

Keith O

> Date: Mon, 23 Aug 2010 14:39:40 +0200
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [iText-questions] The document has been changed since it was created and these rights are no longer valid
>
> rajeev2012 wrote:
> > Sir,
> >
> > I have tried it with the latest iTextSharp (5.04) but still I am having the
> > said issue :(
>
> One thing I noticed:
> When you fill out one field in the form using iTextSharp,
> your file is 149 KB.
> When I fill out the same field in the form using iText,
> the file is 163 KB.
> That's a significant difference.
>
> I think you should look at this difference, and fix the problem
> in iTextSharp. If you have found the fix, please post it back to
> this list so that other people can be helped too.

Maybe it's the PDF file? Tried OP's example code with iTextSharp 5.0.4.0, "newFile.pdf" is 163KB. Also, the Chapter 8 example, part2.chapter08.ReaderEnabledForm worked with all iTextSharp  5.XX versions, and just confirmed it works with iTextSharp 5.0.4.0 too.
     
------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

rajeev2012
In reply to this post by rajeev2012
Sir,

I have tried it with JAVA and t worked. But, the problem is my project is in .NET (C#), hence have got stuck on this point.

Any suggestion ....

Regards
Rajeev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

iText Software
rajeev2012 wrote:
> Sir,
>
> I have tried it with JAVA and t worked. But, the problem is my project is in
> .NET (C#), hence have got stuck on this point.
>
> Any suggestion ....

Your only option is to hire somebody who compares what happens in iText
with what happens in iTextSharp, and fixes the problem.

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

iText Software
In reply to this post by Keith O
Keith O wrote:
> Maybe it's the PDF file?

The OP has posted the PDF file.
I used it with iText and it works.
(This is confirmed by the OP who tried iText.)
So the PDF file is OK.

> Tried OP's example code with iTextSharp 5.0.4.0, "newFile.pdf" is 163KB.
> Also, the Chapter 8 example, part2.chapter08.ReaderEnabledForm worked
> with all iTextSharp  5.XX versions, and just confirmed it works with iTextSharp 5.0.4.0 too.

Am I understanding this correct when I interpret this as:
the problem can't be reproduced using iTextSharp either?
In that case, the problem may be something outside iTextSharp.

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

Keith O

> Date: Mon, 23 Aug 2010 17:00:02 +0200
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [iText-questions] The document has been changed since it was created and these rights are no longer valid
>
> Keith O wrote:
> > Maybe it's the PDF file?
>
> The OP has posted the PDF file.
> I used it with iText and it works.
> (This is confirmed by the OP who tried iText.)
> So the PDF file is OK.

That's what I get for not reading the entire thread.

> > Tried OP's example code with iTextSharp 5.0.4.0, "newFile.pdf" is 163KB.
> > Also, the Chapter 8 example, part2.chapter08.ReaderEnabledForm worked
> > with all iTextSharp 5.XX versions, and just confirmed it works with iTextSharp 5.0.4.0 too.
>
> Am I understanding this correct when I interpret this as:
> the problem can't be reproduced using iTextSharp either?
> In that case, the problem may be something outside iTextSharp.

Sorry, I should have been clearer; the reason I thought it was a problem with the OP's PDF file is because I used the referenced book example code (converted to C#) with supplied resource file you created (xfa_enabled.pdf). All 5.XX versions of iTextSharp correctly preserve the usage rights of **that** PDF file.
     
------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

iText Software
Keith O wrote:
> the reason I thought it was a problem with the OP's PDF file is
> because I used the referenced book example code (converted to C#)
> with supplied resource file you created (xfa_enabled.pdf).
> All 5.XX versions of iTextSharp correctly preserve the usage
> rights of **that** PDF file.

Thanks for the clarification.
The most important information for me is that the book example works
with the provided PDF and iTextSharp. I have no idea why the OP's PDF
works with iText but not with iTextSharp. Just a guess: maybe the
problem is caused by an external problem, for instance: the way a stream
is compressed (this is a very wild guess).

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

Paulo Soares-3
The problem was with the XML serializer in .NET that did not preserved the whitespaces correctly in some cases. It's fixed in the SVN.
 
Paulo
----- Original Message -----
Sent: Monday, August 23, 2010 4:55 PM
Subject: Re: [iText-questions] The document has been changed since it was created and these rights are no longer valid

Keith O wrote:
> the reason I thought it was a problem with the OP's PDF file is
> because I used the referenced book example code (converted to C#)
> with supplied resource file you created (xfa_enabled.pdf).
> All 5.XX versions of iTextSharp correctly preserve the usage
> rights of **that** PDF file.

Thanks for the clarification.
The most important information for me is that the book example works
with the provided PDF and iTextSharp. I have no idea why the OP's PDF
works with iText but not with iTextSharp. Just a guess: maybe the
problem is caused by an external problem, for instance: the way a stream
is compressed (this is a very wild guess).

------------------------------------------------------------------------------
This SF.net email is sponsored by

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: The document has been changed since it was created and these rights are no longer valid

Keith O

> From: [hidden email]
> To: [hidden email]
> Date: Tue, 24 Aug 2010 00:46:20 +0100
> Subject: Re: [iText-questions] The document has been changed since it
> was created and these rights are no longer valid
>
> The problem was with the XML serializer in .NET that did not preserved
> the whitespaces correctly in some cases. It's fixed in the SVN.

XmlDomWriter, nice!

It looks like Microsoft chose to replace newlines with \r\n by default. If CR is the only problem this works too:

XmlWriterSettings settings = new XmlWriterSettings();
settings.NewLineHandling = NewLineHandling.Entitize;
settings.OmitXmlDeclaration = true;
XmlWriter xw = XmlWriter.Create(fout, settings);
...
     
------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users
worldwide. Take advantage of special opportunities to increase revenue and
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/
123
Loading...