我目前正在从 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();