pdfbox

PdfBox adding multiple images into pdf

蓝咒 提交于 2019-12-11 14:35:36
问题 I try to add multiple images into a pdf with pdfbox 2.0.8, but currently only one will be added. I have two different images which should be attached to two different acrofields, but only the last one of my list will be added. This is my test function: @Test public void attachBulkImageToField(){ List<ImageData> data = new ArrayList<>(); data.add(new ImageData(signatureAusstellerField,signatureAussteller.toPath())); data.add(new ImageData(signatureDienstleisterField, signatureDienstleister

Replace data in a PDF file

假如想象 提交于 2019-12-11 14:15:29
问题 I have to replace string between << and >> . However I'm unable to do so. public void doIt( String inputFile, String outputFile) throws IOException, COSVisitorException { PDDocument doc = null; try { doc = PDDocument.load( inputFile ); List pages = doc.getDocumentCatalog().getAllPages(); for( int i=0; i<pages.size(); i++ ) { PDPage page = (PDPage)pages.get( i ); PDStream contents = page.getContents(); PDFStreamParser parser = new PDFStreamParser(contents.getStream()); parser.parse(); List

java.lang.NoClassDefFoundError: Could not initialize class org.apache.pdfbox.pdmodel.font.PDFont

隐身守侯 提交于 2019-12-11 14:08:25
问题 I am using Apache Tika( tika-app 1.17) in wildfly modules. While I start extracting PDF it always throws the error: java.lang.NoClassDefFoundError: Could not initialize class org.apache.pdfbox.pdmodel.font.PDFont For other file extensions it works fine. Things I have tried out dependencies in apache-tika module.xml to PDFbox Explicitly loaded org.apache.pdfbox from standalone.xml I have also tried with the below structure app1.war->(WEB-INF)lib-->app.jar->lib-->tika-app-1.17.jar I have also

PDFBox: Unable to save pdf while running on tomcat

烂漫一生 提交于 2019-12-11 11:06:23
问题 This PDFBOX Example when i run from the main method & run java application then it successfully saving pdf document. But if the same code while running from doGet method of servlet on Tomcat server, then its NOT saving the pdf file. Very confuse can you help me why? do i have to add some external libarary to support for Tomcat server, please help.. Note : i have debugged doGet method its getting call not throuwing any exception Tomcat 6, PDFBox 1.87, all PDFbox dependecies i have included in

PDF issue while reaching end of page

我的梦境 提交于 2019-12-11 10:42:09
问题 Well I'm having some troubles when creating new pages. I get my data from a query. Sorry if I post a lot of code, but it's all needed and I'm not sure how to do a MCVE as I'm pretty new at working with PDF. This issue is: Before writing next block of code I check current Y coord, I can achieve this, but when I need to create new Page and start writing again, well happens this Here are the codes used in the PDF: public float checkContentStream(float y) throws Exception { float newY =

Bad characters when replacing text in pdf using pdfbox

荒凉一梦 提交于 2019-12-11 10:33:39
问题 I'm trying to replace text in pdf and it's kind of replaced, this is my code PDDocument doc = null; int occurrences = 0; try { doc = PDDocument.load("test.pdf"); //Input PDF File Name List pages = doc.getDocumentCatalog().getAllPages(); for (int i = 0; i < pages.size(); i++) { PDPage page = (PDPage) pages.get(i); PDStream contents = page.getContents(); PDFStreamParser parser = new PDFStreamParser(contents.getStream()); parser.parse(); List tokens = parser.getTokens(); for (int j = 0; j <

Continuously write data from memory to response stream

杀马特。学长 韩版系。学妹 提交于 2019-12-11 10:31:46
问题 So I'm using PDFBox to spit out an auto-generated PDF document based off an existing template. I used PDFMergerUtility to achieve somewhat of a solution: PDFMergerUtility finalDoc = new PDFMergerUtility(); for (StudentEN student : students) { PDDocument document = PDDocument.load("template.pdf"); PDPage page = (PDPage) document.getDocumentCatalog().getAllPages().get(0); PDPageContentStream contentStream = new PDPageContentStream(document, page, true, true); contentStream.beginText(); // Draw

Save an image present in PDF on local File System

亡梦爱人 提交于 2019-12-11 09:47:27
问题 This is my first experience of using PDFBox jar files. Also, I have recently started working on TestComplete. In short, all these things are new for me and I have been stuck on one issue for last few hours. I will try to explain as much as I can. Would really appreciate any help! Objective : To save an image present in a PDF file on the file system Issue : When this line gets executed objImage.write2file_2(strSavePath); , I get the error Object doesn't support this property or method . I am

How to check Fully embedded and subset embedded font using PDFBOX

你。 提交于 2019-12-11 08:51:30
问题 Hi I want to check fully embedding and subset embedding of fonts in PDF using PDFBOX. I have tried using the following logic to check: private boolean IsEmbedded(Map<String, PDFont> fontsMap, Set<String> keys) { for(String key:keys) { PDFont font = fontsMap.get(key); PDFontDescriptor fontDescriptor = font.getFontDescriptor(); if(null != fontDescriptor && fontDescriptor instanceof PDFontDescriptorDictionary){ PDFontDescriptorDictionary fontDescriptorDictionary = (PDFontDescriptorDictionary

Remove other operators and keep only Text operators(TJ,Tj) pdfBox

一曲冷凌霜 提交于 2019-12-11 08:38:31
问题 I have a pdf from which I wish to remove all the image and other drawing content from it. and save the resultant as a new pdf. I know how to remove text by using TJ , Tj operators , which I currently perform as below op.getOperation().equals( "TJ") Instead of removing the TJ,Tj operators , Is it possible to copy these Text operators onto an other pdf file with formatting intact so that the new pdf turns out to be pure text only pdf ? Its ok if text drawn using other than Tj , TJ operator