使用PDFBox从Java编辑PDF [英] Editing PDF from Java Using PDFBox

查看:658
本文介绍了使用PDFBox从Java编辑PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 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();

推荐答案

我用来执行此操作的代码是正确的.

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

问题不是代码,而是pdf的生成方式为1.2版. 我需要知道如何更改一个V 1.2版本的PDF

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

这篇关于使用PDFBox从Java编辑PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆