pdfbox

PDFBox: how to properly copy annotation from one pdf to another

扶醉桌前 提交于 2019-12-13 03:18:56
问题 I am trying to copy annotations from one pdf to another. But copying even 1 annotation DOUBLES the size of outputing pdf file. Please find below simple code sample: PDDocument pdf = PDDocument.load(new File("test1.pdf")); PDDocument pdf2 = PDDocument.load(new File("test/test1.pdf")); List<PDAnnotation> pdfAnnotations1 = pdf.getPage(0).getAnnotations(); List<PDAnnotation> pdfAnnotations2 = pdf2.getPage(0).getAnnotations(); pdfAnnotations1.add(pdfAnnotations2.get(0)); pdf.save("test1.pdf"); If

How to extract fonts from PDDocument in PDFBox 2.0.2

寵の児 提交于 2019-12-13 02:55:11
问题 I have seen how to do this in previous versions like below: How to extract font styles of text contents using pdfbox? But I think the getFonts() method has been removed now. I want to retrieve a map of texts to fonts ( Map<String, PDFont> ) in the new version of PDFBox but I have no idea how. Thanks Kabeer 回答1: Do this: PDDocument doc = PDDocument.load("C:/mydoc3.pdf"); for (int i = 0; i < doc.getNumberOfPages(); ++i) { PDPage page = doc.getPage(i); PDResources res = page.getResources(); for

PDFBox not returning the correct size of an image

心不动则不痛 提交于 2019-12-13 01:51:47
问题 I am new to PDFBox and am stuck at finding the height of an image in inches. After a couple of searches, this is the piece of code that I am working with: PDResources resources = aPdPage.findResources(); graphicsState = new PDGraphicsState(aPdPage.findCropBox()); pageWidth = aPdPage.findCropBox().getWidth() / 72; pageHeight = aPdPage.findCropBox().getHeight() / 72; @SuppressWarnings("deprecation") Map<String, PDXObjectImage> imageObjects = resources.getImages(); if (null == imageObjects ||

PDFBox 1.8.10: Fill and Sign Document, Filling again fails

▼魔方 西西 提交于 2019-12-13 01:27:58
问题 In my previous SO question PDFBox 1.8.10: Fill and Sign PDF produces invalid signatures I explained, how I failed to fill and afterwards sign a PDF-Document, using PDFBox 1.8.10. After this got sorted out with some kind help, I now continue to work on the same topic. Starting with doc_v2.pdf (links to the file are below!), I fill and sign it, resulting in doc_v2_fillsigned.pdf (doing it in one go, saving it incrementally). Again I open the edited document (using again PDFBox) and try to fill

Java: Write national characters to PDF using PDFBox [duplicate]

南楼画角 提交于 2019-12-13 01:26:57
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: Using PDFBox to write UTF-8 encoded strings to a PDF I need to create PDF with Czech national characters, and I'm trying to do it with PDFBox library. I have copied following code from some tutorials: public void doIt(String file, String message) throws IOException, COSVisitorException { PDDocument doc = null; try { doc = new PDDocument(); PDSimpleFont font = PDType1Font.TIMES_ROMAN; TextToPDF textToPdf = new

PDFBox - PDF to Image losing barcode

微笑、不失礼 提交于 2019-12-13 01:12:38
问题 I am using PDFBox and have the following code snippet, which is reading a PDF file and converting it to image (PNG). It is working well, the only problem is that it is completely losing the barcode value that is in the PDF file. Does anyone know how to work around this with PDFBox? Is that even possible? Thanks. PDDocument doc = PDDocument.load(new File("INPUT.pdf")); PDPage page = (PDPage) doc.getDocumentCatalog().getAllPages().get(0); BufferedImage image = page.convertToImage(); File

PDFbox saying PDDocument closed when its not

自作多情 提交于 2019-12-13 00:54:25
问题 I am trying to populate repeated forms with PDFbox. I am using a TreeMap and populating the forms with individual records. The format of the pdf form is such that there are six records listed on page one and a static page inserted on page two. (For a TreeMap larger than six records, the process repeats). The error Im getting is specific to the size of the TreeMap. Therein lies my problem. I can't figure out why when I populate the TreeMap with more than 35 entries I get this warning: Apr 23,

Again having invisible text coming from PdfTextStripper

血红的双手。 提交于 2019-12-13 00:38:07
问题 File example: file. Problem - when extracting text using PdfTextStripper, there is token "9/1/2017" and "387986" after "ASSETS" in the page start which should be removed, and some others hidden tokens. I have already applied this solution (so I do not copy-paste it here, because actually problem is exactly the same) and still that hidden text is appearing on page. Could it be hidden by something else except clip path? thanks! 回答1: Could it be hidden by something else except clip path? Yes. In

Apache pdfbox claims that PDF documents are encrypted (but they are not!) - fix?

余生长醉 提交于 2019-12-12 22:12:41
问题 In my program I am downloading misc. PDF documents and at the very end I want to merge those into one combined document using Apache pdfbox (v1.8.8). For some strange reason the PDFMergerUtility fails claiming that the files are encryped - which they are obviously not! I can open them in Adobe Reader and other PDF viewers without any issue and without having to provide any password. The Java exception and stack trace reads: Feb 28, 2015 6:25:54 PM org.apache.pdfbox.pdfparser.PDFParser parse

PDFBox - PageDrawer draws outside the PdfPagePanel

半世苍凉 提交于 2019-12-12 19:15:40
问题 I'm using PDFBox to show a generated pdf-file in my application. I added the PdfPagePanel to a JScrollPane. When I make the window smaller and the scrollbars appeare, the PageDrawer draws onto the scrollbars. This effects also occurs in the PDFReader (executable example of PDFBox). open a pdf-file -> reduce size of window -> pdf-content get's drawn over the scrollbars Does anybody know a way to fix this? Enviroment: PDFBox 1.7.1, Windows 7, Java 1.6.31 Thanks in advance, Sascha 回答1: I still