I developed a Java PDF viewer using Apache PDFBox. The problem is, when rendering a page of a PDF, if the page has file attachments, there is no icon shown in PDFBox rendering, like there is a paper clip icon, when such a file is opened in Adobe PDF reader.
Is it possible to automatically have such icons in the rendering using PDFBox? I think I saw such a code some time ago, like a single line that switches this behavior on and off but I can't find it. Thanks.
This was fixed in PDFBOX-5394 and will be in the version 2.0.26. However only one single symbol will be shown at this time: a paperclip in fixed size.
Related
I'm using docx4j to convert a microsoft word document into a pdf then displaying it in a browser http://www.docx4java.org/trac/docx4j and it works well for a preview. The problem I'm facing is that this conversion loses most of the microsoft word document formatting. Page breaks and fonts don't transfer into the PDF format properly and even though I'm using standard font types docx4j doesn't come with them. In a Linux Tomcat hosted scenario fonts are not found and throw exceptions as it falls back to sans serif or other generic types.
I have found this Microsoft tool to make documents render online, but I'm behind a firewall so I cannot include this tool as an option: https://products.office.com/en-us/office-online/view-office-documents-online
I'm open to suggestion on displaying a docx file as a preview and print option from within a browser. Pdf conversion appears to be the most promising, but I run into formatting issues.
Any ideas are welcome!
Have a play with http://converter-eval.plutext.com/viewer.html
Consider it an alpha level preview. We haven't quite released it yet, but you will be able to host it behind a firewall.
It isn't open source, I'm afraid, and we're still working out pricing (and whether/how there could be a free edition).
If you only need to render a docx document in a browser, u can use Google Documents Viewer for this as :
<iframe src="http://docs.google.com/gview?url=pathOfDocx&embedded=true" />
Currently I'm developing an application that allows users to create a template and generate it into a DOCX file. The application needs to be able to display to users the changes in the template as the user is creating it.
The approach I tried was using DOCX4J library (allows manipulation of DOCX file) and ICEPDF which is primarily used to display the DOCX into the swing component by converting it first into a PDF file. Now the problem in this approach is that it loads pretty slow and some of the changes that occurs in the DOCX file does not reflect on the PDF conversion (example: dashed underline, font changes). When I tried to open the DOCX file ouput in MS WORD, the file is viewed correctly so I know changes do occur, but it seems that ICEPDF just can't show it properly.
So I was wondering if anyone knows a java library that allows DOCX files to be viewed directly from a Swing Component instead of converting it first into a PDF file.
You can try docx4all or DocxEditorKit. Both of these are built around docx4j.
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 information that I get is as follows:
BAAAA+Tahoma-Bold (embedded Subset), type:TrueType, Encoding:
CAAAA+Tahoma (Embedded Subset), type:TrueType, Encoding:
Confused about this, I researched on how to embed fonts from OpenOffice and found that the PDF/A-1a option should be checked. So I made another PDF using this option (in case this was not used when making the original PDF file), yet I got the same results.
I would like your guidance understanding how this works. I would like to be able to open PDF files just as PDF readers do. I also read about the PDFBox_External_Fonts.properties but I am guessing this file shouldn't be modified since I am dealing with embedded fonts.
Thanks.
pdfbox is not able to parse embedded subsets of TrueType fonts.
As far as I understand it, embedded TrueType subsets are missing some metadata for the font file that pdfbox needs.
The bug is known but not easy to solve. Right now I can only advise to use embedded Type 1 Fonts if possible, pdfbox can deal with them.
You can also try to set the path to your complete font files in your pdfbox.jar under org/apache/pdfbox/resources/PDFBox_External_Fonts.properties, so if pdfbox cannot parse the subset, at least it can find a full path to the original font file. Maybe that works, but I have not tested this.
Good Luck!
Looking for a Java based PDF creation library. We're currently using Apache Velocity with HTML to render PDFs on the fly.
We'd like to be able to find a way to render large images (sometimes as big as 3000 x 1700) in a creative manner within the PDF container. For instance, a scrollable image pane within a PDF. This might not be possible within a PDF, I might be wrong.
Open source would ideal.
For a good PDF library you should take a look at iText: http://itextpdf.com/
I have used images of around 5000x4000 with iText without any problems.
I don't know if it is possible to create a working scrollpane inside a PDF, unless of course you were doing it through a custom PDF creator/viewer.
iText is open source but make sure to check out the AGPL license before you use it commecrially: http://itextpdf.com/terms-of-use/agpl.php
For just creating PDF files from images iText is a little overdimensioned. Give xsPDF a chance, it has no limits for images sizes and seems to be appropriate for your problem.
Just a FYI for anyone that may run into this in the future:
I used a library called PDFBox (http://pdfbox.apache.org/) to open a pre-existing PDF and modify the PDF with a custom sized PDFRectangle with the dimensions of the image. Then inserted the image and rectangle into that new page and got the desired results.
I didn't realize you could have multiple page sizes in a single PDF.
I am working on a web application (using Grails) which will generate a gift certificate. I'm thinking of a workflow like this:
The user will pick a template which will be stored as an image.
Then the text (name, date, amount etc) will be overlaid on the image to make the final certificate. There is a set of co-ordinates associated with each template which describes where to put each bit of text.
There is a kind of 'live preview' in the browser which shows the user what the final certificate will look like.
When the user is happy with the results, they download the certificate as a PDF and print it.
Can anyone recommend a library for Java (or Groovy) that will make it easy to do this? I'm not particularly worried about speed, as I suspect that the webapp will only be used by a few people at a time.
UPDATE: in the end I used the iText PDF library to overlay text on a PDF template using PDFStamper.
You can do this with the standard Java 2D graphics libraries - create a BufferedImage from the image, get its Graphics and use drawString() to put the text on top. Of course, the text would then be part of the bitmap in the resulting PDF, and not use the full printing resolution.
In addition to the answers above, I have come across the groovy library GraphicsBuilder and the Grails plugin j2D which are also potiential solutions.
You might consider using Batik to do this as SVG. Your image would be an <img> tag and your text would be one or more <text> tags. There's a converter (called FOP, I believe) which will get you PDF output.