1
我有一个HTML文件,其中有二进制形式的图像。
我想用java将它转换成pdf。
任何人都可以请帮助我吗? 和HTML文件中包含的Base64图像文件Html二进制图像到PDF在java
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.XMLWorkerHelper;
import com.itextpdf.text.Chunk;
public class Test{
public static void main(String args[]){
try {
Document document = new Document();
// step 2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Test.pdf"));
// step 3
document.open();
document.newPage();
document.add(new Chunk(""));
// step 4
XMLWorkerHelper.getInstance().parseXHtml(writer, document,new FileInputStream("/home/farheen/workspace/html.to.pdf/test.html"));
//step 5
document.close();
System.out.println("PDF Created!");
}catch (Exception e) {
e.printStackTrace();
}
}
}
@MaVRoSCy我已经编辑我的问题。请看看它。 – FarheenP