开发者

PDFBox setting A5 page size

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜