2017-06-22 11 views
0

フライングソーサーを使用してこれをPDFに変換するとき、私は以下のhtmlを私に与えています。風景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>

私が使用して、あなたはCSSを使って風景モードでページを設定することができ

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(); 
    } 
} 
+0

Flying SaucerはiText製品ではありません。 HTMLをiTextでPDFに変換する場合は、pdfHTMLを使用する必要があります:http://itextpdf.com/blog/pdfhtml-configuration-options 'PdfDocument'インスタンスを受け入れるメソッドを使用し、ページサイズを'PdfDocument'レベルです。 –

答えて

1

HTMLをPDFに変換するために下記のコードを使用しています:

<style> 
    @page { size: A4 landscape;} 
</style> 

ページサイズはCSS 3仕様の一部で、フライでサポートされています食べる皿。

関連する問題