Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account

example Java Code to Convert any Word Document to PDF File

  • Please log in to reply



    New Member

  • Member
  • Pip
  • 1 posts

I am trying to convert .doc,.xls,.txt,.html to .pdf format, but have not been successful. Please help me with a proper sample code or tutorial to convert any word and html document (.doc,.xls,.txt,.html ) to .pdf format. I tried with the below code, but it is converting the text part only and rest in some ambiguous format.

package our_app;



import java.io.*;
import java.awt.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.io.*;
import java.util.zip.*;
import javax.swing.text.Document;
public class FirstPdf
public static void main(String arg[])throws Exception
System.out.println("Hello RoseIndia");
Document document = new Document(PageSize.A4, 36, 72, 108, 180);
FileOutputStream("C:/shib/PHP SQL UNIX INTERVIEW HELPER.pdf"));
ZipInputStream zip = new ZipInputStream(new
BufferedInputStream(new FileInputStream("C:/shib/PHP SQL UNIX INTERVIEW HELPER.zip")));
ZipEntry entry;
while((entry = zip.getNextEntry()) != null)
byte data[]=new byte[1024];
int count;
String text=";
text=new String(data);
document.add(new Paragraph(text));


Its working and you can use

Edited by estipendio, 14 October 2021 - 01:07 PM.

  • 0




    Trusted Helper

  • Malware Removal
  • 8,033 posts

Have a look here,


Sample Java Code to Convert any Word Document to PDF File | Toolbox Tech

  • 0

Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP