|
View:
New views
13 Messages
—
Rating Filter:
Alert me
|
| < Prev | 1 - 2 | Next > |
|
|
Re: Generation of Multiple Page PDF Document is slowGaneshPrakhya wrote:
>Hi Bruno, > >As you said in the previous thread (Abhishek's): > >"There are other ways to do it, and the book will give you >another example using setField and setFieldCache, but >the procedure described above is faster because it cuts >a lot of corners. > >best regards, >Bruno" > >I am exactly doing the same, I followed all your steps. Can you suggest me >how to use setField and setFieldCache for setting AcroForm fields over >multiple pages. If you can give me an example code, that will be great for >me. > http://itext.ugent.be/articles/eid-pdf/ (see the example at the bottom), but I only found the time to write a description. Meanwhile maybe setFieldCache can help. Just create a HashMap outside the loop that sets the fields: HashMap fieldCache = new HashMap(); Inside the loop you do: form = stamper.getAcroFields(); form.setFieldCache(fieldcache); form.setField(...); This should improve the performance. (Although not as drastically as the modus operandi that is described without a code sample.) br, Bruno ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ iText-questions mailing list iText-questions@... https://lists.sourceforge.net/lists/listinfo/itext-questions |
|
|
Re: Generation of Multiple Page PDF Document is slowHi Bruno,
Excellent!!!! You are an amazing guy, my code is working and I am able to generate records with multiple pages. I will try your cacheing example also. I decided to buy your book :) Thanks a lot, Ganesh.
|
|
|
Re: Generation of Multiple Page PDF Document is slowHi Bruno,
The example you suggested is working fine for me. However, the targent document was around 4MB in size with 100 pages. I tried the samething with same template using PDFLib, the document PDFLib created with 100 pages was around 150KB. Is there any approach to reduce the size of the document. I guess the size is due to copying of documents over many pages in the case of iText. Thanks, Ganesh.
|
|
|
Re: Generation of Multiple Page PDF Document is slowGaneshPrakhya wrote:
>Hi Bruno, > >The example you suggested is working fine for me. However, the targent >document was around 4MB in size with 100 pages. > Yes, that's what I meant when I wrote: "There are different ways to achieve this. The most efficient way, would be to retrieve the coordinates of the fields in an onOpenDocument, to add the flattened form in an onStartPage event, and to add the data using a static ColumnText method." If you add the flattened form in an onStartPage event, the data of the 'template' is added only once. This way the filesize is reduced drastically. >I tried the samething with >same template using PDFLib, the document PDFLib created with 100 pages was >around 150KB. Is there any approach to reduce the size of the document. I >guess the size is due to copying of documents over many pages in the case of > I have separate book examples that demonstrate the separate steps in the process described above, but I still have to make an example that combines everything. Maybe I'll find some time this afternoon. If I do, I'll add it to this page: http://itext.ugent.be/articles/eid-pdf/ and I will let you know through the mailinglist. br, Bruno ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ iText-questions mailing list iText-questions@... https://lists.sourceforge.net/lists/listinfo/itext-questions |
|
|
Re: Generation of Multiple Page PDF Document is slowGaneshPrakhya wrote:
>Hi Bruno, > >The example you suggested is working fine for me. However, the targent >document was around 4MB in size with 100 pages. I tried the samething with >same template using PDFLib, the document PDFLib created with 100 pages was >around 150KB. Is there any approach to reduce the size of the document. > OK, the example I referred to before, has only three pages (one per record) and is 14 KB. Now I have added a more efficient example (using a totally different technique), and the result looks the same (it even has page numbers now), but it is only 3KB. http://itext.ugent.be/articles/eid-pdf/ (at the bottom) http://itext.ugent.be/articles/eid-pdf/test/BatchFormFill.java br, Bruno ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ iText-questions mailing list iText-questions@... https://lists.sourceforge.net/lists/listinfo/itext-questions |
|
|
Re: Generation of Multiple Page PDF Document is slowHi Bruno,
Can you just let me know what's wrong in the uploaded template I created. I am not able to merge data eventhough many pages are created. However, its working fine for your templates (EIDFormTemplate.pdf and SimpleRegistrationForm.pdf). Thanks, Ganesh. Template.pdfTemplate.pdf |
|
|
Re: Generation of Multiple Page PDF Document is slowGaneshPrakhya wrote:
>Hi Bruno, > >Can you just let me know what's wrong in the uploaded template I created. > I don't know what you mean by 'uploaded template' (maybe you meant to add an attachment), but I am 99% sure that you created your form with LiveCycle Designer instead of with Acrobat Professional. http://itext.ugent.be/library/question.php?id=31 You probably didn't realize you were using LiveCycle because Designer is started from Acrobat. Note that the comment section of the FAQ is not a good place to ask questions. The comment will be deleted. You asked: 1) is it possible to convert PDF to HTML. Answer: that is not a good idea. PDF is a Page Definition Language. Creating PDF is a OneWay process; the PDF is an end product. A work flow where you use the PDF as source for conversion to another format is based on bad design. 2) iText DOES support the creation of PDF/X documents. 3) PPML is not supported and even Wikipedia doesn't know what you mean by DDF (Disk Data Format?). br, Bruno ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ iText-questions mailing list iText-questions@... https://lists.sourceforge.net/lists/listinfo/itext-questions |
|
|
Re: Generation of Multiple Page PDF Document is slowHi Bruno,
Here is the process I created the template with acro fields. - I created an MS-Word .doc file with labels like name, company etc. - I converted the word document to PDF, I have Adobe Acrobat Professional. - I opened the pdf document I created above and added acro fields. (I suspect, do I need to add any ACRO FORM here before adding acro fields??) - I tried to use this pdf with acro fields as template, and you know the problem, the data is NOT getting populated even though there are pages added with the core content in template. I am attaching the template I just created from scratch. Thanks, Ganesh. OwnTemplate.pdf |
|
|
Re: Generation of Multiple Page PDF Document is slowGaneshPrakhya wrote:
>I am attaching the template I just created from scratch. > > Giving us the template for inspection is a good idea, but unfortunately you forgot to attach it... br, Bruno ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ iText-questions mailing list iText-questions@... https://lists.sourceforge.net/lists/listinfo/itext-questions |
|
|
Re: Generation of Multiple Page PDF Document is slowI attached with Upload File button. I am wondering what happend??? I am able to see the link for the uploaded pdf in the Preview Message also.
let me try again. ganesh. OwnTemplate.pdf |
|
|
|
|
|
Re: Generation of Multiple Page PDF Document is slowHi Bruno,
Finally, here is my scenario. - I have a template with two pages. On first page, I have an acro field for an image, on the second I have three acro fields. - I used your example (BatchFill.java) and able to write document and fill acro fields on both pages. - I am pasting my programme here, when I run this programme, the page 1 and page 2 are getting included in single page. How can we prevent that? Meantime, I even tried to move to next page also, because if I say, System.out.println("page No: " + writer.getPageNumber()); its always showing page 1. - I read your article and not able to understand, probably you are using stamp, I don't want to use it since my file size needs to be limited. I hope you understand my problem. ----- import java.io.FileOutputStream; import java.io.IOException; import java.io.ByteArrayOutputStream; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Element; import com.lowagie.text.Phrase; import com.lowagie.text.Rectangle; import com.lowagie.text.pdf.AcroFields; import com.lowagie.text.pdf.BaseFont; import com.lowagie.text.pdf.ColumnText; import com.lowagie.text.Chunk; import com.lowagie.text.pdf.PdfContentByte; import com.lowagie.text.pdf.PdfImportedPage; import com.lowagie.text.pdf.PdfPTable; import com.lowagie.text.pdf.PdfPageEventHelper; import com.lowagie.text.pdf.PdfReader; import com.lowagie.text.pdf.PdfWriter; import com.lowagie.text.pdf.PdfStamper; import com.lowagie.text.Image; import java.util.HashMap; import java.util.Iterator; public class BatchFill extends PdfPageEventHelper { public static final String IMAGE = "F1[0].P1[0].imagefield[0]"; public static final String DATE = "F1[0].P2[0].date[0]"; public static final String TIME = "F1[0].P2[0].time[0]"; public static final String LOCATION = "F1[0].P2[0].location[0]"; public static final String[] keys = { DATE, TIME, LOCATION }; private Rectangle[] coordinates = new Rectangle[keys.length]; private PdfImportedPage pageOne; private PdfImportedPage pageTwo; private PdfContentByte canvas; int n = 0; public void onOpenDocument(PdfWriter writer, Document doc) { try { canvas = writer.getDirectContentUnder(); PdfReader reader = new PdfReader("D:\\lucky_one_template.pdf"); n = reader.getNumberOfPages(); System.out.println("Total pages: " + reader.getNumberOfPages()); pageOne = writer.getImportedPage(reader, 1); pageTwo = writer.getImportedPage(reader, 2); AcroFields fields = reader.getAcroFields(); HashMap map = fields.getFields(); Iterator itr = map.keySet().iterator(); while (itr.hasNext()) { System.out.println((String)itr.next()); } for (int i = 0; i < keys.length; i++) { float[] positions = fields.getFieldPositions(keys[i]); //System.out.println(positions); //System.out.println("positions: " + positions.length); //System.out.println("--> "+positions[1] +" "+ (positions[2] + 3) +" "+ positions[3] +" "+ (positions[4] + 3)); coordinates[i] = new Rectangle(positions[1], positions[2] + 3, positions[3], positions[4] + 3); } } catch (IOException e) { e.printStackTrace(); } } //Adding core content. public void onEndPage(PdfWriter writer, Document doc) { canvas.addTemplate(pageOne, 0, 0); canvas.addTemplate(pageTwo, 0, 0); } public static void main(String[] args) { String[] values = { "Date", "Time","Location"}; try { //Image adding stuff. PdfReader reader = new PdfReader("D:\\lucky_one_template.pdf"); ByteArrayOutputStream baos = baos = new ByteArrayOutputStream(); PdfStamper stamper = new PdfStamper(reader, baos); AcroFields form = stamper.getAcroFields(); float[] photograph = form.getFieldPositions(IMAGE); Rectangle rect = new Rectangle(photograph[1], photograph[2], photograph[3], photograph[4]); Image img = Image.getInstance("D:\\otsoe(1).jpg"); img.scaleToFit(rect.width(), rect.height()); img.setAbsolutePosition(photograph[1] + (rect.width() - img.scaledWidth()) / 2, photograph[2] + (rect.height() - img.scaledHeight()) / 2); stamper.close(); BatchFill batch = new BatchFill(); Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("D:\\lucky_one_test.pdf")); writer.setPageEvent(batch); document.open(); PdfContentByte contentOne = writer.getDirectContent(); System.out.println("page No: " + writer.getPageNumber()); PdfContentByte contentTwo = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); ColumnText ct = new ColumnText(contentTwo); for (int i = 0; i < 100; i++) { //System.out.println(values.length); contentOne.addImage(img); document.newPage(); for (int j = 0; j < values.length; j++) { // you can add text with ColumnText //System.out.println(batch.coordinates[j].left() +" "+ batch.coordinates[j].bottom() +" "+ batch.coordinates[j].right() +" "+ batch.coordinates[j].top()); ct.setSimpleColumn(new Phrase(values[j]+(i+1)), batch.coordinates[j].left(), batch.coordinates[j].bottom(), batch.coordinates[j].right(), batch.coordinates[j].top(), 16, Element.ALIGN_LEFT); ct.go(); } //document.newPage(); //System.out.println(); } document.close(); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } } } ---- Thanks, ganesh. |
|
|
Re: Generation of Multiple Page PDF Document is slowGaneshPrakhya wrote:
> - I used your example (BatchFill.java) and able to write document and fill acro fields on both pages. > OK, if you have two pages, you will need to keep track of the pages in onEndPage. >Meantime, I even tried to move to next page also, because if I say, >System.out.println("page No: " + writer.getPageNumber()); its always showing page 1. > > That's only possible if nothing was added to the page. newPage is ignored if nothing was added! >coordinates[i] = new Rectangle(positions[1], positions[2] + 3, >positions[3], positions[4] + 3); > > The +3 is an adjustment (Google for setExtraMargin for more info). Also onEndPage is definitely wrong. You need an if statement. > public void onEndPage(PdfWriter writer, Document doc) { > > if (writer.getPageNumber % 2 == 0) { > canvas.addTemplate(pageOne, 0, 0); > > } else { > canvas.addTemplate(pageTwo, 0, 0); > > } I have no idea what you intend to do with contentOne and contentTwo: > PdfContentByte contentOne = writer.getDirectContent(); > > PdfContentByte contentTwo = writer.getDirectContent(); > > There is no difference between contentOne and contentTwo. I don't understand why you do this. It's rather absurd... > contentOne.addImage(img); > > ??? Why are you adding the image here? It's already there isn't it? > document.newPage(); > > What does ct.go() return??? Was anything added to the doc. > ct.go(); > > } > > //document.newPage(); > > When you compile a piece of code that has too many errors, the compiler says: 'too many errors' and it doesn't show you all the errors. Well, I know what the compiler feels like. There are too many errors in your code to give an answer that makes sense... Please take it step by step. Don't write any line of code before you know what it does... br, Bruno ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ iText-questions mailing list iText-questions@... https://lists.sourceforge.net/lists/listinfo/itext-questions |
| < Prev | 1 - 2 | Next > |
| Free embeddable forum powered by Nabble | Forum Help |