workign with exisitng pdfs
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi,
I am adding a text to the existing pdf and writing to bytearray output stream but when I open the "HelloWorld2.pdf", text is not showing up? But if i create a new pdf for e.g. HelloWorldNew.pdf then the text is shwoing up.
Can any one help me to find out the error reg bytearray outputstream.?
PdfReader pdfReader = new PdfReader(
"C:\\POC\\HelloWorld2.pdf");
ByteArrayOutputStream bao = new ByteArrayOutputStream();
PdfStamper pdfStamper = new PdfStamper(pdfReader, bao);
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat f = new SimpleDateFormat("MM/dd/yyyy");
String signatureDate = f.format(currentDate.getTime());
ct.setAlignment(Element.ALIGN_CENTER);
ct.setSimpleColumn(50, 500, 500, 50);
ct.addText(new Chunk("Current Date : " + signatureDate));
ct.go();
Thanks,
Suguna
I am adding a text to the existing pdf and writing to bytearray output stream but when I open the "HelloWorld2.pdf", text is not showing up? But if i create a new pdf for e.g. HelloWorldNew.pdf then the text is shwoing up.
Can any one help me to find out the error reg bytearray outputstream.?
PdfReader pdfReader = new PdfReader(
"C:\\POC\\HelloWorld2.pdf");
ByteArrayOutputStream bao = new ByteArrayOutputStream();
PdfStamper pdfStamper = new PdfStamper(pdfReader, bao);
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat f = new SimpleDateFormat("MM/dd/yyyy");
String signatureDate = f.format(currentDate.getTime());
ct.setAlignment(Element.ALIGN_CENTER);
ct.setSimpleColumn(50, 500, 500, 50);
ct.addText(new Chunk("Current Date : " + signatureDate));
ct.go();
Thanks,
Suguna
Suguna Devarla
Greenhorn
Posts: 11
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I am trying this Itext libraries.Any reply will be appreciated.
Thanks in advance
Thanks in advance
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
How are you saving the ByteArrayOutputStream?
Suguna Devarla
Greenhorn
Posts: 11
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I am not saving boa object , I am thinking PdfStamper pdfStamper = new PdfStamper(pdfReader,bao) will automatically takes care of that.
Can you tell me wts the code I need to add in order to get the text in same Pdf instaed of careting new one.
Thanks
Can you tell me wts the code I need to add in order to get the text in same Pdf instaed of careting new one.
Thanks
Suguna Devarla
Greenhorn
Posts: 11
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I have added below code but still no luck..Can any one explain how to add content to exisitng pdf with out creating a new different physical file
I wanted to see the new content in same "HelloWorld2.pdf"
PdfReader pdfReader = new PdfReader(
"C:\\POC\\HelloWorld2.pdf");
ByteArrayOutputStream bao = new ByteArrayOutputStream();
PdfStamper pdfStamper = new PdfStamper(pdfReader, bao);
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat f = new SimpleDateFormat("MM/dd/yyyy");
String signatureDate = f.format(currentDate.getTime());
ct.setAlignment(Element.ALIGN_CENTER);
ct.setSimpleColumn(50, 500, 500, 50);
ct.addText(new Chunk("Current Date : " + signatureDate));
ct.go();
PdfCopy copy = new PdfCopy(doc, bao);
copy.addPage(copy.getImportedPage(pdfReader, 1));
I wanted to see the new content in same "HelloWorld2.pdf"
PdfReader pdfReader = new PdfReader(
"C:\\POC\\HelloWorld2.pdf");
ByteArrayOutputStream bao = new ByteArrayOutputStream();
PdfStamper pdfStamper = new PdfStamper(pdfReader, bao);
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat f = new SimpleDateFormat("MM/dd/yyyy");
String signatureDate = f.format(currentDate.getTime());
ct.setAlignment(Element.ALIGN_CENTER);
ct.setSimpleColumn(50, 500, 500, 50);
ct.addText(new Chunk("Current Date : " + signatureDate));
ct.go();
PdfCopy copy = new PdfCopy(doc, bao);
copy.addPage(copy.getImportedPage(pdfReader, 1));
Tim Moores
Bartender
Posts: 7645
178
posted 13 years ago
No. That just saves the altered PDF in the BAOS. You still need to write the contents of the BAOS to a file.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I am not saving boa object , I am thinking PdfStamper pdfStamper = new PdfStamper(pdfReader,bao) will automatically takes care of that.
No. That just saves the altered PDF in the BAOS. You still need to write the contents of the BAOS to a file.
Suguna Devarla
Greenhorn
Posts: 11
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
how do i do that.
I did it using servlet using response object.
ServletOutputStream out = response. getOutputStream();
baos.writeTo(out);
I did it using servlet using response object.
ServletOutputStream out = response. getOutputStream();
baos.writeTo(out);
Suguna Devarla
Greenhorn
Posts: 11
posted 13 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I tried writing byte array output stream to a file after saving it throws me ane error.Below is the line of code added to the program.
bao.writeTo(new FileOutputStream("C:\\Suguna\\POC\\HelloWorld2.pdf"));
Here is the exception.. any reply would be a big help.
java.io.IOException: PDF header signature not found.
at com.lowagie.text.pdf.PRTokeniser.checkPdfHeader(PRTokeniser.java:204)
bao.writeTo(new FileOutputStream("C:\\Suguna\\POC\\HelloWorld2.pdf"));
Here is the exception.. any reply would be a big help.
java.io.IOException: PDF header signature not found.
at com.lowagie.text.pdf.PRTokeniser.checkPdfHeader(PRTokeniser.java:204)
| Lookout! Runaway whale! Hide behind this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |






