pdfbox

Merge Pdf Files Using PDFBox

限于喜欢 提交于 2019-12-07 10:23:27
问题 I have to merge two pdf Files using PdfBox of Apache. I have taken physical pdf files to do so. Below is the code: PDFMergerUtility ut = new PDFMergerUtility(); ut.addSource(path1); ut.addSource(path2); ut.setDestinationFileName(path3); ut.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly()); Files are merged perfectly but then have some constraints as below: I am creating 1st file in the code itself,so it is PDDocument object. The file which I have to merge with 1st file is in byte array

pdfbox: how to clone a page

*爱你&永不变心* 提交于 2019-12-07 07:57:00
问题 Using Apache PDFBox, I am editing an existing document and I would like to take one page from that document and simply clone it, copying whatever elements it contains. As an additional twist, I would like to get a reference to all the PDField s for any form fields in this newly cloned page. Here's the code I tried so far: PDPage newPage = new PDPage(lastPage.getCOSDictionary()); PDFCloneUtility cloner = new PDFCloneUtility(pdfDoc); pdfDoc.addPage(newPage); cloner.cloneMerge(lastPage, newPage)

Write cyrillic chars into PDF form fields with PDFBox

人走茶凉 提交于 2019-12-07 07:03:23
问题 I am using pdfbox 2.0.5 to fill out form fields of a PDF document using this code: doc = PDDocument.load(inputStream); PDDocumentCatalog catalog = doc.getDocumentCatalog(); PDAcroForm form = catalog.getAcroForm(); for (PDField field : form.getFieldTree()){ field.setValue("должен"); } I get this error: U+0434 ('afii10069') is not available in this font Times-Roman (generic: TimesNewRomanPSMT) encoding: StandardEncoding with differences The PDF document itself contains cyrillic text which is

BufferedImage color saturation

微笑、不失礼 提交于 2019-12-07 03:35:53
问题 I'm writing a simple scanning application using jfreesane and Apache PDFBox. Here is the scanning code: InetAddress address = InetAddress.getByName("192.168.0.17"); SaneSession session = SaneSession.withRemoteSane(address); List<SaneDevice> devices = session.listDevices(); SaneDevice device = devices.get(0); device.open(); device.getOption("resolution").setIntegerValue(300); BufferedImage bimg = device.acquireImage(); File file = new File("test_scan.png"); ImageIO.write(bimg, "png", file);

Displaying embedded fonts with PDFBox and Swing

微笑、不失礼 提交于 2019-12-07 02:33:28
I am using PDFBox to display PDF files inside a JInternalFrame. When opening PDF I get lots of warnings like this: Changing font on <m> from <Tahoma Negrita> to the default font I am aware that the fonts being reported are not part of the standard set of 14 fonts. So I decided to check if those fonts are embedded on the PDF file (thinking that there shouldn't be a problem loading embedded fonts, right?). So I open the file on different readers and check properties/fonts. I am in doubt whether this section reports fonts required by the document or fonts actually embedded in the document. The

read text from a particular page using PDFBox [duplicate]

99封情书 提交于 2019-12-06 21:13:24
问题 This question already has answers here : Reading a particular page from a PDF document using PDFBox (6 answers) Closed 6 years ago . I know how to read text of an entire pdf file usinf PDFBox using PDFTextStripper.getText(PDDocument) . I also have a sample on how to get an object reference to a particular page using PDDocumentCatalog.getAllPages().get(i) . How do I get the text of just one page using PDFBox as I dont see any such method on PDPage class? 回答1: You can set parameters on the

java操作PDF(PDFBOX和Itext框架)

南楼画角 提交于 2019-12-06 16:57:37
java有很多可以操作pdf的框架,pdfbox和itext就是其中的两种 pdfbox有如下作用 提取文本,包括Unicode字符。 和Jakarta Lucene等文本搜索引擎的整合过程十分简单。 加密/解密PDF文档。 从PDF和XFDF格式中导入或导出表单数据。 向已有PDF文档中追加内容。 将一个PDF文档切分为多个文档。 覆盖PDF文档 。 下面是一个使用pdfbox的测试程序 public class PdfBoxTest { public void getText(String file) throws Exception{ //是否排序 boolean sort = false; //pdf文件名 String pdfFile = file; //输入文本文件名称 String textFile = null; //编码方式 String encoding = "UTF-8"; //开始提取页数 int startPage = 1; //结束提取页数 int endPage = Integer.MAX_VALUE; //文件输入流,输入文本文件 Writer output = null; //内存中存储的PDF Document PDDocument document = null; try{ try{ //首先当作一个URL来加载文件

Text is reverse in generated pdf

心已入冬 提交于 2019-12-06 15:08:11
问题 I am using pdfbox to add a line to pdf file. but the text i am adding is reversed. File file = new File(filePath); PDDocument document = PDDocument.load(file); PDPage page = document.getPage(0); PDPageContentStream contentStream = new PDPageContentStream(document, page,PDPageContentStream.AppendMode.APPEND,true); int stampFontSize = grailsApplication.config.pdfStamp.stampFontSize ? grailsApplication.config.pdfStamp.stampFontSize : 20 contentStream.beginText(); contentStream.setFont

How do I rotate the contents of a PDF page to an arbitrary angle?

烂漫一生 提交于 2019-12-06 14:06:42
问题 I need to rotate the contents of a PDF page by an arbitrary angle and the PDPage.setRotation(int) command is restricted to multiples of 90 degrees. The contents of the page are vector and text and I need to be able to zoom in on the contents later, which means that I cannot convert the page to an image because of the loss of resolution. 回答1: In comments it already has been indicated that to draw some content, e.g. an existing regular portrait or landscape page, at an arbitrary angle onto a

PdfBox 2.0.0 write text at given postion in a page

て烟熏妆下的殇ゞ 提交于 2019-12-06 13:16:14
问题 I have just passed from PdfBox 1.8 to 2.0.0 and there are quite significant differences. Before to write a text on an existing pdf page I used drawString. In 2.0.0 draw string is deprecated but showText does not work in a block text. My code in 1.8: contentStream.beginText() contentStream.moveTextPositionByAmount(250, 665) contentStream.drawString("1 2 3 4 5 6 7 8 9 1 0") contentStream.endText() My code in 2.0 PDDocument newPdf=null newPdf=PDDocument.load(sourcePdfFile) PDPage firstPage