pdfbox

How to create a PDF document from languages of Unicode char set regarding using third party Fonts

纵饮孤独 提交于 2019-12-03 09:11:41
I'm using PDFBox and iText to create a simple (just paragraphs) pdf document from various languages. Something like : pdfBox : private static void createPdfBoxDocument(File from, File to) { PDDocument document = null; try { document = new TextToPDF().createPDFFromText(new FileReader(from)); document.save(new FileOutputStream(to)); } finally { if (document != null) document.close(); } } private void createPdfBoxDoc() throws IOException, FileNotFoundException, COSVisitorException { PDDocument document = new PDDocument(); PDPage page = new PDPage(); document.addPage(page); PDPageContentStream

How to add PDFBox to an Android project or suggest alternative

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm attempting to open an existing pdf file and then add another page to the pdf document from within an Android application. On the added page, I need to add some text and an image. I am wanting to give PDFBox a try. Other solutions such as iTextPDF aren't suitable for our company because of the licencing terms/price. I have a library project with the main code base, and also full and lite projects that reference the library project. I have downloaded the jar from http://pdfbox.apache.org/download.html and copied it into the library

Watermarking with PDFBox

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to add a watermark to a PDF specifically with PDFBox. I've been able to get the image to appear on each page, but it loses the background transparency because it appears as though PDJpeg converts it to a JPG. Perhaps there's a way to do it using PDXObjectImage. Here is what I have written thus far: public static void watermarkPDF(PDDocument pdf) throws IOException { // Load watermark BufferedImage buffered = ImageIO.read(new File("C:\\PDF_Test\\watermark.png")); PDJpeg watermark = new PDJpeg(pdf, buffered); // Loop through pages

How to find whether PDF has landscape orientation or portrait

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 08:37:08
Are there tools to determine whether a PDF has landscape orientation or portrait? I have currently looked upon pdfbox and Itext for this but seem that I could not find it. Please tell if they support this. Extracting the PDF pages information using Origami is providing a information the pdf pages have rotation of some degree. Here is what Origami reports: {:Parent=>#<PDF::Reader::Reference:0x872349c @id=8, @gen=0>, :Type=>:Page, :Contents=>#<PDF::Reader::Reference:0x8722f24 @id=4, @gen=0>, :Resources=># <PDF::Reader::Reference:0x870dbd8 @id=2, @gen=0>, :MediaBox=>[0, 0, 612, 792], :Rotate=>270

Flatten vector graphics inside pdf and extract using java

守給你的承諾、 提交于 2019-12-03 08:26:12
I am trying to get sizes (width and depth) of images embedded in a PDF file. The images in the PDF are all high resolution vector images. I tried using PDFBox. PDFBox libraries extract images perfectly for normal graphics. But, when it gets vector images, it extracts different layers as different images. I have also read about iText. But iText can convert the whole page as rasterized image. Whereas, my PDF page is actually consisting multiple images and I need to extract/get size of all of them differently. I am attaching my PDFBox image extraction code here. Please let me know, how can I get

Getting PDF TextObjects with PDFBox

守給你的承諾、 提交于 2019-12-03 07:28:52
I have a PDF from which I extracted a page using PDFBox: (...) File input = new File("C:\\temp\\sample.pdf"); document = PDDocument.load(input); List allPages = document.getDocumentCatalog().getAllPages(); PDPage page = (PDPage) allPages.get(2); PDStream contents = page.getContents(); if (contents != null) { System.out.println(contents.getInputStreamAsString()); (...) This gives the following result, which looks like something you'd expect, based on the PDF spec . q /GS0 gs /Fm0 Do Q /Span <</Lang (en-US)/MCID 88 >>BDC BT /CS0 cs 0 0 0 scn /GS1 gs /T1_0 1 Tf 8.5 0 0 8.5 70.8661 576 Tm (This

Apache PDFBox Java library - Is there an API for creating tables?

一笑奈何 提交于 2019-12-03 05:38:40
问题 I am using the Apache PDFBox java library to create PDFs. Is there a way to create a data-table using pdfbox? If there is no such API to do it, I would require to manually draw the table using drawLine etc., Any suggestions on how to go about this? 回答1: Source : Creating tables with PDFBox The following method draws a table with the specified table content. Its a bit of a hack and will work for small strings of text. It does not perform word wrapping, but you can get an idea of how it is done

Java PDFBOX text encoding

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: 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 readers have (ie Adobe Reader, OS X Preview, etc)

extract images from pdf using pdfbox

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I m trying to extract images from a pdf using pdfbox. The example pdf here But i m getting blank images only. The code i m trying:- public static void main(String[] args) { PDFImageExtract obj = new PDFImageExtract(); try { obj.read_pdf(); } catch (IOException ex) { System.out.println("" + ex); } } void read_pdf() throws IOException { PDDocument document = null; try { document = PDDocument.load("C:\\Users\\Pradyut\\Documents\\MCS-034.pdf"); } catch (IOException ex) { System.out.println("" + ex); } List pages = document.getDocumentCatalog()

PDFBox: How to “flatten” a PDF-form?

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do I "flatten" a PDF-form (remove the form-field but keep the text of the field) with PDFBox? Same question was answered here: a quick way to do this, is to remove the fields from the acrofrom. For this you just need to get the document catalog, then the acroform and then remove all fields from this acroform. The graphical representation is linked with the annotation and stay in the document. So I wrote this code: import java.io.File; import java.util.ArrayList; import java.util.List; import org.apache.pdfbox.pdmodel.PDDocument; import