开发者

PDFBox setting A5 page size

开发者 https://www.devze.com 2023-01-04 20:07 出处:网络
Started playing with PDFBox PDDocument document = new PDDocument(); PDPage page = new PDPage(); document.addPage( page );

Started playing with PDFBox

PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage( page );

PDFont font = PDType1Font.HELVETICA_BOLD;
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.beginText();
contentStream.setFont( font, 12 );
contentStream.moveTextPositionByAmount( 100, 700 );
contentStream.drawString( "Hello World" );
contentStream.endText();
contentStream.close();

document.save("Page.pdf");
document.close();

but I want to set the file size to be PDPage.PAGE_SIZE_A5. I've tried setting all the setXXXBox(PDRectangle mediaBox) method signatures but I can't get the expected output.

page.setArtBox(PDPage.PAGE_SIZE_A5); // ??
p开发者_运维技巧age.setMediaBox(PDPage.PAGE_SIZE_A5); // ??

Any ideas?


Quick note: in PDFBox 2 replace PDPage.PAGE_SIZE_A5 with PDRectangle.A5, i.e.

PDPage page = new PDPage(PDRectangle.A5);


Use PDPage.PAGE_SIZE_A5 to change size to A5

PDPage page = new PDPage(PDPage.PAGE_SIZE_A5);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号