[英]Pdf in Landscape using pdfBox
目前我正在使用Apache的PDFBox生成pdf。 它在肖像模式下工作得非常好,但后來我的要求是前兩頁應該是橫向模式,然后是所有其他頁面的縱向。
所以任何人都可以幫助我如何在橫向創建PDF並實現此功能?
注意:我無法從PDFBox切換到其他庫
另一個解決方案是
PDPage page = new PDPage(new PDRectangle(PDRectangle.A4.getHeight(), PDRectangle.A4.getWidth()));
有兩種策略:
1)指定橫向媒體箱(這是用於A4):
float POINTS_PER_INCH = 72;
float POINTS_PER_MM = 1 / (10 * 2.54f) * POINTS_PER_INCH;
new PDPage(new PDRectangle(297 * POINTS_PER_MM, 210 * POINTS_PER_MM));
2)分配縱向媒體框,旋轉頁面並旋轉CTM, 如官方示例所示 :
PDPage page = new PDPage(PDRectangle.A4);
page.setRotation(90);
doc.addPage(page);
PDRectangle pageSize = page.getMediaBox();
float pageWidth = pageSize.getWidth();
PDPageContentStream contentStream = new PDPageContentStream(doc, page, AppendMode.OVERWRITE, false);
// add the rotation using the current transformation matrix
// including a translation of pageWidth to use the lower left corner as 0,0 reference
contentStream.transform(new Matrix(0, 1, -1, 0, pageWidth, 0));
(...)
以下為我工作。
float POINTS_PER_INCH = 72;
float POINTS_PER_MM = 1 / (10 * 2.54f) * POINTS_PER_INCH;
PDPage page = new PDPage(new PDRectangle(400 * POINTS_PER_MM, 210 * POINTS_PER_MM));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.