Hi there
 
I with joy using this iText component..really nice and flexible to use.
Though I have been performance measuring the code and it seams there
might be a few "skelletons in the clotheset" performance wise :).
 
The implementation is simpel. I read a 250 kb PDF file from an http url
using the PdfReader and then use the PdfStamper to set some values, call
close and take the bytearray - Base64 encode it and send it off as an
email attachment. I know the Base64 part takes time and sending the mail
itself but as you can see from below there are other things taking quite
a long time as well. So cry for help is how can I/is it possible to
reduce the processing time even more?
 
-- Code snippet of the reading and processing --
public byte[] importDataInToPDF(Object o, PerfProfilerTO perfProfileTO)
throws ApplicationException {

byte [] buf = null;

try {

PrefilledFormsCastorObject perfilledformCastorObject =
(PrefilledFormsCastorObject) o;

String pdfFileUrl = perfilledformCastorObject.getHtmlUrl();

if (pdfFileUrl == null || pdfFileUrl.trim().length() == 0) {

throw new ApplicationException();

}

pdfFileUrl = pdfFileUrl.substring(0, pdfFileUrl.lastIndexOf('.')) +
".pdf";

try {

Profiler.begin("importDataInToPDF - prefilled forms creating reader",
perfProfileTO, Profiler.APPEND_AS_CHILD, Profiler.LAYER_BO);

reader = new PdfReader(new URL(pdfFileUrl));

Profiler.end("importDataInToPDF - prefilled forms creating reader",
perfProfileTO, Profiler.APPEND_AS_CHILD, Profiler.LAYER_BO);

} catch (Exception e){

String msg = "PDF file not found at specified URL location.";

log.error( msg + " msg: " + e.getMessage());

throw new ApplicationException("Not able generate PDF file." + ", msg: "
+ e.getMessage());

}

PdfStamper stamp1 = null;

Profiler.begin("importDataInToPDF - prefilled forms create some
streams", perfProfileTO, Profiler.APPEND_AS_CHILD, Profiler.LAYER_BO);

ByteArrayOutputStream byteArrOutputStream = new ByteArrayOutputStream();

BufferedOutputStream bufferedOutputStream = new
BufferedOutputStream(byteArrOutputStream);

Profiler.end("importDataInToPDF - prefilled forms create some streams",
perfProfileTO, Profiler.APPEND_AS_CHILD, Profiler.LAYER_BO); 

Profiler.begin("importDataInToPDF - prefilled forms creating stamper",
perfProfileTO, Profiler.APPEND_AS_CHILD, Profiler.LAYER_BO);

stamp1 = new PdfStamper(reader,bufferedOutputStream);

Profiler.end("importDataInToPDF - prefilled forms creating stamper",
perfProfileTO, Profiler.APPEND_AS_CHILD, Profiler.LAYER_BO);

Profiler.begin("importDataInToPDF - prefilled forms gettting
acrofields", perfProfileTO, Profiler.APPEND_AS_CHILD,
Profiler.LAYER_BO);

AcroFields formFields = stamp1.getAcroFields();

Profiler.end("importDataInToPDF - prefilled forms gettting acrofields",
perfProfileTO, Profiler.APPEND_AS_CHILD, Profiler.LAYER_BO);

Profiler.begin("importDataInToPDF - prefilled forms gettting acrofields
as hashtable", perfProfileTO, Profiler.APPEND_AS_CHILD,
Profiler.LAYER_BO);

HashMap hp = formFields.getFields();

Profiler.end("importDataInToPDF - prefilled forms gettting acrofields as
hashtable", perfProfileTO, Profiler.APPEND_AS_CHILD, Profiler.LAYER_BO);

List listOfObj = perfilledformCastorObject.getNameValuePairs();

NameValuePairCasterObject nameValuePairCasterObject =
(NameValuePairCasterObject) listOfObj.get(0);

List listOfNameValueMapping =
nameValuePairCasterObject.getNameValueMapping();

Profiler.begin("importDataInToPDF - prefilled forms iteratelist",
perfProfileTO, Profiler.APPEND_AS_CHILD, Profiler.LAYER_BO);

for (int i = 0; i < listOfNameValueMapping.size(); i++){

NameValueMapingCasterObject nameValueMapingCasterObject = 

(NameValueMapingCasterObject) listOfNameValueMapping.get(i);

if (hp.containsKey(nameValueMapingCasterObject.getName())) {

if (nameValueMapingCasterObject.getValue().equalsIgnoreCase("true")) {

// Get appearance state values.

String[] states =
formFields.getAppearanceStates(nameValueMapingCasterObject.getName());

// Check the checkbox.

formFields.setField(nameValueMapingCasterObject.getName(), states[0]);

} else {

// Else just add as text field

formFields.setField(nameValueMapingCasterObject.getName(),
nameValueMapingCasterObject.getValue());

}

}

}

Profiler.end("importDataInToPDF - prefilled forms iteratelist",
perfProfileTO, Profiler.APPEND_AS_CHILD, Profiler.LAYER_BO);

// Close the PdfStamper and underlying streams.

Profiler.begin("prefilledforms Closing stamper", perfProfileTO,
Profiler.APPEND_AS_CHILD, Profiler.LAYER_BO);

stamp1.close();

Profiler.end("prefilledforms Closing stamper", perfProfileTO,
Profiler.APPEND_AS_CHILD, Profiler.LAYER_BO);

buf = byteArrOutputStream.toByteArray();

log.info("importDataInToPDF: serializing done");

return buf;

} catch (DocumentException e) {

log.error("importDataInToPDF: DocumentException found: " +
e.getMessage(), e);

throw new ApplicationException("Not able generate PDF file." + ", msg: "
+ e.getMessage());

}

catch (ApplicationException e1) {

log.error("Itext_Impl_ImportDataInPDF(): Problem occured while
generating PDF file: " + e1.getMessage(), e1);

throw new
ApplicationException("Itext_Impl_ImportDataInPDF.importDataInToPDF():
Not able generate PDF file." + ", msg: " + e1.getMessage());

}

catch (Exception e) {

log.error("importDataInToPDF: DocumentException found: " +
e.getMessage(), e);

}

return null;

}

 
-- Profiler view --
 
Tue Nov 28 10:32:22 CET 2006, InvokationSuccess=true, Layer=BO,
FacadeMethod=prefilledforms.ordercommand.execute.all,
SubMethod=importDataInToPDF - prefilled forms creating reader,
ExternalCall=null, DatabaseOperation=null, StartTime=1164706342040,
ExecutionTime=4868, AgentId=null, ClientToken=null, Note=null
 
Tue Nov 28 10:32:26 CET 2006, InvokationSuccess=true, Layer=BO,
FacadeMethod=prefilledforms.ordercommand.execute.all,
SubMethod=importDataInToPDF - prefilled forms creating stamper,
ExternalCall=null, DatabaseOperation=null, StartTime=1164706346908,
ExecutionTime=1108, AgentId=null, ClientToken=null, Note=null
 
Tue Nov 28 10:32:28 CET 2006, InvokationSuccess=true, Layer=BO,
FacadeMethod=prefilledforms.ordercommand.execute.all,
SubMethod=importDataInToPDF - prefilled forms gettting acrofields,
ExternalCall=null, DatabaseOperation=null, StartTime=1164706348016,
ExecutionTime=843, AgentId=null, ClientToken=null, Note=null
 
Hope for you help :).
 
Regards Michael


This message contains information that may be privileged or confidential and is 
the property of the Capgemini Group. It is intended only for the person to whom 
it is addressed. If you are not the intended recipient,  you are not authorized 
to read, print, retain, copy, disseminate,  distribute, or use this message or 
any part thereof. If you receive this  message in error, please notify the 
sender immediately and delete all  copies of this message.
-------------------------------------------------------------------------
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
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to