pdfbox

Apache PDFBox refuses to open temporary created PDF file

断了今生、忘了曾经 提交于 2021-01-28 18:51:08
问题 I am creating desktop JavaFX application for viewing PDF files. PDFs are at resource folder. I read resourse file as stream, then I create temporary file and use it to convert contents to image and show into ImageView. currentPdf = new File("current.pdf"); if (!currentPdf.exists()) { // In JAR InputStream inputStream = ClassLoader.getSystemClassLoader() .getResourceAsStream("PDFSample.pdf"); // Copy file OutputStream outputStream; try { outputStream = new FileOutputStream(currentPdf); } catch

org.apache.pdfbox.pdmodel.PDDocument does not load / read the PDF document

我的梦境 提交于 2021-01-28 18:42:03
问题 I wrote a simple java program to get the page number of a PDF document. This works for most of my documents, but it does not work for this one: http://web.itu.edu.tr/~pazarci/rtv/TEK_Digital%20Video%20Measurements_25W_14700_3.pdf The snippet of the code is below: document = PDDocument.load(docPath); System.out.println( docPath + ": " + document.getNumberOfPages() + " pages"); in which docPath points to the local path of this document. The program then halts here. It does not exit and does not

PDFBOX 2.0.18 - How to iterates through pages of a PDF and retrieve specific fields

无人久伴 提交于 2021-01-28 14:40:21
问题 I'm using PDFBox to read specific fields on a pdf document. Actually, I'm able to get all the informations I want with a pdf containing only one page. The PDF has fields with specific names and I can get all the fields and insert it in a database. I use this code with AccroForm to access the fields InputStream document = item.getInputStream(); pdf = PDDocument.load(new RandomAccessBufferedFileInputStream(document)); pdCatalog = pdf.getDocumentCatalog(); pdAcroForm = pdCatalog.getAcroForm();

BouncyCastle CMSSignedData from external signature and public key certificate

五迷三道 提交于 2021-01-28 11:42:17
问题 I have an X509Certificate, and a byte array that represents a raw signature created by a remote server (which has my private key). I'm trying to add this signature with PDFBox 2.0.18. For that, I need CMSSignedData object. How do I generate CmsSignedData without private key (only signature, public key, certificate)? 来源: https://stackoverflow.com/questions/60242213/bouncycastle-cmssigneddata-from-external-signature-and-public-key-certificate

PDFbox - how can i add content to a layer?

笑着哭i 提交于 2021-01-28 07:40:52
问题 I'm using pdfbox 2.0.8 - need to create a layer and add some graphic there. I started from How do I make modifications to existing layer(Optional Content Group) in pdf? which however is based on 1.8. I tried to adapt to 2.0 and managed to create the layer, but it is completely unclear how then you can create a new resource and add it to the layer - i.e. how the props.putMapping(resourceName, layer); which was in 1.8 has to be rewritten 回答1: Equivalent to the PDFBox 1.8 code in the answer

Disable pdf-text searching with pdfBox

江枫思渺然 提交于 2021-01-28 06:07:10
问题 I have a pdf document (no form) where I want to disable the text searching using pdfBox (java). Following possibilities I can imagine: Flatten text Remove Text information (without removing text itself) Add overlay to document. Currently I've no idea how I can implement that. Does anyone has an idea how to solve that? 回答1: many thanks for your help here. I guess I found a way that fit to the requirements. (Honestly, not really clean): Add the rectangle to the address sections convert PDF to

PDFBox scrambling the text

拜拜、爱过 提交于 2021-01-28 05:21:36
问题 I have been trying to edit a PDF document to pre-fill form entries. I've got it working (sort of). The text I'm adding, goes in fine. However, other text that was already there seems to have gotten replaced with "&%£!£! symbols. I've worked out that it's something to do with the "contentStream" section in the code below. It seems to be the "setFont" line. If I remove it, the page remains OK... except that the "Hello Richard" text is no longer displayed! Help please! package pdfboxtest; import

How to convert a PDF to a postscript file using pdfbox 2.0

霸气de小男生 提交于 2021-01-28 02:20:30
问题 I was able to create a PDF with PDFBox (version 1.8.9) and then convert it to a PostScript file with the following code: DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); if (factories.length == 0) { throw new PrinterException("No PostScript factories available"); } PDDocument document = pdfGenerator.getDocument(); // Attributes

“IOException: COSStream has been closed and cannot be read” when trying to save PDF after adding page with PdfBox

让人想犯罪 __ 提交于 2021-01-27 20:28:39
问题 I have some trouble to get this code working. The goal is to merge pdf with a loaded pdf in a PDDocument object. I don't want to use the mergeUtility of PdfBox because it implies to closed the PDDocument object. I have a lot of data to process and I use a loop to process it. Load and close a PDDocument will take too much time and resource (maybe I'm wrong but that the way it feel it). Here is my way to do it : for (String path:pathList) { /* ... */ if(path.endsWith("pdf")){ File pdfToMerge =

Printing Chinese characters in pdfbox

假装没事ソ 提交于 2021-01-27 07:31:54
问题 I'm using the following set-up: Java 11.0.1 pdfbox 2.0.15 Objective: Rendering a pdf that contains Chinese characters Problem: java.lang.IllegalArgumentException: U+674E is not available in this font's encoding: WinAnsiEncoding I already tried: Using different fonts for Chinese character support. The latest one is NotoSansCJKtc-Regular.ttf Set font to unicode as described here: Java: Write national characters to PDF using PDFBox, however the used loadTTF method is deprecated. Using Arial