0
我在下面給出了html,當我使用飛碟將其轉換爲PDF時,它不適合A4人像尺寸。如何生成橫向pdf文件。想使用飛碟生成風景pdf
<html>
<head>
<title>
Selenium Test SC
</title>
</head>
<body style='font-family:Tahoma;font-size:9pt;letter-spacing:0.5px'>
<table border='1' style='color:black;font-size:12px;'>
<tr>
<td>
<a href="file:///C:/Users/611066167/Documents/Sel%20Test%20Result/Screenshots/Screen1.png" target="_blank">
NGSD:TMD (Search)
<img src="file:///C:/Users/611066167/Documents/Sel%20Test%20Result/Screenshots/Screen1.png" title="NGSD:TMD (Search)" style="width:100%;height:100%" alt="NGSD:TMD (Search)" border="0">
</a>
</td>
</tr>
</table>
</body>
</html>
我使用如下代碼轉換HTML到PDF
inputFile = "C:/Users/611066167/Documents/Sel Test Result/screenfile.html";
outputFile = "C:/Users/611066167/Documents/Sel Test Result/screenfile.pdf";
generatePDF(inputFile, outputFile);
public void generatePDF(String inputHtmlPath, String outputPdfPath)
{
try
{
String url = new File(inputHtmlPath).toURI().toURL().toString();
System.out.println("URL: " + url);
OutputStream out = new FileOutputStream(outputPdfPath);
// Flying Saucer part
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(url);
renderer.layout();
renderer.createPDF(out);
out.close();
}
catch (DocumentException | IOException e)
{
// TODO Auto-generated catch block e.printStackTrace();
}
}
飛碟不是iText產品。如果您想用iText將HTML轉換爲PDF,那麼您需要使用pdfHTML:http://itextpdf.com/blog/pdfhtml-configuration-options使用接受「PdfDocument」實例的方法,並在'PdfDocument'級別。 –