My Java code is,
Document doc=new Document();
PdfWriter.getInstance(doc, response.getOutputStream());
doc.open();
doc.add( new Paragraph( "Hello, World!" ) );
doc.close();
file.close();
With this code, I can able to generate the PDF file with the content "Hello, World!" on the fly.
Now, I have one external JAR to return me an document (com.lowagie.text.Document). I need to generate this document on the fly. I have tried the following,
Document doc=new Document();
PdfWriter.getInstance(doc, response.getOutputStream());
doc.open();
doc=method(); // returns me an pdf document
doc.close();
file.close();
It doesn't generated a document on the fly. This is because I have opened a document but not added the content.
My question is, how can I generate that document on the fly?
Also, I would like to add another try of mine. Code of method() is,
private Document method()throws DocumentException
{
Document doc1=new Document();
doc1.open();
doc1.add(new Paragraph("Success"));
doc1.close();
return doc1;
}
If I am passing document object in to that method it is working. Code is,
method(doc);
private void method(Document doc1)throws DocumentException
{
doc1.add(new Paragraph("Success"));
}
Is there anything that I am missing in my non-working code?