Generation of Multiple Page PDF Document is slow

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
35 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Generation of Multiple Page PDF Document is slow

Abhishek Srivastava
Hello all,
 
I am generating a multiple page report using itext. each page of this report is based on a Acroform. My users want this generation to be faster. I am detailing down the steps taken by me. Kindly let me know if the report generation can be faster.
  1. I read the acroform from the DB and cache it in memory.
  2. Create a PdfCopyFields object.
  3. I loop on the student list (each student has one page in the report.)
  4. Create a PDFReader and PDFStamper for the template.
  5. Extract the Acrofields from the template.
  6. Loop on the acrofields  Fill each acro fields
  7. when all acrofields are filled, I close the stamper
  8. I create another PdfReader and call the addDocument method on the PdfCopyFields objects.
this is done for all students, and then I convert the documents to byte array and write in on the HTTP Response stream.
 
Can I improve this by following any other way of generating this report?
 
regards,
Abhishek.

 

 
 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document is slow

blowagie
Abhishek Srivastava wrote:

> Can I improve this by following any other way of generating this report?
>  

Yes, you can. I am doing the same thing for Ghent University.
We have 27.000 students and the document generation is very fast.
Give me some time to distill a code sample from our closed source.
One major error you made, was using PdfCopyFields.
br,
Bruno

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document is slow

blowagie
In reply to this post by Abhishek Srivastava
As promised, this is the procedure I use to create a 27.000+ page document
really fast using an existing 1-page PDF document with a form.

My class Letter extends PdfPageEventHelper.

In the onOpenDocument method
1. I read the existing PDF and retrieve the fields and their coordinates
  I store these coordinates for later use.
2. I read the page into a PdfImportedPage and store this page in a
  member variable 'page'

In the onStartPage method, I do:
writer.getDirectContent().addTemplate(page, 0, 0);

In the main method, I go through the 5 steps of document creation:
1. Document document = new Document();
  (in your case, it would probably be a good idea to retrieve the page
size from the original PDF)
2. PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("new.pdf"));
  Letter letter = new Letter();
  writer.setPageEvent(letter);
3. document.open();
4. I add content
  I loop over all the records in my database and I add it to the PDF
using ColumnText
  the coordinates used in the ColumnText objects, are the ones retrieved
in the onOpenDocument method.
  After each record, I do document.newPage();
  I don't worry about the 'template', the imported page is added
automatically in the page event.
5. document.close();

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

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document is slow

Abhishek Srivastava
Thanks Bruno,
 
could you clarify the following lines in your code snipped
 
Letter letter = new Letter();
 writer.setPageEvent(letter);
 
what is letter over here?
 
regards,
Abhishek.
 
On 8/4/06, bruno <[hidden email]> wrote:
As promised, this is the procedure I use to create a 27.000+ page document
really fast using an existing 1-page PDF document with a form.

My class Letter extends PdfPageEventHelper.

In the onOpenDocument method
1. I read the existing PDF and retrieve the fields and their coordinates
I store these coordinates for later use.
2. I read the page into a PdfImportedPage and store this page in a
member variable 'page'

In the onStartPage method, I do:
writer.getDirectContent().addTemplate(page, 0, 0);

In the main method, I go through the 5 steps of document creation:
1. Document document = new Document();
(in your case, it would probably be a good idea to retrieve the page
size from the original PDF)
2. PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("new.pdf"));
Letter letter = new Letter();
writer.setPageEvent(letter);
3. document.open();
4. I add content
I loop over all the records in my database and I add it to the PDF
using ColumnText
the coordinates used in the ColumnText objects, are the ones retrieved
in the onOpenDocument method.
After each record, I do document.newPage();
I don't worry about the 'template', the imported page is added
automatically in the page event.
5. document.close();

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

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.techsay.com/default.php?page=join.php&amp;p=sourceforge&amp;CID=DEVDEV" target="_blank"> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.sourceforge.net/lists/listinfo/itext-questions" target="_blank">https://lists.sourceforge.net/lists/listinfo/itext-questions


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document is slow

blowagie
Abhishek Srivastava wrote:

> Thanks Bruno,
>  
> could you clarify the following lines in your code snipped
>  
> Letter letter = new Letter();
>  writer.setPageEvent(letter);
>  
> what is letter over here?

Letter is the name of my main class.
It extends PdfPageEventHelper.
That's why it is instantiated and set as PageEvent for the writer.

It is used to take one standard letter (an existing PDF)
and to create a 27.000 page PDF where each page
contains the same letter, but with a different name/address.
We ship this PDF to our printing office and they make sure
the letter is sent to the students.
br,
Bruno

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document is slow

Abhishek Srivastava
PdfReader reader = new PdfReader ("existing.pdf");

Document doc = new Document();

PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("target.pdf"));

PdfImportedPage page = writer.getImportedPage(reader, 1);
throws a null pointer exception at me.
 
here i can see that reader is not null (so existing.pdf was read correctly).
 
regards,
Abhishek.
 
is this the correct way of getting a PdfImportedPage?
 
On 8/4/06, bruno <[hidden email]> wrote:
Abhishek Srivastava wrote:

> Thanks Bruno,
>
> could you clarify the following lines in your code snipped
>
> Letter letter = new Letter();
>  writer.setPageEvent(letter);
>
> what is letter over here?

Letter is the name of my main class.
It extends PdfPageEventHelper.
That's why it is instantiated and set as PageEvent for the writer.

It is used to take one standard letter (an existing PDF)
and to create a 27.000 page PDF where each page
contains the same letter, but with a different name/address.
We ship this PDF to our printing office and they make sure
the letter is sent to the students.
br,
Bruno

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document isslow

Paulo Soares
Where's doc.open()?

Paulo

----- Original Message -----
From: "Abhishek Srivastava" <[hidden email]>
To: "Post all your questions about iText here"
<[hidden email]>
Sent: Friday, August 04, 2006 2:08 PM
Subject: Re: [iText-questions] Generation of Multiple Page PDF Document
isslow


> PdfReader reader = new PdfReader("existing.pdf");
>
> Document doc = new Document();
>
> PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("
> target.pdf"));
>
> PdfImportedPage page = writer.getImportedPage(reader, 1);
> throws a null pointer exception at me.
>
> here i can see that reader is not null (so existing.pdf was read
> correctly).
>
> regards,
> Abhishek.
>
> is this the correct way of getting a PdfImportedPage?
>
> On 8/4/06, bruno <[hidden email]> wrote:
>>
>> Abhishek Srivastava wrote:
>>
>> > Thanks Bruno,
>> >
>> > could you clarify the following lines in your code snipped
>> >
>> > Letter letter = new Letter();
>> >  writer.setPageEvent(letter);
>> >
>> > what is letter over here?
>>
>> Letter is the name of my main class.
>> It extends PdfPageEventHelper.
>> That's why it is instantiated and set as PageEvent for the writer.
>>
>> It is used to take one standard letter (an existing PDF)
>> and to create a 27.000 page PDF where each page
>> contains the same letter, but with a different name/address.
>> We ship this PDF to our printing office and they make sure
>> the letter is sent to the students.
>> br,
>> Bruno
>>
>> -------------------------------------------------------------------------
>> Take Surveys. Earn Cash. Influence the Future of IT
>> Join SourceForge.net's Techsay panel and you'll get the chance to share
>> your
>> opinions on IT & business topics through brief surveys -- and earn cash
>> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>> _______________________________________________
>> iText-questions mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>
>


--------------------------------------------------------------------------------


> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


--------------------------------------------------------------------------------


> _______________________________________________
> iText-questions mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Modify Content

Zhi Ren
In reply to this post by blowagie
Hi,

Maybe this is a stupid question. we know we cannot
modify the content of an existing PDF file, but using
iText we can add more into the PDF file. My question
is: if I use iText to add an image or an paragraph
into an existing PDF file, can I delete the image or
the paragraph later with iText? My thought is: because
the image was added into a PDF file by myself, I know
exactly where I put there and all the other infomation
about the image, so is those enough to enable me to
delete the image later with iText?

Thanks!

Zhi

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Modify Content

Leonard Rosenthol
At 01:19 PM 8/4/2006, Zhi Ren wrote:
>Maybe this is a stupid question. we know we cannot
>modify the content of an existing PDF file,

         You can - but not with iText.


>My question
>is: if I use iText to add an image or an paragraph
>into an existing PDF file, can I delete the image or
>the paragraph later with iText?

         Again, not with iText.

         iText doesn't support READ access to content ONLY WRITE.


>My thought is: because
>the image was added into a PDF file by myself, I know
>exactly where I put there and all the other infomation
>about the image,

         You do??

         You know what PDF object ID it is?  You know where it is in
the content stream?


>so is those enough to enable me to delete the image later with iText?

         Yes, if you want to do some work...


Leonard

---------------------------------------------------------------------------
Leonard Rosenthol                            <mailto:[hidden email]>
Chief Technical Officer                      <http://www.pdfsages.com>
PDF Sages, Inc.                              215-938-7080 (voice)
                                              215-938-0880 (fax)


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Modify Content

Mark Storer-3
In reply to this post by Zhi Ren
> because
> the image was added into a PDF file by myself, I know
> exactly where I put there and all the other infomation
> about the image, so is those enough to enable me to
> delete the image later with iText?

If you're feeling a bit brave, yes... or if your PDF-Fu is Mighty.  But if that were the case, you wouldn't need to ask.  Read on Brave One.

Content added by your iText app (so long as no other program has made changes) will be the first and/or last content streams in a given page's /Contents array.

There's an example called "AddWatermarkPageNumbers" on the "iText by Example" page: http://itextdocs.lowagie.com/tutorial/.  If you'll have a look at the output PDF in a text editor (Or a tool like windjack.com's PDF Can Opener in Acrobat) you'll see that there are three content streams in each page's /Contents array.  The first is the 'under' content, the second is the original content stream (and there can be more than one stream from the original), and the last is the 'over' content.

If all you've added was that image, removing it is a 'simple' matter of deleting the appropriate content stream from the /Contents array.  You'll have to dig around in the PDF object model... using dictionaries, arrays and streams in this case:

----

// this is all off the cuff, so might need some tweaking.
PdfDictionary pageDict = myReader.getPageN( pageNum );
PdfObject pageCont = pageDict.get( PdfName.CONTENTS );
if (pageCont.getType() == PdfObject.ARRAY) {
  PdfArray contArray = (PdfArray)pageCont;
  // how strange.  PdfArrays dont have any 'remove' methods,
  // but they do expose their internal ArrayList. ;)
  ArrayList contGuts = contArray.getArrayList();
  if (arrayLen > 0 && killOverContent) {
    contGuts.remove( arrayLen - 1 );
  }
  if (arrayLen > 0 && killUnderContent) {
    contGuts.remove( 0 );
  }
}

----

On the other hand, if you've added a number of different things other than the image at the same time, you have a bit more work ahead of you.

Option 1: Dig up the image you added and make it invisible.
1a: By setting it's width & height to zero.
1b: By removing all its image data (which involves altering an existing content stream)

Option 2: Modify the way you add the image to make it easier to dig out of the page's content, then parse and alter the appropriate content stream.

To make it easier to find, you can use the Marked Content system:

---

myContentByte.beginMarkedContentSequence( new PdfName( "IndianGiver" ) );
...  // add the image here
myContentByte.endMarkedContentSequence();

---

To actually get the content stream's bytes... that's tough.  Lets see here...  Ah!  Not so bad after all.  All the elements of a page's /Contents array are PdfStream objects.  If they're from a PdfReader (rather than created by a PdfWriter) they're instances of PRStream (a descendant of PdfStream).  You can call PdfReader's static getStreamBytes( PRStream yourContents ) and get back a byte[].

You'll need to search that byte array for "BMC IndianGiver" (Begin Marked Content, plus whatever tag you used in beginMarkedContentSquence() ), and yank out everything until you reach "EMC".  You'll also need to create a new PdfStream with your altered version of that byte array.  You cannot modify it in place:

(AND, you'll want to save the last token before "EMC" because you'll want to know the name of the resource to yank later.)

---

PRStream modifiedContent = new PRStream( myReader, modifiedBytes );
pageContArray.getArrayList().set( streamSourceIndex, modifiedContent );

---

You have to make these changes before connecting the PdfReader to a PdfWriter or the changes may not 'take'.

For space reasons, you'll also want to hunt down the image and drop it from the page's resource dictionary, then call myReader.removeUnusedObjects().  Just removing the reference to the image in the page resources and contents isn't enough to remove it from the file.

---

PdfDictionary pageDict = myReader.getPageN( pageNumNOT_INDEX );
PdfDictionary resDict = (PdfDictionary) pageDict.get( PdfName.RESOURCES );
if (resDict != null) { // they should always be dictionaries
  PdfDictionary xobjDict = (PdfDictionary) resDict.get( PdfName.XOBJECT ); // again, always a dict
  if (xobjDict != null) {
    xobjDict.remove( new PdfName( nameOfImageYouSavedEarlier ) );
  }
}
---

That's a lot of black-belt Pdf Fu going on there.  It becomes much easier to understand what's going on when you know what's already there, and what you want it to look like when you're done.  That's where opening PDFs in a text editor (or something like PDF Can Opener, no affiliation) is INVALUABLE.

When you can snatch the content stream from my hand, young grasshopper...

--Mark Storer
  Senior Software Engineer
  Cardiff Software

#include <disclaimer>
typedef std::Disclaimer<Cardiff> DisCard;

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Modify Content

Alan Keown



-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of Mark
Storer
Sent: Saturday, 5 August 2006 4:36 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Modify Content


> because
> the image was added into a PDF file by myself, I know
> exactly where I put there and all the other infomation
> about the image, so is those enough to enable me to
> delete the image later with iText?

If you're feeling a bit brave, yes... or if your PDF-Fu is Mighty.  But if
that were the case, you wouldn't need to ask.  Read on Brave One.
...

Thank you Mark
That was a truly informative and invigorating lesson.

Can't wait 'til you move on to "Nei PDF Gung" and "PDF Chi".

Cheers
AlanK



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document isslow

Abhishek Srivastava
In reply to this post by Paulo Soares
Thanks Paulo,
 
I am able to generate my document now.
 
Just one question.
 
The document which I use as template is landscape.
 
When I generate my document I also create it as Landscape. However the template document appears vertical in my page.
 
I have tried setting the Rectangle of the ImportedPage to the size of a Rotated A4 page but it still has imported the template correctly.
 
In short both my source and target documents have landscape A4 pages.
 
regards,
Abhishek.
 
 
 
 
 

 
On 8/4/06, Paulo Soares <[hidden email]> wrote:
Where's doc.open()?

Paulo

----- Original Message -----
From: "Abhishek Srivastava" < [hidden email]>
To: "Post all your questions about iText here"
<[hidden email]>
Sent: Friday, August 04, 2006 2:08 PM
Subject: Re: [iText-questions] Generation of Multiple Page PDF Document
isslow


> PdfReader reader = new PdfReader("existing.pdf");
>
> Document doc = new Document();

>
> PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("
> target.pdf"));
>
> PdfImportedPage page = writer.getImportedPage(reader, 1);
> throws a null pointer exception at me.
>
> here i can see that reader is not null (so existing.pdf was read
> correctly).
>
> regards,
> Abhishek.
>
> is this the correct way of getting a PdfImportedPage?
>
> On 8/4/06, bruno <[hidden email]> wrote:
>>
>> Abhishek Srivastava wrote:
>>
>> > Thanks Bruno,
>> >
>> > could you clarify the following lines in your code snipped
>> >
>> > Letter letter = new Letter();
>> >  writer.setPageEvent(letter);
>> >
>> > what is letter over here?
>>
>> Letter is the name of my main class.
>> It extends PdfPageEventHelper.
>> That's why it is instantiated and set as PageEvent for the writer.
>>
>> It is used to take one standard letter (an existing PDF)
>> and to create a 27.000 page PDF where each page
>> contains the same letter, but with a different name/address.
>> We ship this PDF to our printing office and they make sure
>> the letter is sent to the students.
>> br,
>> Bruno
>>
>> -------------------------------------------------------------------------
>> Take Surveys. Earn Cash. Influence the Future of IT
>> Join SourceForge.net 's Techsay panel and you'll get the chance to share
>> your
>> opinions on IT & business topics through brief surveys -- and earn cash
>> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>> _______________________________________________
>> iText-questions mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/itext-questions
>>
>


--------------------------------------------------------------------------------


> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


--------------------------------------------------------------------------------


> _______________________________________________
> iText-questions mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document isslow

blowagie
Abhishek Srivastava wrote:

> The document which I use as template is landscape.
>  
> When I generate my document I also create it as Landscape. However the
> template document appears vertical in my page.
>  
> I have tried setting the Rectangle of the ImportedPage to the size of
> a Rotated A4 page but it still has imported the template correctly.
>  
> In short both my source and target documents have landscape A4 pages.

There are different ways to solve this.
There is an addTemplate method that allows you to
define the rotation (using a transformation matrix).
Or you could wrap the PdfImportedPage inside
a com.lowagie.text.Image object, rotate the image
and add it with addImage.
br,
Bruno

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document isslow

Abhishek Srivastava
> There are different ways to solve this
 
Which will be the most efficient?
 
regards,
Abhishek.
 
On 8/7/06, bruno <[hidden email]> wrote:
Abhishek Srivastava wrote:

> The document which I use as template is landscape.
>
> When I generate my document I also create it as Landscape. However the
> template document appears vertical in my page.
>
> I have tried setting the Rectangle of the ImportedPage to the size of
> a Rotated A4 page but it still has imported the template correctly.
>
> In short both my source and target documents have landscape A4 pages.

There are different ways to solve this.
There is an addTemplate method that allows you to
define the rotation (using a transformation matrix).
Or you could wrap the PdfImportedPage inside
a com.lowagie.text.Image object, rotate the image
and add it with addImage.
br,
Bruno

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.techsay.com/default.php?page=join.php&amp;p=sourceforge&amp;CID=DEVDEV" target="_blank"> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.sourceforge.net/lists/listinfo/itext-questions" target="_blank">https://lists.sourceforge.net/lists/listinfo/itext-questions


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document isslow

blowagie
Abhishek Srivastava wrote:

> > There are different ways to solve this
>  
> Which will be the most efficient?

"One answer solves all" doesn't apply here.
First I thought of answering that the addTemplate
with the transformation coordinates would be the
best way to go, but then you need to do some
extra calculations. That's no problem if the original
PDF always has the same dimensions, but if you
have to support any template PDF (with any possible
page format and orientation), it could be more
interesting to use the Image approach (maintenance
will be easier)
br,
Bruno

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document isslow

Abhishek Srivastava
Hello Bruno,
 
I tried the following to rotate the template by 90 degrees.

writer.DirectContent.addTemplate(_page, 0, 1, -1, 0, PageSize.A4.height(), 0);

Now I get an inverted Imported page. (upside down).

If I try any other permutation combinarion I get a blank pdf. (for example:

  • _page, 0, 1, -1, 0, -1 * PageSize.A4.height(), 0).
  • _page, 0, 1, -1, 0, PageSize.A4.width(), PageSize.A4.height())
  • _page, 0, 1, -1, 0, PageSize.A4.height(), PageSize.A4.width())
 
Could you please give me what parameters should I use for a, b, c, d, e, f so that my vertical template rotates 90 degrees.
 
I don't want any scaling. and my source document is always of the same size (A4, landscape).
 
reagards,
Abhishek.

On 8/7/06, bruno <[hidden email]> wrote:
Abhishek Srivastava wrote:

> > There are different ways to solve this
>
> Which will be the most efficient?

"One answer solves all" doesn't apply here.
First I thought of answering that the addTemplate
with the transformation coordinates would be the
best way to go, but then you need to do some
extra calculations. That's no problem if the original
PDF always has the same dimensions, but if you
have to support any template PDF (with any possible
page format and orientation), it could be more
interesting to use the Image approach (maintenance
will be easier)
br,
Bruno

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document isslow

Abhishek Srivastava
Thanks Bruno,
 
The image approach works for me.
 
However I want to compare it to the addTemplate apporach.
 
if a co-ordinate is X1, Y1 in portait, then it becomes Y1, PageSize.A4.Width - X1 when the page becomes landscape.
 
Given the above, what transformation matrix should be applied? so that the template is added correctly?
 
regards,
Abhishek.

On 8/7/06, Abhishek Srivastava <[hidden email]> wrote:
Hello Bruno,
 
I tried the following to rotate the template by 90 degrees.

writer.DirectContent.addTemplate(_page, 0, 1, -1, 0, PageSize.A4.height(), 0);

Now I get an inverted Imported page. (upside down).

If I try any other permutation combinarion I get a blank pdf. (for example:

  • _page, 0, 1, -1, 0, -1 * PageSize.A4.height(), 0).
  • _page, 0, 1, -1, 0, PageSize.A4.width(), PageSize.A4.height())
  • _page, 0, 1, -1, 0, PageSize.A4.height(), PageSize.A4.width())
 
Could you please give me what parameters should I use for a, b, c, d, e, f so that my vertical template rotates 90 degrees.
 
I don't want any scaling. and my source document is always of the same size (A4, landscape).
 
reagards,
Abhishek.

On 8/7/06, bruno <[hidden email]> wrote:
Abhishek Srivastava wrote:

> > There are different ways to solve this
>
> Which will be the most efficient?

"One answer solves all" doesn't apply here.
First I thought of answering that the addTemplate
with the transformation coordinates would be the
best way to go, but then you need to do some
extra calculations. That's no problem if the original
PDF always has the same dimensions, but if you
have to support any template PDF (with any possible
page format and orientation), it could be more
interesting to use the Image approach (maintenance
will be easier)
br,
Bruno

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.techsay.com/default.php?page=join.php&amp;p=sourceforge&amp;CID=DEVDEV" target="_blank"> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[hidden email]
<a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.sourceforge.net/lists/listinfo/itext-questions" target="_blank">https://lists.sourceforge.net/lists/listinfo/itext-questions



-------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document isslow

blowagie
Abhishek Srivastava wrote:

> Thanks Bruno,
>  
> The image approach works for me.
>  
> However I want to compare it to the addTemplate apporach.
>  
> if a co-ordinate is X1, Y1 in portait, then it becomes Y1,
> PageSize.A4.Width - X1 when the page becomes landscape.
>  
> Given the above, what transformation matrix should be applied? so that
> the template is added correctly?

The problem you had is that the template is rotated outside the page.
I don't have the time to look it up right now, but it is just a matter of
applying some high school algebra. You can find the formulas here:
http://itextdocs.lowagie.com/tutorial/directcontent/coordinates/index.html#transform
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document isslow

Abhishek Srivastava
I will get the matrix approach to work.
 
I have made good progress with the image approach, I am able to write data using ColumnText but I am facing a problem in Fonts. my acrofields have fonts, and font style specified on them.
 
when I write text using ColumnText I should use the same Font and style. I am not able to extract the Font information from the Acrofield. Here is what I have done so far
 

foreach (PdfDictionary dict in item.merged)
{
  foreach(PdfName name in dict.Keys)
  {
    if (name.ToString() == "/AP")
    {
      PdfDictionary fontDict = (PdfDictionary)dict.Get(name);
      foreach (PdfName name2 in fontDict.Keys)
      {
        if (fontDict.Get(name2).IsIndirect())
        {
          Console.WriteLine("indirect found");
          PRIndirectReference obj = (PRIndirectReference)fontDict.Get(name2);
          PRStream stream = (PRStream) PdfReader.GetPdfObject(obj);

          Console.WriteLine(stream.GetType().Name);

          foreach (PdfName o in stream.Keys)
          {
            Console.WriteLine("{0} {1}", o.ToString(), stream.Get(o));
          }
          PRTokeniser token = new PRTokeniser(stream.GetBytes ());
          while (token.NextToken())
          {
            if (token.TokenType == PRTokeniser.TK_STRING) Console.WriteLine(token.ToString());
          }
          Console.WriteLine(obj.Type);               
        }
      }
    }
  }

but the above code does not work and it throws a null pointer exception.
 
regards,
Abhishek.

 
On 8/8/06, bruno <[hidden email]> wrote:
Abhishek Srivastava wrote:

> Thanks Bruno,
>
> The image approach works for me.
>
> However I want to compare it to the addTemplate apporach.
>
> if a co-ordinate is X1, Y1 in portait, then it becomes Y1,
> PageSize.A4.Width - X1 when the page becomes landscape.
>
> Given the above, what transformation matrix should be applied? so that
> the template is added correctly?

The problem you had is that the template is rotated outside the page.
I don't have the time to look it up right now, but it is just a matter of
applying some high school algebra. You can find the formulas here:
http://itextdocs.lowagie.com/tutorial/directcontent/coordinates/index.html#transform
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions


-------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Reply | Threaded
Open this post in threaded view
|

Re: Generation of Multiple Page PDF Document is slow

GaneshPrakhya
In reply to this post by blowagie
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.

Thanks in advance,
Ganesh.





Bruno Lowagie wrote
As promised, this is the procedure I use to create a 27.000+ page document
really fast using an existing 1-page PDF document with a form.

My class Letter extends PdfPageEventHelper.

In the onOpenDocument method
1. I read the existing PDF and retrieve the fields and their coordinates
  I store these coordinates for later use.
2. I read the page into a PdfImportedPage and store this page in a
  member variable 'page'

In the onStartPage method, I do:
writer.getDirectContent().addTemplate(page, 0, 0);

In the main method, I go through the 5 steps of document creation:
1. Document document = new Document();
  (in your case, it would probably be a good idea to retrieve the page
size from the original PDF)
2. PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("new.pdf"));
  Letter letter = new Letter();
  writer.setPageEvent(letter);
3. document.open();
4. I add content
  I loop over all the records in my database and I add it to the PDF
using ColumnText
  the coordinates used in the ColumnText objects, are the ones retrieved
in the onOpenDocument method.
  After each record, I do document.newPage();
  I don't worry about the 'template', the imported page is added
automatically in the page event.
5. document.close();

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

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
12