Tag: pdf

PDFBox LayerUtility – 将图层导入现有PDF

我使用pdfbox来操作PDF内容。 我有一个很大的PDF文件(比如500页)。 我还有一些其他单页PDF文件只包含一个图像,最大每个文件大约8-15kb。 我需要做的是将这些单页pdf导入到大PDF文件的某些页面上。 我已经尝试了pdfbox的LayerUtility,我已经成功了但是它创建了一个非常大的文件作为输出。 在处理之前,源pdf大约是1MB,当添加较小的pdf文件时,大小达到64MB。 有时我需要将两个较小的PDF包含在较大的PDF中。 有没有更好的方法来做到这一点,还是我只是做错了? 在下面发布代码,尝试在单个页面上添加两个图层: … … .. overlayDoc[pCounter] = PDDocument.load(“data\\” + overlay + “.pdf”); outputPage[pCounter] = (PDPage) overlayDoc[pCounter].getDocumentCatalog().getAllPages().get(0); LayerUtility lu = new LayerUtility( overlayDoc[pCounter] ); form[pCounter] = lu.importPageAsForm( bigPDFDoc, Integer.parseInt(pageNo)-1); lu.appendFormAsLayer( outputPage[pCounter], form[pCounter], aTrans, “OVERLAY_”+pCounter ); outputDoc.addPage(outputPage[pCounter]); mOverlayDoc[pCounter] = PDDocument.load(“data\\” + overlay2 + “.pdf”); mOutputPage[pCounter] = (PDPage) mOverlayDoc[pCounter].getDocumentCatalog().getAllPages().get(0); LayerUtility lu2 […]

Jasper报告 – 在PDF文档中设置作者属性

有没有办法通过在从Java调用Jasper时设置参数来将Author属性设置为PDF文档。 这就是我从Java生成Jasper报告的方法。 JasperPrint jasperPrint; String outFile = “39285923953222.pdf”; HashMap hm = new HashMap(); hm.put(“ID”,id); hm.put(“FOOTER”,Constants.FOOTER); // Set somehow a string for the author name Session session = this.sessionFactory.openSession(); Connection con = session.connection(); jasperPrint = JasperFillManager.fillReport(jasperPath + “myReport.jasper”, hm, con); JasperExportManager.exportReportToPdfFile(jasperPrint, outPath + outFile);

如何使用iText为我的(pdf-)文本添加背景颜色以使用Java创建它

首先:我对用于创建pdf的框架的了解并不是最好的,请在回答时牢记这一点。 我需要一个框架/库,我可以用它在java中创建pdf文件,并且(重要的!)将文本放在某些x和y坐标处。 经过大量的研究,我经历过,我可以通过iText实现这一点。 这是一个简单的代码片段,基本上用iText中的文本显示我现在正在做的事情。 您只需将其复制到您的编程环境中,您只需要iText jar(可在此下载: http : //sourceforge.net/projects/itext/files/latest/download? source = files) import java.io.FileOutputStream; import com.itextpdf.text.Document; import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.pdf.PdfContentByte; import com.itextpdf.text.pdf.PdfWriter; public class PDFTesting { public static void main(String[] args) { Document document = new Document(); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(“output.pdf”)); document.open(); PdfContentByte cb = writer.getDirectContent(); int x = 100; int […]

从pdf文件中提取文本

我需要从pdf文件中提取文字(逐字逐句)。 import java.io.*; import com.itextpdf.text.*; import com.itextpdf.text.pdf.*; import com.itextpdf.text.pdf.parser.*; public class pdf { private static String INPUTFILE = “http://ontology.buffalo.edu/ontology%28PIC%29.pdf” ; private static String OUTPUTFILE = “c:/new3.pdf”; public static void main(String[] args) throws DocumentException, IOException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(OUTPUTFILE)); document.open(); PdfReader reader = new PdfReader(INPUTFILE); int n = […]

在Java中将PDF转换为Word

是否可以在Java中将PDF转换为Word? 我不是在谈论解析PDF文档,然后再自定义再渲染到Word。 我想要一个可以直接转换它的Java库。

从PDF中删除页面

我目前正在使用iText,我想知道是否有办法从PDF文件中删除页面? 我用读卡器等打开了它,我想删除一个页面然后保存回新文件; 我怎样才能做到这一点?

如何在iText XMLWorker中摆脱Helvetica?

我们使用iText从Java代码生成PDF文件,这在大多数情况下都能很好地工作。 几天前,我们开始生成PDF / A而不是普通的PDF文件,需要嵌入所有字体。 iText Document主要是自定义PdfPTable和其他类的构建,我们直接控制字体。 所有使用的字体都是通过以下代码加载的TTF文件创建的 – 这很好用: private BaseFont load(String path) { try { URL fontResource = PrintSettings.class.getResource(path); if (fontResource == null) { return null; } String fontPath = fontResource.toExternalForm(); BaseFont baseFont = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); baseFont.setSubset(true); return baseFont; } catch (DocumentException ex) { Logger.getLogger(PrintSettings.class).warn(“…”); } catch (IOException ex) { Logger.getLogger(PrintSettings.class).warn(“…”); } return […]

从PNG图像或Java面板创建PDF

我正在寻找一个可以拍摄图像(PNG)并创建PDF的Java库。 或者直接从已绘制的java面板创建PDF。

为什么使用Arial Unicode MS无法正确呈现Gujarati-Indian文本?

这是关于如何将古吉拉特语 – 印度语中的字体导出为pdf的后续问题? , @ amedee-van-gasse ,iText的质量保证工程师让我用相关的mcve发布一个特定于itext的问题。 为什么这个unicode序列\u0ab9\u0abf\u0aaa\u0acd\u0ab8无法正确呈现? 它应该像这样呈现: હિપ્સ,也用unicode转换器测试过 但是这段代码 (示例改编自iText:第11章:选择正确的字体 ) public class FontTest { /** The resulting PDF file. */ public static final String RESULT = “fontTest.pdf”; /** the text to render. */ public static final String TEST = “\u0ab9\u0abf\u0aaa\u0acd\u0ab8”; public void createPdf(String filename) throws IOException, DocumentException { Document document = new […]

使用iText从PCKS7签名的PDF文件中获取哈希/摘要

我正在编写一个Java Web服务,用来自网络中某些客户的iText签署PDF文档。 文档正确签名,可以使用外部工具进行validation。 但是,由于某些法律限制,为了将此文档存储在官方文档库中,我必须提供签名中的哈希/摘要消息。 我已经尝试了几乎任何东西来获取该哈希值,但我能得到的最接近的是使用此代码片段获取整个签名(CERT + HASH / DIGEST + TIMESTAMP)作为字符串(原谅字符串和[1]因为我我只是测试如何做到这一点: PdfReader reader = new PdfReader(path); File temp = TempFileManager.createTempFile(“aasd2sd”, “asdasda222cff”); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(temp)); stamper.setRotateContents(false); PdfString firma = (PdfString) stamper.getAcroFields().getSignatureDictionary(“Signature1”).get((PdfName)stamper.getAcroFields().getSignatureDictionary(“Signature1”).getKeys().toArray()[1]); 据我所知,我得到了一个DER-enconded PKCS7签名。 但是,我不知道如何解读/读取这些信息以便达到目的。 任何想法? 谢谢,克里斯。