Re: [iText-questions] Copy and stamp the first page of a pdf

2010-04-20 Thread 1T3XT info
Vito De Tullio wrote:
> Hi all.
> 
> I'm a new iText user... what I need to do, given a pdf is:
> copy the first page (so, starting from a 5-pages pdf I need to end
> with a 6-pages pdf) and stamp some text on it.

OK.

> Toying around the apis, all I made is a method like this:

This is absolutely forbidden:
> byte[] page1 = reader.getPageContent(1);  // content of the first page
> stamp.insertPage(1, reader.getPageSize(1));   // insert a very first blank 
> page
> reader.setPageContent(1, page1);  // copy the content of the "old" first 
> page

Using setPageContent() copies the content stream of a page
WITHOUT THE RESOURCES!!!

> but acrobat reader say it cannot find the right font for the generated
> pdf (?) and show me the copy of the first page with some strange
> characters...

Adobe Reader tells you that you're using a font that can't
be found in the resources.

You should use PdfImportedPage if you want to copy the content
AND the necessary resources.

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

--
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
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/


[iText-questions] Copy and stamp the first page of a pdf

2010-04-20 Thread Vito De Tullio
Hi all.

I'm a new iText user... what I need to do, given a pdf is:
copy the first page (so, starting from a 5-pages pdf I need to end
with a 6-pages pdf) and stamp some text on it.

Toying around the apis, all I made is a method like this:

(original is an InputStream with the original pdf)
...
PdfReader reader = new PdfReader(original);
int n = reader.getNumberOfPages();
if (n == 0)
return original; // no pages

ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamp = new PdfStamper(reader, baos);

// copy the first page
byte[] page1 = reader.getPageContent(1);  // content of the first page
stamp.insertPage(1, reader.getPageSize(1)); // insert a very first blank 
page
reader.setPageContent(1, page1);// copy the content of the "old" first 
page

// "stamp" the "new" first page
PdfContentByte layer_over = stamp.getOverContent(1);
layer_over.beginText();
layer_over.setFontAndSize(
BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
BaseFont.EMBEDDED),
this.text_size);
layer_over.moveText(this.left_spacing, this.bottom_spacing);
layer_over.setLeading(this.text_size);
layer_over.setTextRenderingMode(
PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE_CLIP);
for (final String text: texts)
layer_over.newlineShowText(text);
layer_over.endText();

stamp.close();
return new ByteArrayInputStream(baos.toByteArray());

but acrobat reader say it cannot find the right font for the generated
pdf (?) and show me the copy of the first page with some strange
characters...

-- 
Vito De Tullio - vito.detul...@gmail.com

--
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
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/


[iText-questions] I-Text PDF to TIFF Conversion

2010-04-20 Thread Anil Sahu
Dear All,

Can any one tell me how can we convert a PDF to TIFF Using Itext Apis.
I tried the Same using PDFBox but it is converting only the PDFs whcih
are generated through Adobe, No idea why it is not converting for
other PDFs which are generated using a Scanner.

Below is the Code Snippet for whcih i used PDFBox Libs.

File file =new File("\\C:\\AnilSahu\\0321146182_J2E.pdf");  
org.apache.pdfbox.pdmodel.PDDocument document =null;
document =  PDDocument.load(file);
PDFImageWriter writer = new PDFImageWriter();
writer.writeImage(document, "tif", "", 1, Integer.MAX_VALUE,
"\\C:\\AnilSahu\\Imaging\\" + file.getName() + "-");
document.close();

It would be greate if anyone can give me some clue for implementing
the same using IText Lib's.

Thanks in Advance.

Cheers,
Anil Sahu.

--
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
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/


Re: [iText-questions] Error: Font 'Arial' with 'Cp1252' isnotrecognized.

2010-04-20 Thread Lu, Tao (MOH)
Thanks a lot!
 
Best Regards,
Tao
 



From: Paulo Soares [mailto:psoa...@glintt.com] 
Sent: April 20, 2010 4:27 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] Error: Font 'Arial' with 'Cp1252'
isnotrecognized.


Use "Arial.ttf" as the font name.
 
Paulo

- Original Message - 
From: Lu, Tao (MOH)   
To: itext-questions@lists.sourceforge.net 
Sent: Tuesday, April 20, 2010 8:49 PM
Subject: [iText-questions] Error: Font 'Arial' with 'Cp1252' is
notrecognized.


Hi, All, 

I am getting this error :Font 'Arial' with 'Cp1252' is not
recognized. 

Here is the code: 

byte[] ttf = .  // An byte array of file -- arial.ttf 
BaseFont.createFont("Arial", BaseFont.WINANSI,
BaseFont.EMBEDDED, true, ttf, null); 

And clue? 

Thanks a lot in advance! 

Regards, 
Tao 



--
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
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/

Re: [iText-questions] Error: Font 'Arial' with 'Cp1252' is notrecognized.

2010-04-20 Thread Paulo Soares
Error: Font 'Arial' with 'Cp1252' is not recognized.Use "Arial.ttf" as the font 
name.

Paulo
  - Original Message - 
  From: Lu, Tao (MOH) 
  To: itext-questions@lists.sourceforge.net 
  Sent: Tuesday, April 20, 2010 8:49 PM
  Subject: [iText-questions] Error: Font 'Arial' with 'Cp1252' is notrecognized.


  Hi, All, 

  I am getting this error :Font 'Arial' with 'Cp1252' is not recognized. 

  Here is the code: 

  byte[] ttf = …..  // An byte array of file -- arial.ttf 
  BaseFont.createFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, true, ttf, 
null); 

  And clue? 

  Thanks a lot in advance! 

  Regards, 
  Tao 



--
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
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/

[iText-questions] Error: Font 'Arial' with 'Cp1252' is not recognized.

2010-04-20 Thread Lu, Tao (MOH)
Hi, All, 

I am getting this error :Font 'Arial' with 'Cp1252' is not recognized.

Here is the code:

byte[] ttf = .  // An byte array of file -- arial.ttf
BaseFont.createFont("Arial", BaseFont.WINANSI, BaseFont.EMBEDDED, true,
ttf, null);

And clue? 

Thanks a lot in advance!

Regards,
Tao



--
___
iText-questions mailing list
iText-questions@lists.sourceforge.net
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/

Re: [iText-questions] performance question

2010-04-20 Thread Paulo Soares
You may increase the speed if you are filling the same form repeatedely with 
AcroFields.setFieldCache() and the copying constructor of PdfReader, see 
http://1t3xt.info/examples/browse/?page=example&id=249.

Paulo


From: Azùa Giovanni (KSXD 32) [giovanni.a...@credit-suisse.com]
Sent: Tuesday, April 20, 2010 2:54 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] performance question


Hello Paulo,

I am perfectly aware of the benefits of iText, that's why I proposed it for our 
project in the first place but it can be hard to convince the team lead and 
colleagues to switch to a framework when it comes at a performance toll of 30% 
overhead for the use-case at hand.

I didn't mean to start a flame but was actually fishing for rewrite 
alternatives to improve the performance of our use-case ...

Best regards,
Giovanni

==
Please access the attached hyperlink for an important electronic communications 
disclaimer:

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html 


==


From: Paulo Soares [mailto:psoa...@glintt.com]
Sent: Tuesday, April 20, 2010 2:48 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] performance question

Hmm, there are lies, damn lies and statistics. While I don't dispute the 30% 
let's see the probable causes for this:

- iText tries to do things correctly avoiding to cut corners that will come and 
bite your later. Metadata writing, appearance generation and so on.

- iText is a generic PDF library. It reads, writes and modifies PDFs. Any 
library designed with a narrower purpose can optimize the interested areas to 
perform better.

- iText comes with source and can be extended, modified, altered. This implies 
that a sensible and probably heavier structure must be in place to allow that. 
If you have a closed source library with just a single purpose things can be 
done faster as that's all it's going to do.

- com.itextpdf.text.pdf.PdfStamperImpl.close() is where everything is written 
to file, if you avoid calling this nothing will come out.

- There are some speed and memory improvements in the pipeline but I don't know 
how much % improvement will result or in what areas.

Paulo


Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter 
informação confidencial ou legalmente protegida. A incorrecta transmissão desta 
mensagem não significa a perca de confidencialidade. Se esta mensagem for 
recebida por engano, por favor envie-a de volta para o remetente e apague-a do 
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de 
usar, revelar ou distribuir qualquer parte desta mensagem. 

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain 
confidential or legally protected information. The incorrect transmission of 
this message does not mean the loss of its confidentiality. If this message is 
received by mistake, please send it back to the sender and delete it from your 
system immediately. It is forbidden to any person who is not the intended 
receiver to use, distribute or copy any part of this message.

--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev___
iText-questions mailing list
iText-questions@lists.sourceforge.net
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/

Re: [iText-questions] performance question

2010-04-20 Thread Mark Storer
Is this other library flattening the form as well?  That can get pricey, 
computation-wise.  Is it appending its changes to the existing PDF, or 
rewriting everything?  Are both Java libraries?

 

--Mark Storer

  Senior Software Engineer

  Cardiff.com

 

import legalese.Disclaimer;

Disclaimer DisCard = null;

 



From: Azùa Giovanni (KSXD 32) [mailto:giovanni.a...@credit-suisse.com] 
Sent: Tuesday, April 20, 2010 6:54 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] performance question

 

Hello Paulo, 

I am perfectly aware of the benefits of iText, that's why I proposed it for our 
project in the first place but it can be hard to convince the team lead and 
colleagues to switch to a framework when it comes at a performance toll of 30% 
overhead for the use-case at hand.

  
I didn't mean to start a flame but was actually fishing for rewrite 
alternatives to improve the performance of our use-case ... 

  
Best regards, 
Giovanni 

== 
Please access the attached hyperlink for an important electronic communications 
disclaimer: 

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html 
  
 >  

== 
 

From: Paulo Soares [mailto:psoa...@glintt.com  ] 
Sent: Tuesday, April 20, 2010 2:48 PM 
To: Post all your questions about iText here 
Subject: Re: [iText-questions] performance question 

Hmm, there are lies, damn lies and statistics. While I don't dispute the 30% 
let's see the probable causes for this: 
  
- iText tries to do things correctly avoiding to cut corners that will come and 
bite your later. Metadata writing, appearance generation and so on.

  
- iText is a generic PDF library. It reads, writes and modifies PDFs. Any 
library designed with a narrower purpose can optimize the interested areas to 
perform better.

  
- iText comes with source and can be extended, modified, altered. This implies 
that a sensible and probably heavier structure must be in place to allow that. 
If you have a closed source library with just a single purpose things can be 
done faster as that's all it's going to do.

  
- com.itextpdf.text.pdf.PdfStamperImpl.close() is where everything is written 
to file, if you avoid calling this nothing will come out.

  
- There are some speed and memory improvements in the pipeline but I don't know 
how much % improvement will result or in what areas.

  
Paulo 

No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.801 / Virus Database: 271.1.1/2806 - Release Date: 04/20/10 
05:45:00


--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev___
iText-questions mailing list
iText-questions@lists.sourceforge.net
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/

Re: [iText-questions] performance question

2010-04-20 Thread KSXD 32
Hello Paulo,

I am perfectly aware of the benefits of iText, that's why I proposed it for our 
project in the first place but it can be hard to convince the team lead and 
colleagues to switch to a framework when it comes at a performance toll of 30% 
overhead for the use-case at hand.
 
I didn't mean to start a flame but was actually fishing for rewrite 
alternatives to improve the performance of our use-case ... 
 
Best regards,
Giovanni

== 
Please access the attached hyperlink for an important electronic communications 
disclaimer: 

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html 
  
== 


From: Paulo Soares [mailto:psoa...@glintt.com] 
Sent: Tuesday, April 20, 2010 2:48 PM
To: Post all your questions about iText here
Subject: Re: [iText-questions] performance question

Hmm, there are lies, damn lies and statistics. While I don't dispute the 30% 
let's see the probable causes for this:
 
- iText tries to do things correctly avoiding to cut corners that will come and 
bite your later. Metadata writing, appearance generation and so on.
 
- iText is a generic PDF library. It reads, writes and modifies PDFs. Any 
library designed with a narrower purpose can optimize the interested areas to 
perform better.
 
- iText comes with source and can be extended, modified, altered. This implies 
that a sensible and probably heavier structure must be in place to allow that. 
If you have a closed source library with just a single purpose things can be 
done faster as that's all it's going to do.
 
- com.itextpdf.text.pdf.PdfStamperImpl.close() is where everything is written 
to file, if you avoid calling this nothing will come out.
 
- There are some speed and memory improvements in the pipeline but I don't know 
how much % improvement will result or in what areas.
 
Paulo
--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev___
iText-questions mailing list
iText-questions@lists.sourceforge.net
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/

Re: [iText-questions] performance question

2010-04-20 Thread Mike Marchywka

Forgive the top posting but since this involves statistical modelling
with OP from a financial services company and the "comments" have
already started flying, allow me to throw my two sticks onto the
fire. 
 
It may help us here formulate a constructive response 
if you could dig a bit deeper into the close
method and see who the big resource hog is. Also, if you can
point to the speed limiting step in your alt package it may
be interesting to contemplate. We really don't know too much
about details of your typical use case, we won't forward your
comments to IRS or SEC ( LOL). Often you do find that mundane
things get taken for granted- I;ve found sometimes IO dominates
instead of computation just because no one looked at the code
and data gets copied many times and is moved byte by byte etc.
 
Also, since you went to all the trouble of doing a stats
analysis, and since these things are "supposed to be" deterministic,
it may help to get some idea how the execution time
noise appears if indeed it is a significant fraction of the average. Presumably 
this is things like OS, other tasks on machine if you
measured "wall clock" ( not cpu time devoted to you )  and GC and
other "stuff" including maybe disk and memory cache states. 
I would point out that depending on exactly what you are measuring,
you could be seeing lots of caching hot/cold issues that could dominate
the results. 







> From: lrose...@adobe.com
> To: itext-questions@lists.sourceforge.net
> Date: Tue, 20 Apr 2010 06:07:13 -0700
> Subject: Re: [iText-questions] performance question
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> And following up on point 3 – you have the source code, feel
> free to modify it for your personal needs.
>
>
>
>
>
>
>
> Leonard
>
>
>
>
>
>
>
>
>
>
>
> From: Paulo Soares
> [mailto:psoa...@glintt.com]
>
> Sent: Tuesday, April 20, 2010 8:48 AM
>
> To: Post all your questions about iText here
>
> Subject: Re: [iText-questions] performance question
>
>
>
>
>
>
>
>
>
>
>
>
>
> Hmm, there are lies, damn lies and statistics. While I don't
> dispute the 30% let's see the probable causes for this:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> -
> iText tries to do things correctly avoiding to cut corners that will come and
> bite your later. Metadata writing, appearance generation and so on.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> -
> iText is a generic PDF library. It reads, writes and modifies PDFs. Any 
> library
> designed with a narrower purpose can optimize the interested areas to
> perform better.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> -
> iText comes with source and can be extended, modified, altered. This implies
> that a sensible and probably heavier structure must be in place to allow
> that. If you have a closed source library with just a single purpose things 
> can
> be done faster as that's all it's going to do.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> -
> com.itextpdf.text.pdf.PdfStamperImpl.close()
> is where everything is written to file, if you avoid calling this nothing will
> come out.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> -
> There are some speed and memory improvements in the pipeline but I don't
> know how much % improvement will result or in what areas.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Paulo
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> 
>
>
>
>
>
> From: Azùa Giovanni (KSXD 32) [giovanni.a...@credit-suisse.com]
>
> Sent: Tuesday, April 20, 2010 1:12 PM
>
> To: Post all your questions about iText here
>
> Subject: [iText-questions] performance question
>
>
>
>
>
>
>
> Hello,
>
>
>
> For a
> specific Letter generation use-case I prepared a test of statistical
> significance using a paired t-test for comparing the performance [1] of iText
> vs a commercial PDF framework. The experiment shows that for our relevant
> use-case iText underperforms by 30% with 95% confidence.
>
>
>
> I did some
> further investigation of the iText code for this specific use-case and found
> the following call to be among the top most expensive calls:
>
>
>
> com.itextpdf.text.pdf.PdfStamperImpl.close
> (line 189) taking up to 195 milliseconds
>
>
>
> The code
> that invokes such method is the following:
>
>
>
> private
> static
> void
> appendFooter(PdfWriter writer) throws Exception {
>
>
>
> Map> String> replacements = new HashMap();
>
>
>
>
> replacements.put("ph0001", "X
> X");
>
>
>
> replacements.put("ph0002", "Head of
> Customer Acquisition");
>
>
>
> replacements.put("ph0003", "XX
> XXX");
>
>
> replacements.put("ph0004", "Head of Customer
> Satisfaction");
>
>
>
>
>
> PdfReader footerReader = new PdfReader(FOOTER_PATH);
>
>
> ByteArrayOutputStream outputStream = new
> ByteArrayOutputStream();
>
>
> PdfStamper stamper = new PdfStamper(footerReader, outputStream);
>
>
>
> AcroFields form = stamper.getAcroFields();
>
>
> for
> (Map.Entry entry : replacements.entrySet()) {
>
>
>
> form.setField(entry.getKey(),
> entry.getValue());
>
>
> }
>
>
> stamper.setFormFlattening(true);
>
>
> stamper.close();

Re: [iText-questions] performance question

2010-04-20 Thread Leonard Rosenthol
And following up on point 3 – you have the source code, feel free to modify it 
for your personal needs.

Leonard

From: Paulo Soares [mailto:psoa...@glintt.com]
Sent: Tuesday, April 20, 2010 8:48 AM
To: Post all your questions about iText here
Subject: Re: [iText-questions] performance question

Hmm, there are lies, damn lies and statistics. While I don't dispute the 30% 
let's see the probable causes for this:

- iText tries to do things correctly avoiding to cut corners that will come and 
bite your later. Metadata writing, appearance generation and so on.

- iText is a generic PDF library. It reads, writes and modifies PDFs. Any 
library designed with a narrower purpose can optimize the interested areas to 
perform better.

- iText comes with source and can be extended, modified, altered. This implies 
that a sensible and probably heavier structure must be in place to allow that. 
If you have a closed source library with just a single purpose things can be 
done faster as that's all it's going to do.

- com.itextpdf.text.pdf.PdfStamperImpl.close() is where everything is written 
to file, if you avoid calling this nothing will come out.

- There are some speed and memory improvements in the pipeline but I don't know 
how much % improvement will result or in what areas.

Paulo


From: Azùa Giovanni (KSXD 32) [giovanni.a...@credit-suisse.com]
Sent: Tuesday, April 20, 2010 1:12 PM
To: Post all your questions about iText here
Subject: [iText-questions] performance question

Hello,

For a specific Letter generation use-case I prepared a test of statistical 
significance using a paired t-test for comparing the performance [1] of iText 
vs a commercial PDF framework. The experiment shows that for our relevant 
use-case iText underperforms by 30% with 95% confidence.

I did some further investigation of the iText code for this specific use-case 
and found the following call to be among the top most expensive calls:

com.itextpdf.text.pdf.PdfStamperImpl.close (line 189) taking up to 195 
milliseconds

The code that invokes such method is the following:

private static void appendFooter(PdfWriter writer) throws Exception {
Map replacements = new HashMap();
replacements.put("ph0001", "X X");
replacements.put("ph0002", "Head of Customer Acquisition");
replacements.put("ph0003", "XX XXX");
replacements.put("ph0004", "Head of Customer Satisfaction");

PdfReader footerReader = new PdfReader(FOOTER_PATH);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(footerReader, outputStream);
AcroFields form = stamper.getAcroFields();
for (Map.Entry entry : replacements.entrySet()) {
form.setField(entry.getKey(), entry.getValue());
}
stamper.setFormFlattening(true);
stamper.close();

int pageOne = 1;
int xOffset = 5;
int yOffset = -560;
PdfReader memoryReader = new PdfReader(outputStream.toByteArray());
PdfImportedPage importedPage = writer.getImportedPage(memoryReader, 
pageOne);
PdfContentByte content = writer.getDirectContent();
content.addTemplate(importedPage, xOffset, yOffset);
}

Are there any possible rewrites to avoid the expensive call?

Thanks in advance,
Best regards,
Giovanni

[1] The Art of Computer Systems Performance Analysis: Techniques for 
Experimental Design, Measurement, Simulation, and Modeling 
http://www.amazon.com/Art-Computer-Systems-Performance-Analysis/dp/0471503363/ref=cm_cr-mr-title

==
Please access the attached hyperlink for an important electronic communications 
disclaimer:

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==


Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter 
informação confidencial ou legalmente protegida. A incorrecta transmissão desta 
mensagem não significa a perca de confidencialidade. Se esta mensagem for 
recebida por engano, por favor envie-a de volta para o remetente e apague-a do 
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de 
usar, revelar ou distribuir qualquer parte desta mensagem.

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain 
confidential or legally protected information. The incorrect transmission of 
this message does not mean the loss of its confidentiality. If this message is 
received by mistake, please send it back to the sender and delete it from your 
system immediately. It is forbidden to any person who is not the intended 
receiver to use, distribute or copy any part of this message.
--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs

Re: [iText-questions] performance question

2010-04-20 Thread Paulo Soares
Hmm, there are lies, damn lies and statistics. While I don't dispute the 30% 
let's see the probable causes for this:

- iText tries to do things correctly avoiding to cut corners that will come and 
bite your later. Metadata writing, appearance generation and so on.

- iText is a generic PDF library. It reads, writes and modifies PDFs. Any 
library designed with a narrower purpose can optimize the interested areas to 
perform better.

- iText comes with source and can be extended, modified, altered. This implies 
that a sensible and probably heavier structure must be in place to allow that. 
If you have a closed source library with just a single purpose things can be 
done faster as that's all it's going to do.

- com.itextpdf.text.pdf.PdfStamperImpl.close() is where everything is written 
to file, if you avoid calling this nothing will come out.

- There are some speed and memory improvements in the pipeline but I don't know 
how much % improvement will result or in what areas.

Paulo


From: Azùa Giovanni (KSXD 32) [giovanni.a...@credit-suisse.com]
Sent: Tuesday, April 20, 2010 1:12 PM
To: Post all your questions about iText here
Subject: [iText-questions] performance question


Hello,

For a specific Letter generation use-case I prepared a test of statistical 
significance using a paired t-test for comparing the performance [1] of iText 
vs a commercial PDF framework. The experiment shows that for our relevant 
use-case iText underperforms by 30% with 95% confidence.

I did some further investigation of the iText code for this specific use-case 
and found the following call to be among the top most expensive calls:

com.itextpdf.text.pdf.PdfStamperImpl.close (line 189) taking up to 195 
milliseconds

The code that invokes such method is the following:

private static void appendFooter(PdfWriter writer) throws Exception {
Map replacements = new HashMap();
replacements.put("ph0001", "X X");
replacements.put("ph0002", "Head of Customer Acquisition");
replacements.put("ph0003", "XX XXX");
replacements.put("ph0004", "Head of Customer Satisfaction");

PdfReader footerReader = new PdfReader(FOOTER_PATH);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(footerReader, outputStream);
AcroFields form = stamper.getAcroFields();
for (Map.Entry entry : replacements.entrySet()) {
form.setField(entry.getKey(), entry.getValue());
}
stamper.setFormFlattening(true);
stamper.close();

int pageOne = 1;
int xOffset = 5;
int yOffset = -560;
PdfReader memoryReader = new PdfReader(outputStream.toByteArray());
PdfImportedPage importedPage = writer.getImportedPage(memoryReader, 
pageOne);
PdfContentByte content = writer.getDirectContent();
content.addTemplate(importedPage, xOffset, yOffset);
}

Are there any possible rewrites to avoid the expensive call?

Thanks in advance,
Best regards,
Giovanni

[1] The Art of Computer Systems Performance Analysis: Techniques for 
Experimental Design, Measurement, Simulation, and Modeling 
http://www.amazon.com/Art-Computer-Systems-Performance-Analysis/dp/0471503363/ref=cm_cr-mr-title

==
Please access the attached hyperlink for an important electronic communications 
disclaimer:

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==


Aviso Legal:
Esta mensagem é destinada exclusivamente ao destinatário. Pode conter 
informação confidencial ou legalmente protegida. A incorrecta transmissão desta 
mensagem não significa a perca de confidencialidade. Se esta mensagem for 
recebida por engano, por favor envie-a de volta para o remetente e apague-a do 
seu sistema de imediato. É proibido a qualquer pessoa que não o destinatário de 
usar, revelar ou distribuir qualquer parte desta mensagem. 

Disclaimer:
This message is destined exclusively to the intended receiver. It may contain 
confidential or legally protected information. The incorrect transmission of 
this message does not mean the loss of its confidentiality. If this message is 
received by mistake, please send it back to the sender and delete it from your 
system immediately. It is forbidden to any person who is not the intended 
receiver to use, distribute or copy any part of this message.

--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev___
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-ques

[iText-questions] performance question

2010-04-20 Thread KSXD 32
Hello,

For a specific Letter generation use-case I prepared a test of statistical 
significance using a paired t-test for comparing the performance [1] of iText 
vs a commercial PDF framework. The experiment shows that for our relevant 
use-case iText underperforms by 30% with 95% confidence.

I did some further investigation of the iText code for this specific use-case 
and found the following call to be among the top most expensive calls:

com.itextpdf.text.pdf.PdfStamperImpl.close (line 189) taking up to 195 
milliseconds 

The code that invokes such method is the following:

private static void appendFooter(PdfWriter writer) throws Exception {
Map replacements = new HashMap();
replacements.put("ph0001", "X X");
replacements.put("ph0002", "Head of Customer Acquisition");
replacements.put("ph0003", "XX XXX");
replacements.put("ph0004", "Head of Customer Satisfaction");

PdfReader footerReader = new PdfReader(FOOTER_PATH);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(footerReader, outputStream);
AcroFields form = stamper.getAcroFields();
for (Map.Entry entry : replacements.entrySet()) {
form.setField(entry.getKey(), entry.getValue());
}
stamper.setFormFlattening(true);
stamper.close();

int pageOne = 1;
int xOffset = 5;
int yOffset = -560;
PdfReader memoryReader = new PdfReader(outputStream.toByteArray());
PdfImportedPage importedPage = writer.getImportedPage(memoryReader, 
pageOne);
PdfContentByte content = writer.getDirectContent();
content.addTemplate(importedPage, xOffset, yOffset);
}

Are there any possible rewrites to avoid the expensive call?

Thanks in advance,
Best regards,
Giovanni

[1] The Art of Computer Systems Performance Analysis: Techniques for 
Experimental Design, Measurement, Simulation, and Modeling 
http://www.amazon.com/Art-Computer-Systems-Performance-Analysis/dp/0471503363/ref=cm_cr-mr-title

==
Please access the attached hyperlink for an important electronic communications 
disclaimer:

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
== 
--
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev___
iText-questions mailing list
iText-questions@lists.sourceforge.net
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/