2

我目前正在从 PDF 中获取一个页面,然后尝试编辑该特定页面。当我进行编辑时,它不会保存在 PDF 本身中。

这是我的代码,有人可以帮忙。

PDPage page = (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();
4

2 回答 2

0

我正在使用的代码是正确的。

问题不在于代码,而在于生成 pdf 的方式是 1.2 版。我需要能够知道我可以做些什么来更改一个 V 1.2 的 PDF

于 2011-09-02T06:47:54.840 回答
0

请使用/更新以下代码

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

它为我工作

于 2016-05-06T21:10:08.893 回答