Hi, I am using the PDFWriter and Document classes of iText.jar file and trying to convert a ".doc" file to ".pdf" format. I am able to fetch the data and put it into a pdf file. But the ".doc" data being read contains some formatting information that is being appended to the content, in the beginnning and at the end. How to get rid of that code content in the PDF file through java code? I am trying this out as a stand alone API, which takes the "Document File Name" as command line argument.
I could successfully convert a ".txt" file into ".pdf". Also, can I insert a GIF into this PDF(just created) in a page that contains a particular text String ? Please send me the code piece, as I badly need that. Attaching a copy of the code that I am currently using. Regards, Subbu __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com
// This Java Class is to Convert a specified Document into a PDF Format
// This Takes a file as an input and Generates a PDF from this.
// Developed by S Subrahmanyam Mallela on 24/3/2003 for Sirvisetti Global Services
import java.util.*;
import java.io.*;
import java.sql.*;
// Custom Packages itext-1.0.0.jar
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
public class PdfGenerator
{
public PdfGenerator(String str)
{
String img_path = "";
String fax_no = "";
String tmpStr="";
String file_nm = "";
String fname = "";
String lname = "";
DocumentException ex = null;
Document doc = new Document();
PdfWriter docWriter = null;
RandomAccessFile raf = null;
try
{
raf = new RandomAccessFile(str,"r");
OutputStream os= new FileOutputStream("file_nm.pdf");
docWriter = PdfWriter.getInstance(doc,os);
docWriter.flush();
// Option to Hide the ToolBar and MenuBar
// docWriter.setViewerPreferences(PdfWriter.HideMenubar |
PdfWriter.HideToolbar);
// This piece of Code is for Embedding a GIF or JPG into the
PDF at the Desired Position
Watermark watermark = new
Watermark(Image.getInstance("img_path.gif"), 400, 90);
doc.add(watermark);
raf.close();
doc.open();
tmpStr = "";
raf = new RandomAccessFile(str,"r");
while((tmpStr=raf.readLine())!= null){
doc.add(new Paragraph(tmpStr));
}
raf.close();
}catch (DocumentException dex){
dex.printStackTrace();
System.out.println(this.getClass().getName()+ " caught
an exception: ");
}
catch (IOException ioe){
System.out.println(" caught an IO exception: "+ioe);
}
catch(Exception ioe){
ioe.printStackTrace();
System.out.println("Caught in Submethbod "+ioe);
}
finally {
if (doc != null){
doc.close();
}
if (docWriter != null){
docWriter.close();
}
}
}
// Main Method to create instance and invoke the Generator Method
public static void main(String args[]){
PdfGenerator sub = new PdfGenerator(args[0]);
}
}
file_name.pdf
Description: file_name.pdf
