나는 pdf에 html로 변환하는 것은 더 생각한다 이다. 먼저 jtidy 라이브러리 을 사용하여 .html 파일을 .xhtml 파일로 변환하십시오. b. 두 번째 변환은 itextrender에게 코드
을 여기
입니다 사용하여 .pdf 파일에 .xhtml 파일을 결과.
FileInputStream fis = null;
try
{
fis = new FileInputStream("D://Html//junitnoframes.html");
}
catch (java.io.FileNotFoundException e)
{
System.out.println("File not found: ");
}
Tidy tidy = new Tidy();
tidy.setShowWarnings(false);
tidy.setXmlTags(false);
tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setXHTML(true);//
tidy.setMakeClean(true);
Document xmlDoc = tidy.parseDOM(fis, null);
try
{
tidy.pprint(xmlDoc,new FileOutputStream("D://Html//msc.xhtml"));
}
catch(Exception e)
{
}
b.
public static void main(String[] args)
throws IOException, DocumentException {
String inputFile = "D://Html//msc.xhtml";
String url = new File(inputFile).toURI().toURL().toString();
String outputFile = "D://Html//secondsdoc.pdf";
OutputStream os = new FileOutputStream(outputFile);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(os);
os.close();
}
기존 생성 된 HTML 보고서를 PDF 형식으로 나타내야했습니다. 예산과 시간 제한으로 인해 생성 된 HTML에서 실행되는 변환기를 찾는 것이 유일한 방법이었습니다. 약 4 라이브러리와 내가 얻을 수있는 최상의 결과를 시도 : http://pd4ml.com –
사람이 몇 가지 새로운 라이브러리를 알고 있습니까? 이 것들은 약간 구식 인 것 같습니다. – dege