I understand that I need to close the PdfStamper before it would write
anything.
I also know that I should setCloseStream as false if I want to keep on
appending stuffs to the outputStream (I read this from searching in the
mailing list reply).

Here is the additional snippets that I didn't add:
PdfImportedPage page = stamper.getImportedPage(reader, 1);
over = stamper.getOverContent(1);
over.beginText();
over.setFontAndSize(bf, 18);
over.showTextAligned(Element.ALIGN_LEFT,
        "DUPLICATE OF AN EXISTING PDF DOCUMENT", 30, 600, 0);
over.endText();
stamper.getWriter().setCloseStream(false);
stamper.close();

However, it still doesn't work.
The only way to make it work is to create a new FileOutputStream and write
it to another file.
I could do that, and then import the temporary file into the main stream,
and then delete the temporary file, but that would be extra un-necessary
processing if I could find a way to output PdfStamper to the same file (via
the main writer, or the same FileOutputStream that creates the main writer).
Meanwhile, I will try to read the documentation again, it seemed that I
don't understand how output stream works.


Paulo Soares-3 wrote:
> 
>  
> 
>> -----Original Message-----
>> From: rorostar [mailto:[email protected]] 
>> Sent: Tuesday, February 10, 2009 4:57 PM
>> To: [email protected]
>> Subject: [iText-questions] PdfStamper appending to existing file
>> 
>> 
>> Hi,
>> 
>> I have a question regarding PdfStamper.
>> 
>> Here is the code snippets 
>> 
>> 
>> FileOutputStream outputStream = new
>> FileOutputStream("C:\\Java\\HelloWorld.pdf");
>> PdfWriter writer = PdfWriter.getInstance(document, outputStream);
>> document.open();
>> //add stuffs to documents
>> 
>> //This is the file to copy
>> PdfReader reader = new PdfReader(new
>> FileInputStream("c:\\java\\original.pdf"));
>> 
>> //how do I create a PdfStamper and redirecting the output to 
>> the existing
>> writer so it could be appended to the same file? 
>> //Most examples force the user to create another PDF file
>> //I tried using outputStream and it didn't work.
>> PdfStamper stamper = new PdfStamper(reader, outputStream);
>> 
>> Any suggestion?
>> 
> 
> Read the documentation and don't invent. That's done by importing pages
> and you'll always need to close the PdfStamper before doing it but it may
> reside in memory.
> 
> 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.
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> Create and Deploy Rich Internet Apps outside the browser with
> Adobe(R)AIR(TM)
> software. With Adobe AIR, Ajax developers can use existing skills and code
> to
> build responsive, highly engaging applications that combine the power of
> local
> resources and data with the reach of the web. Download the Adobe AIR SDK
> and
> Ajax docs to start building applications
> today-http://p.sf.net/sfu/adobe-com
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> 
> Buy the iText book: http://www.1t3xt.com/docs/book.php
> 

-- 
View this message in context: 
http://www.nabble.com/PdfStamper-appending-to-existing-file-tp21937884p21938906.html
Sent from the iText - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to