想要使用飞碟生成风景pdf [英] Want to generate landscape pdf using Flying Saucer
本文介绍了想要使用飞碟生成风景pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用飞碟将其转换为PDF时,我在下面给出了html,它不适合A4纵向尺寸.如何生成横向pdf文件.
I am having below given html with me, when I am converting this to PDF using flying saucer, It is not fitting A4 Portrait size. How to generate landscape pdf file.
<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
I am using below given code for converting html to 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();
}
}
推荐答案
您可以使用CSS在横向模式下设置页面,
You can set your page in landscape mode using CSS, using:
<style>
@page { size: A4 landscape;}
</style>
页面大小是CSS 3规范的一部分,并且受飞碟支持.
The page size is part of CSS 3 specification, and is supported by flying saucer.
这篇关于想要使用飞碟生成风景pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文