pdfbox

Filling landscape PDF with PDFBox

末鹿安然 提交于 2020-01-04 15:28:01
问题 I try to fill a PDF form with PDFBox and I managed to do it well with a portrait oriented document. But I have a problem when filling a document in landscape mode. The fields are filled up, but the text orientation is not good. It appear vertically like if it was still in portrait but in a rotation of 90 degrees. Here is my simplified code: PDDocument pdfDoc = PDDocument.load(MY_FILE); PDDocumentCatalog docCatalog = pdfDoc.getDocumentCatalog(); PDAcroForm acroForm = docCatalog.getAcroForm();

PDF Rendering with PDFBox 2.0 and Decrypting

Deadly 提交于 2020-01-04 05:39:08
问题 I have just upgraded PDFBox version from 1.8 to 2.0. Migration says that .convertToImage() has been removed and there is no a line in their example code for BufferedImage , but it is used in .writeImage() Their code: PDDocument document = PDDocument.load(new File(pdfFilename)); PDFRenderer pdfRenderer = new PDFRenderer(document); int pageCounter = 0; for (PDPage page : document.getPages()) { pdfRenderer.renderImageWithDPI(pageCounter, 300, ImageType.RGB); // suffix in filename will be used as

Understanding loading of font in PDFBox 2.0

倖福魔咒の 提交于 2020-01-03 17:19:04
问题 I have finally succeeded in making PDFBox print my unicodes. But now, I would like to understand the solution that I have come up with. The code below works and prints a ≥ to the page. Two things do not work: changing PDType0Font.load(documentMock, systemResourceAsStream, true); to PDType0Font.load(documentMock, systemResourceAsStream, false); changing final PDFont robotoLight = loadFontAlternative("Roboto-Light.ttf"); to final PDFont robotoLight = loadFont("Roboto-Light.ttf"); The first

Setting character spacing with PDFBox

≡放荡痞女 提交于 2020-01-03 17:10:44
问题 I'm currently using Java and the PDFBox library to create some PDFs on the fly. I need to be able to set the character spacing/tracking of some text but can't seem to figure it out. It looks as there is a method to do so : http://ci.apache.org/projects/pdfbox/javadoc/index.html?org/apache/pdfbox/util/operator/SetCharSpacing.html But I'm not quite sure how to apply this in the situation. cs.beginText(); cs.setFont( font, fontSize ); cs.setNonStrokingColor(color); cs.moveTextPositionByAmount

PDFBox - how to create table of contents

北战南征 提交于 2020-01-03 16:57:28
问题 Is there a way to create a table of contents using Java PDFBox library? The table of contents should be clickable (jump to the right page) Thanks. 回答1: There's no simple method for doing this, but here's an approach. I haven't figured out how to attach links directly to text, so my approach means you have to draw the annotations as rectangles and the text separately. It's a bit rough around the edges, but it works. // there are other types of destinations, choose what is appropriate

Shapes drawn on an image is inverted when written into PDF file

梦想与她 提交于 2020-01-03 06:45:55
问题 I have a PDF file that I converted into an image. Was able to write on top of the image but when I tried to save the shapes/lines into the pdf, the point are not their place and the shapes are inverted. This is what I draw. This is the saved PDF File. I'm really sorry but that is the shortest code I can make in order replicate the problem. I know this question is not good but I hope someone can help. Thank you Tilman Hausherr for your patience.. package pdfwriter; import java.awt.Dimension;

Using Apache PDFBox in Oracle JVM

六月ゝ 毕业季﹏ 提交于 2020-01-03 04:55:08
问题 I'm trying to load the Apache PDFBox Java libraries into the Oracle JVM but seem to get lost in unresolved dependencies. Did someone success to load PDFBox 2.0.8 into a Oracle 12.2 JVM? 回答1: It’s mostly a problem on how to resolve the java dependencies and once that’s done, everything works as expected by loading the packages in the following order: 1) Load the “Bouncy Castle” dependencies loadjava -resolve -user scott/tiger@localhost:1521:orcl -thin bcprov-jdk15on-158.jar bcmail-jdk15on-158

PDFBox - Line / Rectangle extraction

无人久伴 提交于 2020-01-02 17:34:34
问题 I am trying to extract text coordinates and line (or rectangle) coordinates from a PDF. The TextPosition class has getXDirAdj() and getYDirAdj() methods which transform coordinates according to the direction of the text piece the respective TextPosition object represents (Corrected based on comment from @mkl) The final output is consistent, irrespective of the page rotation. The coordinates needed on the output are X0,Y0 (TOP LEFT CORNER OF THE PAGE) This is a slight modification from the

Extracting text from pdf (java using pdfbox library) from a table's rows with different heights

扶醉桌前 提交于 2020-01-02 09:24:17
问题 Black shapes are text that need to be extracted: So far, i've extracted the text from columns, but manually, because there are only 5 (using the Rectangle class for the regions). My question is: is there a way to do so for rows since the size (height) of the Rectangles are different and manually doing it to 50+ rows would be an atrocity? More specific, can i change the rectangle according to every row's height using a function? Or any suggestion that may help? 回答1: As proposed in comments,

Extracting text from pdf (java using pdfbox library) from a table's rows with different heights

最后都变了- 提交于 2020-01-02 09:23:29
问题 Black shapes are text that need to be extracted: So far, i've extracted the text from columns, but manually, because there are only 5 (using the Rectangle class for the regions). My question is: is there a way to do so for rows since the size (height) of the Rectangles are different and manually doing it to 50+ rows would be an atrocity? More specific, can i change the rectangle according to every row's height using a function? Or any suggestion that may help? 回答1: As proposed in comments,