pdfbox

PDFBox how to import acrofield from another pdf

血红的双手。 提交于 2019-12-02 07:49:09
问题 I have a problem with import exist acrofield from a pdf into another pdf. The two pdf are similar. I tried to import and save the file (code below). if I open it from the file system I do not see the changes, but if I open it with pdfbox I see the acrofiles inserted earlier. I notice that the file size has increased, but when I open it I do not see the fields fillable. Thank you in advance PDDocument documentSrc = PDDocument.load(new File(SRC)); PDAcroForm acroFormSrc = documentSrc

How to delete an optional content group alongwith its content from pdf using pdfbox?

为君一笑 提交于 2019-12-02 07:23:49
I have implemented functionality to delete the layer from pdf, but the problem is that, the content that I had drawn on the layer, does not get delete.Here is the code that I am using to delete the layer: PDDocumentCatalog documentCatalog = doc.getDocumentCatalog(); PDOptionalContentProperties ocgProps = documentCatalog.getOCProperties(); PDOptionalContentGroup ocg = ocgProps.getGroup(markupLayerName); COSDictionary ocgsDict = (COSDictionary)ocgProps.getCOSObject(); COSArray ocgs = (COSArray)ocgsDict.getItem(COSName.OCGS); int indexToBeDeleted = -1; for (int index = 0; index < ocgs.size();

How to select pdf page using bookmark in pdf box?

淺唱寂寞╮ 提交于 2019-12-02 07:23:48
Sorry i am new to PDF box and was looking for a solution on how to get a specific pdf page using the bookmark name? Like the below code snippet am trying to loop all the pages but stuck to link the book mark with the page i need. Can any one please help? import java.awt.print.PrinterException; import java.io.File; import java.io.IOException; import org.apache.pdfbox.cos.COSObject; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException; import org.apache.pdfbox.pdmodel.interactive

Setting image form field

匆匆过客 提交于 2019-12-02 06:58:22
I created a sample PDF form with one image field. I'm trying to set an image to the field using PDFBox. I see that PDFBox treats such field as an instance of PDPushButton but I don't see this class' interface exposes methods to deal with images... The sample PDF can be downloaded using the URL in comment. How can it be done? EDIT : Here is what I'm doing so far: PDDocument pdfDocument = null; PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm(); if (acroForm != null) { PDPushButton field = (PDPushButton) acroForm.getField("test"); PDImageXObject pdImageXObject = PDImageXObject

Rotate watermark text at 45 degree angle across the center Apache PDFBox

久未见 提交于 2019-12-02 06:06:51
I want to add a text to the PDF using PDFBox API and rotate it by 45 Degree and place it at the center of the page, The text is dynamic and should be placed in the center always, I got everything else to work except centering piece, I'll appreciate any help. I have this code: Point2D.Float pageCenter = getCenter(page); float stringWidth = getStringWidth(watermarkText, font, fontSize); float textX = pageCenter.x - stringWidth / 2F + center.x; System.out.println(textX); float textY = pageCenter.y + center.y; //System.out.println("Inside cross"+textX+", "+textY); fontSize = 110.0f; cs.transform

Java PDFBOX text encoding

我怕爱的太早我们不能终老 提交于 2019-12-02 05:43:51
问题 I try to export some data from my Java application to a pdf file. I decided to use the pdfBox library,but I realized that I could not do the Greek characters displayed properly into the pdf file. Is there a way to set the encoding? to utf8, or iso-8859-7? I try something like PdFontEncoding or Encoding but I did not get anything. Thank you for your time. 回答1: There are two things you would need to do: set the encoding, and provide a font with Greek characters The inbuilt fonts that most PDF

How to change the coordinates of a text in a pdf page from lower left to upper left

微笑、不失礼 提交于 2019-12-02 05:19:07
I am using PDFBOX and itextsharp dll and processing a pdf. so that I get the text coordinates of the text within a rectangle. the rectangle coordinates are extracted using the itextsharp.dll. Basically I get the rectangle coordinates from itextsharp.dll, where itextsharp uses the coordinates system as lower left. And I get the pdf page text from PDFBOX, where PDFBOX uses the coordinates system as top upper left. I need help in converting the Coordinates from lower left to upper left Updating my question Pardon me if you didn't understood my question and if not full information was provided.

setting ttf for PDF to Image on PDFbox

冷暖自知 提交于 2019-12-02 04:02:13
问题 i'm trying to set an external ttf , to be able to render an image out of a pdf containing arabic caracters , the font i need to set is "Arial" , having done that the console keeps on informing that it's using the defaultFont instead of arial. org.apache.pdfbox.pdmodel.font.PDSimpleFont drawString ATTENTION: Changing font on <3> from <Arial> to the default font here's my code : import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.Iterator;

PdfBox issue while changing page

此生再无相见时 提交于 2019-12-02 03:14:56
I'm not a big fan of asking this kind of questions but well, it's been 3 whole days now trying to solve this bug on my code. I know it's a logic problem and I know how to solve it in my mind, but when it comes to translate my ideas into code I just can't make it work as I want. I'm working on a contract endorsement (a modification of a contract) which compares the data from 2 tables and if any of them has changed then it paints only that information. Sometimes the information that changes such as conditions grows up or lowers in length, here's where the problem lies. I made an algorithm which

PdfBox - PDColorSpaceFactory.createColorSpace(document, iccColorSpace) throws nullpointerexception

旧城冷巷雨未停 提交于 2019-12-02 03:10:44
I'm trying to create a PDF which has a single image on a single page. The tricky part is to use a custom (defined in a separate file) CMYK color space. I've tried to call PDColorSpaceFactory.createColorSpace(document, iccColorSpace) but keep getting nullpointerexception. I've managed to track the issue up to the constructor: public PDICCBased( PDDocument doc ) { array = new COSArray(); array.add( COSName.ICCBASED ); array.add( new PDStream( doc ) ); } The PDICCBased object has stream field and it's obviously not set. Thus when it's called at: public static PDColorSpace createColorSpace(