Tag: pdfbox

如何使用PDFBox 2.0创建单选按钮组

我想使用PDFBox 2.0创建一个单选按钮组,我能够创建3个单选按钮,但我无法弄清楚如何对它们进行分组(PDFBox 1.8,使用了PDRadioCollection ,但2.0没有。)。 如何使用PDFBox 2.0创建单选按钮组? 这是我目前的代码: PDDocument document = new PDDocument(); PDPage page = new PDPage(PDRectangle.A4); document.addPage(page); PDAcroForm acroForm = new PDAcroForm(document); acroForm.setNeedAppearances(true); document.getDocumentCatalog().setAcroForm(acroForm); PDResources res = new PDResources(); COSName fontName = res.add(PDTrueTypeFont.load(document, new FileInputStream(“C:/Windows/Fonts/arial.ttf”), StandardEncoding.INSTANCE)); acroForm.setDefaultResources(res); acroForm.setDefaultAppearance(‘/’ + fontName.getName() + ” 10 Tf 0 g”); PDPageContentStream contents = new PDPageContentStream(document, page); List options […]

如何使用Java PDFBOX api检查PDF格式的复选框

如何使用Java PDFBOX api检查PDF格式的复选框 最初我尝试使用下面的代码,但执行后复选框字段在PDF中是不可见的,但它已被检查..如何避免这种情况或他们实现的方式是错误的? 谁能帮我吗 public void check() throws Exception { PDDocument fdeb = null; fdeb = PDDocument.load( “C:\\Users\\34\\Desktop\\complaintform.pdf” ); PDAcroForm form = fdeb.getDocumentCatalog().getAcroForm(); PDField feld3 = form.getField( “check” ); feld3.setValue(“check”); fdeb.save(“C:\\Users\\34\\Desktop\\complaintform.pdf”); fdeb.close(); } 谢谢

BufferedImage颜色饱和度

我正在使用jfreesane和Apache PDFBox编写一个简单的扫描应用程序。 这是扫描码: InetAddress address = InetAddress.getByName(“192.168.0.17”); SaneSession session = SaneSession.withRemoteSane(address); List devices = session.listDevices(); SaneDevice device = devices.get(0); device.open(); device.getOption(“resolution”).setIntegerValue(300); BufferedImage bimg = device.acquireImage(); File file = new File(“test_scan.png”); ImageIO.write(bimg, “png”, file); device.close(); 并制作PDF: PDDocument document = new PDDocument(); float width = bimg.getWidth(); float height = bimg.getHeight(); PDPage page = new PDPage(new PDRectangle(width, height)); […]

使用PDFBox从特定页面读取文本

我知道如何使用PDFTextStripper.getText(PDDocument)使用PDFBox读取整个pdf文件的文本。 我还有一个关于如何使用PDDocumentCatalog.getAllPages().get(i)对象引用的示例PDDocumentCatalog.getAllPages().get(i) 。 如何使用PDFBox获取一个页面的文本,因为我在PDPage类PDPage不到任何此类方法?

使用PDFBox添加页码

如何将页码添加到使用PDFBox生成的文档中的页面? 合并不同的PDF后,有人能告诉我如何在文档中添加页码吗? 我在Java中使用PDFBox库。 这是我的代码,它运行良好,但我需要添加页码。 PDFMergerUtility ut = new PDFMergerUtility(); ut.addSource(“c:\\pdf1.pdf”); ut.addSource(“c:\\pdf2.pdf”); ut.addSource(“c:\\pdf3.pdf”); ut.mergeDocuments();

无法弄清楚如何使用PDFBox

我正在尝试创建一个PDF文件,其中包含文档中的大量文本框和来自其他类的文本框。 我正在使用PDFBox。 好的,创建一个新文件很简单,编写一行文本很容易。 现在,当我尝试插入下一个文本行或文本字段时,它会覆盖内容。 PDDocument doc = null; PDPage page = null; try{ doc = new PDDocument(); page = new PDPage(); doc.addPage(page); PDFont font = PDType1Font.HELVETICA_BOLD; PDPageContentStream title = new PDPageContentStream(doc, page); title.beginText(); title.setFont( font, 14 ); title.moveTextPositionByAmount( 230, 720 ); title.drawString(“DISPATCH SUMMARY”); title.endText(); title.close(); PDPageContentStream title1 = new PDPageContentStream(doc, page); title1.beginText(); title1.setFont( font, 11 […]

使用PDFBox动态创建多页面文档

我正在尝试从Java ResultSet创建PDF报告。 如果报告只有一页,我在这里没问题。 问题来自报告可能长达一到十页的事实。 现在,我有这个来创建一个单页文档: PDDocument document = new PDDocument(); PDPage page = new PDPage(PDPage.PAGE_SIZE_LETTER); document.addPage(page); PDPageContentStream content = new PDPageContentStream(document,page); 所以我的问题是,如何根据需要动态创建页面。 是否有一个面向对象的答案盯着我的脸,我只是看不到它?

确定PDF页面是包含文本还是纯图片

如何使用Java确定PDF页面是包含文本还是纯图片? 我搜索了很多论坛和网站,但我找不到答案。 是否可以从PDF中提取文本,以了解页面是格式图片还是文本? PdfReader reader = new PdfReader(INPUTFILE); PrintWriter out = new PrintWriter(new FileOutputStream(OUTPUTFILE)); for (int i = 1; i <= reader.getNumberOfPages(); i++) { // here I want to test the structure of the page !!!! if it's possible out.println(PdfTextExtractor.getTextFromPage(reader, i)); }

如何使用java读取pdf中的控制字符

我正在使用PDFBox来阅读PDF文件。 但有些字符打印效果不佳,打印效果与控制字符类似。 有人帮助从控制字符中读取值。 我已附上图片请看一下图片示例PDF: 截图: 示例代码 class PDFManager { private PDFParser parser; private PDFTextStripper pdfStripper; private PDDocument pdDoc ; private COSDocument cosDoc ; private String Text ; private String filePath; private File file; public PDFManager() { } public String ToText() throws IOException { this.pdfStripper = null; this.pdDoc = null; this.cosDoc = null; file = new […]

pdfbox – 签署横向文件错误

我使用pdfbox-1.8.8在PDF文件上执行签名function。 它在纵向模式下适用于PDF文件。 但是对于横向文件,我有一个问题 看起来景观文件的坐标是错误的。 有谁知道文件有什么问题? 这是pdf文件的链接 这是我用来签名的代码 public void signDetached(String inputFilePath, String outputFilePath, String signatureImagePath, Sign signProperties) { OutputStream outputStream = null; InputStream inputStream = null; PDDocument document = null; InputStream signImageStream = null; try { setTsaClient(null); document = PDDocument.load(inputFilePath); // create signature dictionary PDSignature signature = new PDSignature(); signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE); signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED); signature.setName(“VANDUC1102”); signature.setLocation(null); String displayName […]