SVG markup in PDF as generated from Jasper Reports - java

Problem Statement
I have a SVG markup sent from front end javascript to back-end action classes. I am using Jasper Reports to generate PDF which will contain the SVG image( i have markup data only). How do i do that.
What i have tried
I have tried to embed SVG image( having the link to image file) to the PDF file while generating reports.
Looking for
How to embed svg markup so that i can see the image in PDF. Any other best approach to solve it.

In later versions of jasper reports you no longer need to add class="net.sf.jasperreports.engine.JRRenderable" to the imageExpression.
It is the default in JasperReports 6+ and JasperSoftStudio (JSS) will remove it if you add it in the Source pane.
The Tomcat SVG file provided in the JasperSoft Community answer works nicely. My own SVG file would show properly in MS Edge or Chrome but didn't appear in JSS.
When I added width, height, viewbox and overflow attributes to the svg element, it then did appear in JSS - so try the example first before trying the svg you actually want.

According to their own web site (here: http://community.jaspersoft.com/wiki/how-add-svg-image-your-report-jrxml) you need to include the SVG using a special HTML element:
<imageExpression class="net.sf.jasperreports.engine.JRRenderable">
<![CDATA[net.sf.jasperreports.renderers.BatikRenderer.getInstance(new java.io.File("D:\\tomcat.svg"))]]>
</imageExpression>

As the question indicates the absence of a SVG markup file, you could stick to the answer by David van Driessche but use a different getter:
BatikRenderer.getInstanceFromText($P{svgMarkup}) for example where svgMarkup is a parameter of String type containing the SVG markup data.

Related

how can i check color profile (CMYK or RGB) in PDF file using itext library

I'm working on an e-learning project. I have the pdf file's and I have to do the validation, that is pdf file contain the RGB/CMYK color profile or not.
If color profile is found RGB that is require to reject the file. I have tried so much but did not get appropriate logic/answer.
If anyone has any idea that how can i do this in itext or other java pdf library. please suggest me.
iText is for producing PDF files programmatically (e.g. converting from HTML to PDF, or producing PDF reports.) - it is only for producing, not for rendering, so you can't use it to check color.
In order to check color of a pixel in the PDF document
you need to render it to a BufferedImage or so, and then take the color of pixel in specific (x,y) position.
To render PDF you could use a library like ICEpdf, jpedal.
There is a topic on SO about java pdf renderer libraries Java PDF Renderer

PDF Validation task in ASP.Net web Application while uploading

I've been provided with PDF Validation task in my ASP.Net web Application. I need to do Preflight check for the following points.
Check for presence or barcode or text in a defined area.
Check for embedded font issues.
Check for image transparent issue.
Check version.
I have checked for the options available like Itextsharp etc but they are not fulfilling my requirement. Please help.
My name is Tilal Ahmad and I am developer evangelist at Aspose.
You may try Aspose.Pdf for .NET to accomplish your requirements:
- Check for presence or barcode or text in a defined area.
For checking text in a defined PDF page region, please check following documetnation link of Aspose.Pdf for .NET and analyze the extracted text string(extractedText).
Extract Text from an particular page region
To check presence of barcode in a defined PDF page area. Initially You should convert a specific page region to image and then use Aspose.Barcode to detect barcode from that image.
- Check for embedded font issues.
If you meant to embed un-embedded fonts into PDF document by "checking missing embedded fonts...to correct it" then you may try this documentation link of Aspose.Pdf for .NET for the purpose.
Embedding fonts in an existing PDF document
- Check version.
You may load your PDF document to Aspose.Pdf.Document() object and get the PDF version as following.
Aspose.Pdf.Document doc = new Aspose.Pdf.Document("input.pdf");
Console.WriteLine("PDF version: {0}",doc.Version);
- Check for image transparent issue.
For image transparency issue we need some investigation, if possible you can post your sample document and details in Aspose.PDF forum. We will look into it and guide you.
Furthermore, if you want to validate some PDFA standard then you may load PDF document to Aspose.Pdf.Document() object and use Validate method.
Validate PDF document for PDFA standard

iText inline svg not locate by coordinates

I've been trying to use batik and iText to create a PDF in my application containing an SVG graph, however I only seem to be able to find examples where the svg is located at some coordinates. I don't want to have the image located at some coordinates however, I'm wanting it to be put into the page, preferably fit to the width of the page depending on whether it is landscape or portrait and be inline with any other content that I might add, have everything wrap around it.
Is this possible? I'm beginning to suspect my wish that somewhere it will start behaving like HTML is going to be in vain.
Many thanks,
Andrew
p.s.I have a working JAVA class to place the SVG on the page as a template, as per this tutorial:
http://itextpdf.com/examples/iia.php?id=263
p.p.s.For people looking for this issue in relation to Vaadin Charts I've tagged the question as Vaadin related also, as that's what has generated my SVG.

Extracting the outline (or bookmarks) from PDF files using Java

I'm using PDFBox to extract the outline (bookmarks) information from PDF files, that's even explained in the same site.
However, I've had problems not extracting but generating the qualified urls (foo.pdf#page=22777&zoom=2,2,777) to open the PDF in those bookmarks. Sometimes PDFBox is not able to find the page in which the bookmark is placed (i.e. the page number, left coordinate or top coordinate are wrong.)
Anyone knows a PDF library capable to do this (preferably in Java)? Thanks.
Best regards,
Alexander.
iText (http://itextpdf.com) might work for you.
I've used it mostly to create PDFs (not so much with parsing already exitingones), but the library is good, and does have objects related to outlines and bookmarks.

Convert html to pdf with linked documents inline

I need to convert a bundle of static HTML documents into a single PDF file programmatically on the server side on a Java/J2EE platform using a batch process preferably. The pdf files would be distributed to site users for offline browsing of the web pages.
The major points of the requirements are:
The banner at the top should not be present in the final pdf document.
The navigation bar on the left should be transformed into pdf bookmarks from html hyperlinks.
All hyperlinked contents (html/pdf/doc/docx etc.) present in the web pages should be part of the final pdf document with pdf bookmarks.
Is there any standard open source way of doing this?
Try Apache FOP. I just used it to convert XML to PDF and I think you can do the same with HTML/DOM. The website has a whole section on running FOP in a Java application and there's example code for DOM to PDF.
You can try iText - but I am not sure whether it handles all that you require.
Moreover, it is always better if you explore many options and then decide what you can and cannot do. In many cases there won't be any library/API that will out of the box support all that you ask for.
You can try www.alt-soft.com Xml2PDF for this

Categories