Tag: pdfbox

如何使用pdfbox从pdf中提取粗体文本?

我正在使用Apache pdfbox来提取文本。 我可以从pdf中提取文本,但我不知道如何知道这个词是否是粗体??? (代码建议会很好!!!)这是从pdf中提取纯文本的代码,该代码工作正常。 PDDocument document = PDDocument .load(“/home/lipu/workspace/MRCPTester/test.pdf”); document.getClass(); if (document.isEncrypted()) { try { document.decrypt(“”); } catch (InvalidPasswordException e) { System.err.println(“Error: Document is encrypted with a password.”); System.exit(1); } } // PDFTextStripperByArea stripper = new PDFTextStripperByArea(); // stripper.setSortByPosition(true); PDFTextStripper stripper = new PDFTextStripper(); stripper.setStartPage(1); stripper.setEndPage(2); stripper.setSortByPosition(true); String st = stripper.getText(document);

用PDFBOX写阿拉伯语并使用正确的字符表示forms而不分开

我正在尝试使用PDFBox Apache生成包含阿拉伯文本的PDF,但文本生成为单独的字符,因为Apache将给定的阿拉伯字符串解析为一系列通用的“官方”Unicode字符,这些字符相当于孤立forms的阿拉伯字符。 这是一个例子: 目标文本以PDF格式写入“应该是PDF文件中的预期输出” – >جملةبالعربي 我在PDF文件中得到了什么 – > 我尝试了一些方法,但这里有一些没用: 1.将字符串转换为比特流并尝试提取正确的值 2.使用UTF-8 && UTF-16处理String一个字节序列并从中提取值 有一些方法似乎非常有希望获得每个字符的值“Unicode”但它生成一般“官方Unicode”这是我的意思 System.out.println( Integer.toHexString( (int)(new String(“كلمة”).charAt(1))) ); 输出是644但是fee0是预期的输出,因为这个字符在中间从那时起我应该得到中间的Unicode费用0 所以我想要的是一些生成正确Unicode的方法,而不仅仅是正式的Unicode 以下链接中第一个表中的“Left”列表示常规Unicode 阿拉伯语Unicode表维基百科

pdfbox 2.0.2>调用PageDrawer.processPage方法捕获exception

作为pdfbox 2.0.2( https://github.com/apache/pdfbox/tree/2.0.2 )用户的新手,我想得到所有描边线(例如,表的列和行边框)页面(PDPage),因此我创建了以下类:package org.apache.pdfbox.rendering; import java.awt.geom.GeneralPath; import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; import org.apache.commons.io.IOUtils; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.rendering.PDFRenderer; import org.apache.pdfbox.rendering.PageDrawer; import org.apache.pdfbox.rendering.PageDrawerParameters; public class LineCatcher { private PageDrawer pageDrawer; private PDDocument document; private PDFRenderer pdfRenderer; private PDPage page; public LineCatcher(URI pdfSrcURI) throws IllegalArgumentException, MalformedURLException, IOException { this.document = PDDocument.load(IOUtils.toByteArray(pdfSrcURI)); this.pdfRenderer = new […]

使用Java从PDF中提取图像

我需要仅从PDF中提取条形码(使用矩形),而不是将整个PDF转换为图像。 图像格式可以是jpg / png。

将PDF转换为多页tiff(第4组)

我正在尝试将org.apache.pdfbox.pdmodel.PDDocument类和icafe库( https://github.com/dragon66/icafe/ )所代表的PDF转换为具有第4组压缩和300 dpi的多页tiff 。 示例代码适用于我288 dpi,但奇怪的是不是300 dpi,导出的tiff仍然只是白色。 有谁知道这里的问题是什么? 我在示例中使用的示例pdf位于: http : //www.bergophil.ch/a.pdf import java.awt.image.BufferedImage; import java.io.FileOutputStream; import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import cafe.image.ImageColorType; import cafe.image.ImageParam; import cafe.image.options.TIFFOptions; import cafe.image.tiff.TIFFTweaker; import cafe.image.tiff.TiffFieldEnum.Compression; import cafe.io.FileCacheRandomAccessOutputStream; import cafe.io.RandomAccessOutputStream; public class Pdf2TiffConverter { public static void main(String[] args) { String pdf = “a.pdf”; PDDocument pddoc = null; […]

PDFBox:将pdf页面转换为图像的问题

我的任务非常简单:将pdf文件的每一页转换为图像。 我尝试使用icepdf开源版本来生成图像,但它们不会生成具有正确字体的图像。 所以我开始使用PDFBox。 代码如下: PDDocument document = PDDocument.load(new File(“testing.pdf”)); List pages = document.getDocumentCatalog().getAllPages(); for (int i = 0; i < pages.size(); i++) { PDPage singlePage = pages.get(i); BufferedImage buffImage = convertToImage(singlePage, 8, 12); ImageIO.write(buffImage, "png", new File(PdfUtil.DATA_OUTPUT_DIR+(count++)+".png")); } 字体看起来不错,但pdf文件中的图片看起来很晕眩(参见附件)。 我查看源代码,但我仍然不知道如何解决它。 你们有什么想法发生了什么事吗? 请帮忙。 谢谢!!

使用PDFBox加水印

我正在尝试使用PDFBox专门为PDF添加水印。 我已经能够让图像显示在每个页面上,但它会失去背景透明度,因为它看起来好像PDJpeg将其转换为JPG。 也许有一种方法可以使用PDXObjectImage来完成它。 这是我到目前为止所写的内容: public static void watermarkPDF(PDDocument pdf) throws IOException { // Load watermark BufferedImage buffered = ImageIO.read(new File(“C:\\PDF_Test\\watermark.png”)); PDJpeg watermark = new PDJpeg(pdf, buffered); // Loop through pages in PDF List pages = pdf.getDocumentCatalog().getAllPages(); Iterator iter = pages.iterator(); while(iter.hasNext()) { PDPage page = (PDPage)iter.next(); // Add watermark to individual page PDPageContentStream stream = […]