开发者

Editing PDF from Java Using PDFBox

I am currently getting a page from a PDF and then trying to edit that particular page. When i do the edit it is not saving within the PDF itself.

This is my code could someone please help.

PDPage pag开发者_如何学编程e = (PDPage) allPages.get(f);
System.out.println(page);
PDRectangle pageSize = page.findMediaBox();
float stringWidth = font.getStringWidth( "AAA" );
float centeredPosition = (pageSize.getWidth() - (stringWidth*fontSize)/1000f)/2f;

PDPageContentStream contentStream = new PDPageContentStream(pdoc,page,true,false);

contentStream.beginText();
contentStream.setFont( font, fontSize );
//contentStream.addLine(700, 700, 700, 1000);
contentStream.moveTextPositionByAmount(0 , 0);
contentStream.drawString( "AAA" );
contentStream.endText();
contentStream.close();

pdoc.save("C:/1/1.pdf");
pdoc.close();


The code is with which I am doing this is correct.

The problem is not the code but the way the pdfs are being generated are at a Version 1.2. I would need to be able know what I can do to alter PDFs that are one V 1.2


please use/update below code

contentStream = new PDPageContentStream(
                document, page, true, true);

Its working for me

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜