PDPageContentStream drwastring method is not working - pdfbox

I am trying to create a new pdf document using a java program using the pdfbox API, but
Exception in thread "main"
java.lang.NoClassDefFoundError:org/apache/commons/logging/LogFactory
Every time I am facing same error. I have already added external jar file to classpath, It is also showing that the drawString method of PDPageContentStream object is deprecated.
What could be the problem with this?

Related

Strongname Signing IKVM PDFBox for Word Addin

for a Word Addin I am using PDFBox to manipulate PDFs. Or rather I would like to use it. I used it before with a self-created Desktop App. PDFBox is a Java Library that can be made usable as DLLs with IKVM (like here: http://www.squarepdf.net/pdfbox-in-net ). The problem that I experience is that all libraries for Wordaddins must be strongnamed. I tried to strongname sign but then I get an exception that a part of apache common logging (in directory MANIFEST.MF) cannot be found.
I know this is pretty vague so far and I will post more details later on, but maybe someone already went through this and has an idea on how to do this right or can point me to some place where there is already a strongnamed version of PDFBox.
Thanks in advance!
I will give some more information to this question, because my colleague is in holiday. I have strong named all pdfbox-dlls and on the try to open a pdf, i will get the first FileNotFoundException. The File $(PrjectDir)\bin\x86\Debug\commons-logging.properties could not be found.
All following Exceptions has the same problem. As a sample the next exception is a DirectoryNotFoundException. It could not find \bin\x86\Debug\META-INF\services\org.apache.commons.logging.LogFactory . There are more than 10 FileNotFoundExceptions only at the opening of my PDF:
doc = PDDocument.load(new File(inputFile));
All of Them can't find something of the Logger.
In the next Step, i try to make a content Stream from the first page of that pdf:
contentStream = new PDPageContentStream(doc, (PDPage)doc.getDocumentCatalog().getAllPages().get(0), true, false);
The first Exception, i will become there is another FileNotFoundException for C:\Users(user).accessibility.properties or $(ProjectDir)\bin\x86\Debug\META-INF\services\java.text.spi.NumberFormatProvider
Until this point, i have 20 Exceptions or so. The most of them can't find something of the logger. But i can write the opened pdf to the harddisk. If i try to insert some text into contentstream, i get a harder Exception at the point i have to set the font:
PDFont font = PDType1Font.HELVETICA;
contentStream.setFont(font, 10);
At this point i get following Exception:
An exception (first chance) of type "System.TypeInitializationException" occurred in fontbox-1.8.12.dll.
Additional information: The type initializer for "org.apache.fontbox.cmap.CMap" generated an exception.
I think the references has a problem, if pdfbox is strong named. Has anybody an idea, what is to do? Thank you very much.

Can't get PDFBox CreatePDFA example to work - Color profile not found

I'm trying to get the example for creating a PDF/A document with Apache PDFBox up an running (CreatePDFA.java).
For this I copied the example class as is into a project module that includes a maven-dependency on PDFBox in version 2.0.0-RC3. I only changed the method signature and used a fixed font, filename and message instead of args[].
When trying to run the code I get an NPE in Line 107 because it cant't load the color profile (InputStream is null) When I check the included library in the project details I can see the resources folder, but it does not contain the expected file, namely "pdfa/sRGB Color Space Profile.icm".
Unfortunately, google-ing the problem only turned up more references to always the same example implementation, but after a while I acutally found what seems to be the needed file on apache.googlesource.com
I copied the file to our own resource directory and then used this line of code instead:
InputStream colorProfile = CreatePdfA.class.getResourceAsStream("/pdfa/sRGB Color Space Profile.icm");
This finally stopped the NPE - the file is apparently found - but now I get another exception which says:
java.lang.IllegalArgumentException: Invalid ICC Profile Data
Here, I'm stuck. I had hoped that this would work just out of the box, but it seems like I am missing something. Any ideas?
You already answered one part of the problem yourself: put the file into your resource directory.
The second problem may be a bad repository mirror or a transfer problem (binary to ascii). Here's the official repository URL with the ICC profile from the example:
https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/resources/org/apache/pdfbox/resources/pdfa/

Phantomjs is duplicating content when exporting to PDF

I've encountered a weird issue with Phantomjs when converting an html file to pdf. My html, resulting pdf, and rasterize.js files are below:
http://401web.com/_pub/2TRTI8E.html
http://401web.com/_pub/2TRTI8E.pdf
http://401web.com/_pub/rasterize.js
You will notice that in the PDF file, at page 6, the content gets cut off and then on page 7, the content is repeated and is then correct all the way to the end of the document.
The html file contains a series of tags with their src attributes set as data:image/png;base64...
The application call to the phantom library is as follows:
phantomJS.Run("C:\path\to\directory\rasterize.js"),
new[] { webpath, outFilePdf, "A4", "1", "portrait"}, null, null);
Note that sometimes the rendered pdf file will exhibit the break/repeat behavior in different locations within the document eg: page 7 instead of 6) but the same issue always occurs.
Also, I am using phantomjs throughout my application (with the same rasterize.js script) with no other issues. This only happens on this export and only if there are a number of images.
My theory is that there is something going on with the image.onload event, specifically with base64 data but I have no idea how to troubleshoot this.
This is all within a .Net MVC application. I am using the PhantomJS nuget package found here: https://www.nuget.org/packages/PhantomJS/
Help is greatly appreciated.
Update: when running phantomjs locally via command line I was receiving the error below:
[CRITICAL] QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written
libpng error: Read Error
I solved this (though I have no idea how/why) by replacing the cdn references in the html file to font-awesome.css and weather-icons.css files with locally hosted versions. After that, no more error and no more duplicate content.

Windows Phone 8.1 File Picker UnauthorizedAccessException

I have a problem trying to replicate the File Picker example in link, I create a new application using a Universal Application Windows store template.
I extract the content of the class Scenario02 and create a similar one in my example. This class implements an interface called IFileOpenPickerContinuable which I extract from the class ContinuationManager and create a file in my project with the same name to implement that interface.
I don't get any compilation errors when I run the application. When the line openPicker.PickMultipleFilesAndContinue(); is executed, it throw a exception.
'UnauthorizedAccessException'(Access is denied. Exception from HRESULT: 0x80070005) exception.
In the Microsoft example they don't modify any of the manifests of the application. Do you know what can I be missing?
(Question solved in a question edit. Converted to a community wiki answer.)
The OP wrote:
Solved! The problem was trying to launch the data picker in the class constructor.

Count not initialize Class JRLoader

I'm trying to embed a JR report into a EJB and then serve rendered as pdf with a webservice.
I put the report file into src\reports folder. The getResourceAsStream method work fine and return a stream, but when I call JRLoader.loadObject I get this error:
java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRLoader
I'm developing with NetBeans and running on GlassFish server (on Windows)
InputStream reportStream = this.getClass().getResourceAsStream("/reports/AlterDesignReport.jasper");
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportStream);
PS: this the report is taken from example projects from JasperReports, but i tryed with my report to