RE: [iText-questions] PdfCopy.copyAcroForm wrong method getReaderFile

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

RE: [iText-questions] PdfCopy.copyAcroForm wrong method getReaderFile

Paulo Soares
 

> -----Original Message-----
> From: Andreas Wittek [mailto:[hidden email]]
> Sent: Tuesday, September 27, 2005 10:43 AM
> To: Paulo Soares
> Subject: RE: [iText-questions] PdfCopy.copyAcroForm wrong
> method getReaderFile
>
> Hi,
>
> thank you for your answer. I tried PdfCopyFields now but I
> simply cannot achieve what I want.
>
> What I tried now was:
>
>                 PdfReader formreader = new PdfReader(formpdf);
>                 PdfReader tmplreader = new PdfReader(tmplpdf);
>
>                 tmplreader.removeFields();
>
>                 PdfCopyFields copy = new PdfCopyFields(outpdf);
>
>                 copy.addDocument(tmplreader);
>
>                 // I do not really want to add pages but (if
> possible simply extrakt the form information)
>                 ArrayList al = new ArrayList();
>                 copy.addDocument(formreader,al);
>
>                 copy.close();
>
> What I want is:
>
> a) having two documents, having the same layout one let's say
> in German with form and one in English withtout form
> b) I do not want to put in the form and fields in the English
> document by hand but instead automatize it by just copying
> the form and field information from the German Version to the
> English version.
>
> Is this possible using the defined classes and methods iText?

No.

> Or would I have to look at say PdfCopyFieldsImp an write it myself?
>

Yes.

> Regarding PdfCopy: is copyAcroForm simply obsolete? Don't you

Yes.

> agree, that the Method getReaderFile should be changed in any case?

No. It's obsolete, I won't waste time on that.

>
> Thank you for your help.
>
> Andreas
>
>
> At 15:55 26.09.2005 +0100, you wrote:
> >Forms are not supported with PdfCopy. Use PdfCopyFields.
> >
> >> -----Original Message-----
> >> From: [hidden email]
> >> [mailto:[hidden email]] On
> >> Behalf Of Andreas Wittek
> >> Sent: Monday, September 26, 2005 2:37 PM
> >> To: [hidden email]
> >> Subject: [iText-questions] PdfCopy.copyAcroForm wrong method
> >> getReaderFile
> >>
> >> Hello,
> >>
> >> I am trying to use one PDF-File containing a form as as
> >> template (regarding the form) for other PDFs which have the
> >> same structure as the form document but do not contain a form.
> >>
> >> Like Richard Freedman's  Question on 2005-02-02  I try
> something like
> >>
> >>
> >>     public static void copyFormToPDF(InputStream formpdf,
> >> InputStream tmplpdf, OutputStream outpdf)
> >>           throws IOException {
> >>         // Create document descriptors
> >>       try {
> >>          PdfReader formreader = new PdfReader(formpdf);
> >>          PdfReader tmplreader = new PdfReader(tmplpdf);
> >>
> >>          Document document  = new
> >> Document(tmplreader.getPageSizeWithRotation(1));
> >>          PdfCopy copy = new PdfCopy(document,outpdf);
> >>          document.open();
> >>          int n = tmplreader.getNumberOfPages();
> >>          for (int i = 1; i <= n; i++) {
> >>             copy.addPage(copy.getImportedPage(tmplreader,i));
> >>          }
> >>          copy.copyAcroForm(formreader);
> >>          document.close();
> >>       }
> >>       catch (Exception ex) {
> >>          ex.printStackTrace();
> >>       }
> >>     }
> >>
> >> and I get
> >>
> >> java.lang.ArrayIndexOutOfBoundsException
> >> at java.lang.System.arraycopy(Native Method)
> >> at java.io.BufferedOutputStream.write(Unknown Source)
> >> at
> >> com.lowagie.text.pdf.OutputStreamCounter.write(OutputStreamCou
> >> nter.java:160)
> >> at com.lowagie.text.pdf.PRStream.toPdf(PRStream.java:218)
> >> at
> >> com.lowagie.text.pdf.PdfIndirectObject.writeTo(PdfIndirectObje
> >> ct.java:167)
> >> at com.lowagie.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:370)
> >> at com.lowagie.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:350)
> >> at com.lowagie.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:342)
> >> at com.lowagie.text.pdf.PdfWriter.addToBody(PdfWriter.java:1889)
> >> at com.lowagie.text.pdf.PdfCopy.copyIndirect(PdfCopy.java:195)
> >> at com.lowagie.text.pdf.PdfCopy.copyObject(PdfCopy.java:263)
> >> at com.lowagie.text.pdf.PdfCopy.copyArray(PdfCopy.java:249)
> >> at com.lowagie.text.pdf.PdfCopy.copyObject(PdfCopy.java:265)
> >> at com.lowagie.text.pdf.PdfCopy.copyDictionary(PdfCopy.java:216)
> >> at com.lowagie.text.pdf.PdfCopy.copyObject(PdfCopy.java:261)
> >> at com.lowagie.text.pdf.PdfCopy.copyIndirect(PdfCopy.java:194)
> >> at com.lowagie.text.pdf.PdfCopy.copyObject(PdfCopy.java:263)
> >> at com.lowagie.text.pdf.PdfCopy.copyDictionary(PdfCopy.java:219)
> >> at com.lowagie.text.pdf.PdfCopy.copyObject(PdfCopy.java:261)
> >> at com.lowagie.text.pdf.PdfCopy.copyIndirect(PdfCopy.java:194)
> >> at com.lowagie.text.pdf.PdfCopy.copyObject(PdfCopy.java:263)
> >> at com.lowagie.text.pdf.PdfCopy.copyArray(PdfCopy.java:249)
> >> at com.lowagie.text.pdf.PdfCopy.copyObject(PdfCopy.java:265)
> >> at com.lowagie.text.pdf.PdfCopy.copyDictionary(PdfCopy.java:219)
> >> at com.lowagie.text.pdf.PdfCopy.copyObject(PdfCopy.java:261)
> >> at com.lowagie.text.pdf.PdfCopy.copyIndirect(PdfCopy.java:194)
> >> at com.lowagie.text.pdf.PdfCopy.copyObject(PdfCopy.java:263)
> >> at com.lowagie.text.pdf.PdfCopy.copyArray(PdfCopy.java:249)
> >> at com.lowagie.text.pdf.PdfCopy.copyObject(PdfCopy.java:265)
> >> at com.lowagie.text.pdf.PdfCopy.copyDictionary(PdfCopy.java:219)
> >> at com.lowagie.text.pdf.PdfCopy.copyAcroForm(PdfCopy.java:388)
> >> at rw.util.pdf.PDFFormular.copyFormToPDF(PDFFormular.java:268)
> >> at rw.util.pdf.PDFFormular.copyFormToPDF(PDFFormular.java:247)
> >> at rw.util.pdf.FormCopy.main(FormCopy.java:20)
> >>
> >>
> >> I think I have found the reason for this Problem which is
> >> that PdfCopy uses the inherited Method
> >>
> >>         RandomAccessFileOrArray getReaderFile(PdfReader reader) {
> >>             return currentPdfReaderInstance.getReaderFile();
> >>         }
> >>
> >> from PdfWriter. However, the currentPdfReaderInstance ist the
> >> wrong one, being the one for the PdfReader which does not
> >> contain the form.
> >> This method should be overwritten by something like (compare
> >> to other methods in PdfCopy)
> >>
> >>         RandomAccessFileOrArray getReaderFile(PdfReader reader) {
> >>             if (currentPdfReaderInstance != null) {
> >>                 if (currentPdfReaderInstance.getReader()
> != reader) {
> >>                     try {
> >>                        
> >> currentPdfReaderInstance.getReaderFile().close();
> >>                     }
> >>                     catch (IOException ioe) {
> >>                         // empty on purpose
> >>                     }
> >>                     currentPdfReaderInstance =
> >> reader.getPdfReaderInstance(this);
> >>                 }
> >>             }
> >>             else {
> >>                 currentPdfReaderInstance =
> >> reader.getPdfReaderInstance(this);
> >>             }
> >>             return currentPdfReaderInstance.getReaderFile();
> >>         }
> >>
> >>
> >> When I add this mehtod to PdfCopy the Exception disappears
> >> and the information about the form appears in the output-PDF-file.
> >>
> >> However, the form does not display, when I open that file in
> >> e.g. Acrobat Reader.
> >>
> >> I do not understand enough about the content of PDF-files to
> >> be able to figure out, what goes wrong now.
> >>
> >> Perhaps someone can help me on this?
> >>
> >>
> >> Thanks
> >>
> >> Andreas
> >>
> >> *******************************************************
> >> * Dr. Andreas Wittek
> >> * Ravenworks GbR                email: [hidden email]
> >> * Fahrenheitstr. 1      Tel.: ++49-421-2239700
> >> * 28359 Bremen          Fax.: ++49-421-2239825
> >> * Germany                       http: www.ravenworks.de
> >> *******************************************************
> >>
> >>
> >>
> >> -------------------------------------------------------
> >> SF.Net email is sponsored by:
> >> Tame your development challenges with Apache's Geronimo
> App Server.
> >> Download it for free - -and be entered to win a 42" plasma tv
> >> or your very
> >> own Sony(tm)PSP.  Click here to play:
> >> http://sourceforge.net/geronimo.php
> >> _______________________________________________
> >> iText-questions mailing list
> >> [hidden email]
> >> https://lists.sourceforge.net/lists/listinfo/itext-questions
> >>
>
> *******************************************************
> * Dr. Andreas Wittek
> * Ravenworks GbR                email: [hidden email]
> * Fahrenheitstr. 1      Tel.: ++49-421-2239700
> * 28359 Bremen          Fax.: ++49-421-2239825
> * Germany                       http: www.ravenworks.de
> *******************************************************
>
>


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
itextsharp-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions