Instead of inventing why don't you read the tutorial at http://itextdocs.lowagie.com/tutorial/?
Paulo ----- Original Message ----- From: "Ayusman Dikshit" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Monday, March 19, 2007 7:10 AM Subject: [iText-questions] writing to a PDF document. > Hi All, > I am trying to write content to an PDF file, after reading it through the > iText API. > Even though I add a Chunk/Author information to the PDF file, I am unable > to get those information on the PDF file. (The file size does not change.) > Can any one tell me the reason why is it so? > > Please go through the code belo: > File: Example3.java > =================== > > package com.xxx.yy.printpdf; > import java.awt.Color; > import java.io.FileInputStream; > import java.io.InputStream; > import java.io.OutputStream; > import java.io.FileOutputStream; > import java.io.IOException; > import com.lowagie.text.Chunk; > import com.lowagie.text.Document; > import com.lowagie.text.FontFactory; > import com.lowagie.text.PageSize; > import com.lowagie.text.Paragraph; > import com.lowagie.text.pdf.PdfReader; > import com.lowagie.text.pdf.PdfWriter; > import com.lowagie.text.Font; > > public class Example3 > { > public static void main(String[] args) > { > try > { > > FileInputStream fis = new FileInputStream ("C:\\TestRead.pdf"); > System.out.println("1. the length is:: "+fis.available()); > //PdfReader pdfreader = new PdfReader( (InputStream)( fis)); > > //Create a Document. > Document document = new Document(); > document.addAuthor("Bruno Lowagie"); > //Open the document.. > document.open(); > > //Create an FileOutputStream > FileOutputStream fos = new FileOutputStream("C:\\TestWrite.pdf"); > System.out.println("Calling the copyStream method"); > > //Write the full inputstream to this new File.. this is done by calling > the copyStreams() method. > copyStreams(fis, fos); > //Create a Writer from the document and OutputStream > PdfWriter pdfwriter = PdfWriter.getInstance(document,fos); > Chunk chunk = new Chunk("Hello world", > FontFactory.getFont(FontFactory.COURIER, 20, Font.ITALIC, new Color(255, > 0,0))); > document.add(chunk); > document.add(new Chunk("Silent Auto Print")); > > document.setJavaScript_onLoad("alert('Hi there...');"); > > //Flush the output stream. > fos.flush(); > > //pdfreader.close (); > pdfwriter.close(); > fis.close(); > fos.close(); > } > catch(Exception e) > { > e.printStackTrace(); > } > > } > > public static void copyStreams(InputStream is, OutputStream os) > { > try > { > if (null != is) > { > byte[] b = new byte[1]; > System.out.println("In copyStream method..the length is:: > "+is.available()); > while(is.available() > 0) > { > //System.out.println("A byte of data read from input stream"); > //Read one byte of data from the input stream > is.read(b); > > //Write one byte of data to the output stream > os.write(b); > //System.out.println("b is:: "+b); > } > } > > } > catch(IOException ioe) > { > System.out.print("IOException occured in copyStreams method...."); > ioe.printStackTrace(); > } > catch(Exception e) > { > System.out.print("Unknown Exception occured in copyStreams method...."); > e.printStackTrace(); > } > > }//End of copyStreams(). > } > > Please advise if I have done anything wrong. > > Regards > Ayusman > > > > ___________________________________________________________ > Copy addresses and emails from any email account to Yahoo! Mail - quick, > easy and free. http://uk.docs.yahoo.com/trueswitch2.html -------------------------------------------------------------------------------- > ------------------------------------------------------------------------- > 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 > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions > Buy the iText book: http://itext.ugent.be/itext-in-action/ > ------------------------------------------------------------------------- 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 [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/
