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);
PdfWriter.getInstance(document,System.out);
PdfWriter.getInstance(document,new
FileOutputStream("C:/shib/PHP SQL UNIX INTERVIEW HELPER.pdf"));
document.open();
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=";
while((count=zip.read(data,0,1024))!=-1)
{
text=new String(data);
document.add(new Paragraph(text));
}
}
document.close();
}
}
Its working and you can use
Edited by estipendio, 14 October 2021 - 01:07 PM.