Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

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
  • 7,892 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