pdfbox

How to add .png images to pdf using Apache PDFBox

笑着哭i 提交于 2019-12-04 02:27:47
When I try to draw png images using pdfBox, the pages remain blank. Is there any way to insert png images using pdfBox? public void createPDFFromImage( String inputFile, String image, String outputFile ) throws IOException, COSVisitorException { // the document PDDocument doc = null; try { doc = PDDocument.load( inputFile ); //we will add the image to the first page. PDPage page = (PDPage)doc.getDocumentCatalog().getAllPages().get( 0 ); PDXObjectImage ximage = null; if( image.toLowerCase().endsWith( ".jpg" ) ) { ximage = new PDJpeg(doc, new FileInputStream( image ) ); } else if (image

Create mutli-page document dynamically using PDFBox

跟風遠走 提交于 2019-12-04 00:01:23
I am attempting to create a PDF report from a Java ResultSet. If the report was only one page, I would have no problem here. The issue comes from the fact that the report could be anywhere from one to ten pages long. Right now, I have this to create a single-page document: PDDocument document = new PDDocument(); PDPage page = new PDPage(PDPage.PAGE_SIZE_LETTER); document.addPage(page); PDPageContentStream content = new PDPageContentStream(document,page); So my question is, how do I create pages dynamically as they are needed. Is there an object-oriented answer staring me in the face and I just

pdfbox wrap text

徘徊边缘 提交于 2019-12-03 23:34:53
I am using PDFBox with the following code: doc = new PDDocument(); page = new PDPage(); doc.addPage(page); PDFont font = PDType1Font.COURIER; pdftitle = new PDPageContentStream(doc, page); pdftitle.beginText(); pdftitle.setFont( font, 12 ); pdftitle.moveTextPositionByAmount( 40, 740 ); pdftitle.drawString("Here I insert a lot of text"); pdftitle.endText(); pdftitle.close(); Does anyone know how I can wrap the text so that it automatically goes to another line? Lukas I don't think it is possible to wrap text automatically. But you can wrap your text yourself. See How to Insert a Linefeed with

Not able to read the exact text highlighted across the lines

与世无争的帅哥 提交于 2019-12-03 22:13:59
问题 I am working on reading the highlighted from PDF document using PDBox. I was able to read the highlighted text in single line both single and multiple words. However, I could not read the highlighted text across the lines. Please find the following sample code to read the highlighted text. PDDocument pddDocument = PDDocument.load(new File("C:\\pdf-sample.pdf")); List allPages = pddDocument.getDocumentCatalog().getAllPages(); for (int i = 0; i < allPages.size(); i++) { int pageNum = i + 1;

Text extraction from PDF using PDFBox 2.0

╄→гoц情女王★ 提交于 2019-12-03 21:57:37
I'm trying to use PDFBox 2.0 for text extraction. I would like to get information on the font size of specific characters and the position rectangle of that character on the page. I've implemented this in PDFBox 1.6 using a PDFTextStripper: PDFParser parser = new PDFParser(is); try{ parser.parse(); }catch(IOException e){ } COSDocument cosDoc = parser.getDocument(); PDDocument pdd = new PDDocument(cosDoc); final StringBuffer extractedText = new StringBuffer(); PDFTextStripper textStripper = new PDFTextStripper(){ @Override protected void processTextPosition(TextPosition text) { extractedText

Using pdfbox to get form field values

蹲街弑〆低调 提交于 2019-12-03 21:01:16
I'm using pdfbox for the first time. Now I'm reading something on the website Pdf Summarizing I have a pdf like this: only that my file has many and many different component(textField,RadionButton,CheckBox). For this pdf I have to read these values : Mauro,Rossi,MyCompany. For now I wrote the following code: PDDocument pdDoc = PDDocument.loadNonSeq( myFile, null ); PDDocumentCatalog pdCatalog = pdDoc.getDocumentCatalog(); PDAcroForm pdAcroForm = pdCatalog.getAcroForm(); for(PDField pdField : pdAcroForm.getFields()){ System.out.println(pdField.getValue()) } Is this a correct way to read the

How to reduce the size of merged PDF/A-1b files with pdfbox or other java library

倖福魔咒の 提交于 2019-12-03 20:29:57
问题 Input : A list of (e.g. 14) PDF/A-1b files with embedded fonts. Processing : Doing a simple merge with Apache PDFBOX. Result : 1 PDF/A-1b file with large (too large) file size. (It is almost the sum of the size of all the source files). Question : Is there a way to reduce the file size of the resulting PDF? Idea : Remove redundant embedded fonts. But how to? And is it the right way to do? Unfortunately the following code is not doing the job, but is highlighting the obvious problem. try

Unable to verify digital signature using Apache PDFBOX

Deadly 提交于 2019-12-03 15:15:54
I am a newbie in using Digital Signatures. In one of the projects we are using Apache PdfBox for processing digitally signed pdf files. While we could test all features, verification of signed pdf files is something we are unable to crack. We are using BouncyCastle as the provider. Below is the code: //Get Digital Signature and Signed Content from pdf file byte[] signatureAsBytes = pdsignature.getContents(new FileInputStream(this.INPUT_FILE)); byte[] signedContentAsBytes = pdsignature.getSignedContent(new FileInputStream(this.INPUT_FILE)); //Digital Signature Verification Security.addProvider

How can I create fixed-width paragraphs with PDFbox?

天大地大妈咪最大 提交于 2019-12-03 10:32:26
I can insert simple text like this: document = new PDDocument(); page = new PDPage(PDPage.PAGE_SIZE_A4); document.addPage(page); PDPageContentStream content = new PDPageContentStream(document, page); content.beginText(); content.moveTextPositionByAmount (10 , 10); content.drawString ("test text"); content.endText(); content.close(); but how can I create a paragraph similar to HTML using the width attribute? <p style="width:200px;">test text</p> Warning : this answer applies to and old version of PDFBox and relies on features that has since been deprecated. See the comments below for more

Performance iText vs.PdfBox

廉价感情. 提交于 2019-12-03 09:23:45
I'm trying to convert a pdf (my favorite book Effective Java, if its matter)to text, i checked both iText and Apache PdfBox. I see a really big difference in performance: With iText it took 2:521, and with PdfBox: 6:117. This if my code for PdfBOx PDFTextStripper stripper = new PDFTextStripper(); BUFFER.append(stripper.getText(PDDocument.load(pdf))); And this is for iText PdfReader reader = new PdfReader(pdf); for (int i = 1; i <= reader.getNumberOfPages(); i++) { BUFFER.append(PdfTextExtractor.getTextFromPage(reader, i)); } My question is in what the performance depends, is there a way how to