pdfbox

remove encryption from pdf with pdfbox, like qpdf

送分小仙女□ 提交于 2019-11-30 04:35:07
问题 With qpdf, you can simply remove restrictions/encryption from a pdf like so: qpdf --decrypt infile outfile I would like to do the same thing with PDFBox in Java: PDDocument doc = PDDocument.load(inputFilename); if( doc.isEncrypted() ) { //remove the encryption to alter the document } I've tried this with StandardDecryptionMaterial, but I have no idea what the owner password is. How does qpdf do this? Sample document: https://issues.apache.org/jira/secure/attachment/12514714/in.pdf 回答1: This

How to center a text using PDFBox

血红的双手。 提交于 2019-11-29 23:43:23
My question is very simple: how can I center a text on a PDF, using PDFBox ? I don't know the string in advance, I can't find the middle by trial. The string doesn't always have the same width. I need either: A method that can center the text, something like addCenteredString(myString) A method that can give me the width of the string in pixels. I can then calculate the center, for I know the dimensions of the PDF. Any help is welcome! SteeveDroz Ok, I found the answer myself. Here is how to center some text on a page: String title = "This is my wonderful title!"; // Or whatever title you want

Using PDFbox to determine the coordinates of words in a document

假如想象 提交于 2019-11-29 21:50:41
I'm using PDFbox to extract the coordinates of words/strings in a PDF document, and have so far had success determining the position of individual characters. this is the code thus far, from the PDFbox doc: package printtextlocations; import java.io.*; import org.apache.pdfbox.exceptions.InvalidPasswordException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDStream; import org.apache.pdfbox.util.PDFTextStripper; import org.apache.pdfbox.util.TextPosition; import java.io.IOException; import java.util.List; public

Java pdfBox: Fill out pdf form, append it to pddocument, and repeat

别说谁变了你拦得住时间么 提交于 2019-11-29 19:55:30
问题 I have a pdf form made and I'm trying to use pdfBox to fill in the form and print the document. I got it working great for 1 page print jobs but i had to try and modify for multiple pages. Basically it's a form with basic info up top and a list of contents. Well if the contents are larger than what the form has room for I have to make it a multiple page document. I end up with a document with a nice page one and then all the remaining pages are the blank template. What am I doing wrong?

PDFBox - Removing invisible text (by clip/filling paths issue)

二次信任 提交于 2019-11-29 18:03:46
Link to example PDF: click here . Here you can see that many labels in the left are clipped (because of some clipping instructions) When I use PDFTextStripper, it prints all text which is actually cut/hidden in example PDF file. I have already tried solution described here however it makes it even worth because removes much text in the top + some text in the beginning of each row. Is there any other way to show only visible characters, and skip all overlapped, using PDFBox? Or maybe is there any other tool which could return only visible text? Thanks in advance. The reason why the

Table disappears when drawn before contentStream - PDFBox with Boxable

谁说我不能喝 提交于 2019-11-29 17:39:03
I am new to PDFBox and Boxable and I'm hoping if someone could help me with this! This question is in reference to a question asked here (Ref: https://github.com/dhorions/boxable/issues/89 ) In this, flurinBoonea presented a small sample code to put Text, Image and Table all in the same page. My question is, if I want to create a Table (which has dynamic height based on the content inside) and then I need to put some text after the table. How am I able to do that ?!? Somewhere I read that while drawing the table I use something similar to get the YPosition for next element, float yPosition =

how to add background image to PDF using PDFBox?

瘦欲@ 提交于 2019-11-29 17:29:31
I am using Java PDFBox version 2.0. I want to know how to add a back ground image to the pdf. I can not find any good example in the pdfbox.apache.org Do this with each page, i.e. from 0 to doc.getNumberOfPages(): PDPage pdPage = doc.getPage(page); InputStream oldContentStream = pdPage.getContents(); byte[] ba = IOUtils.toByteArray(oldContentStream); oldContentStream.close(); // brings a warning because a content stream already exists PDPageContentStream newContentStream = new PDPageContentStream(doc, pdPage, false, true); // createFromFile is the easiest way with an image file // if you

Dynamically resize jframe/image or scroll

不羁岁月 提交于 2019-11-29 16:10:48
As discussed in this question ( Wrap image to Jframe ), i need a jframe to match the exact provided image (The image itself is originally a PDF which has been converted to an image) The solution provided does indeed build a jframe to my image dimensions, but i can't actually see all of the image. I need to be able to resize the jframe, with the image dynamically adjusting to the new jframe size. Failing that, i think if i could just scroll the jframe or even zoom in or out, i could at least get to the parts of the image that i currently cannot see. The reason i need this is that, within my

PDFBox - find page dimensions

空扰寡人 提交于 2019-11-29 16:09:16
问题 How can I find(in mm) the width and the height of a pdf page using PDFBox? Currently, I'm using this: System.out.println(page.getMediaBox().getHeight()); System.out.println(page.getMediaBox().getWidth()); but the result is(not in mm): 842.0 595.22 回答1: Measurement units inside a PDF are in points, a traditional graphic industry measurement unit. Adobe uses the following definition: 1 pt = 1/72 inch and since one inch is defined to be exactly 25.4 mm (really!), you can convert from points to

How to (horizontally) align text of PDTextField in PDFBox?

不问归期 提交于 2019-11-29 16:06:36
I have a program that create TextFields inside a PDF-file so it can be used as a form. I would like to have the text I write in the TextFields I created to be centered though. How is that possible? My code currently looks like this: PDTextField textBox = new PDTextField(acroForm); textBox.setPartialName("Field " + j + " " + i); defaultAppearanceString = "/Helv 8 Tf 0 g"; //Textsize: 8 textBox.setDefaultAppearance(defaultAppearanceString); acroForm.getFields().add(textBox); PDAnnotationWidget widget = textBox.getWidgets().get(0); PDRectangle rect = new PDRectangle(inputField.getX(), inputField