Hi.
I'm trying to convert Microsoft Word (doc and docx) files to PDF.
For the last couple of days i have been reading forums and the general idea is:
*1.* Use OpenOffice to convert you document into PDF
*2.* Use a PDF Printer too convert do PDF.
I already implemented the first solution, however the result PDF is not always similar to the input document. Because of that, i'm trying to implement solution 2.
I've installed a PDF Printer (CutePDF - http://www.cutepdf.com/Products/CutePDF) and i'm trying to use JAVA Print API to send my documents to that printer. However, i have only been able to print PNG or GIF images into PDF. I have not succeeded to print txt or doc files.
Here is my code:
PrintServiceAttributeSet printServiceAttributes = new HashPrintServiceAttributeSet();
printServiceAttributes.add(new PrinterName("CutePDF Writer", null));
PrintService[] defaultPrintService = PrintServiceLookup.lookupPrintServices(null, printServiceAttributes);
DocPrintJob printerJob = defaultPrintService[0].createPrintJob();
File inputFile = new File("c:\\image.png");
FileInputStream fis = new FileInputStream(inputFile);
SimpleDoc simpleDoc = new SimpleDoc(fis, DocFlavor.INPUT_STREAM.PNG, null);
printerJob.print(simpleDoc, null);
With this code i create a PDF file containing the png image. If i try to print a txt file, or a doc file, creating the SimpleDoc like this:
SimpleDoc simpleDoc = new SimpleDoc(fis, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
The output is an empty PDF File.
Can anyone help me?
Thanks in advance.
João Simas