How to integrate wkhtmltopdf into my java webapplication? - java

I am trying to generate PDF document from HTML using wkhtmltopdf. But I am not able to figure out how to integrate wkhtmltopdf into my webapplication as there are no jar files in the tar file provided by the author. Can someone help me to set up this?

The wkhtmltopdf program is provided in a form of a stand-alone executable. It uses Qt Webkit module from Qt library for rendering the HTML and producing the PDF output. It is written in C/C++ thus you will be unable to find any JAR files.
You can save the HTML to a temporary file, use Runtime.exec() or ProcessBuilder to fork a new process from Java and when the process finishes, read the PDF file.
Qt Jambi might help you as well with its QWebView class might help you as well. Alternatively, you can implement your own wrapper over Qt Webkit in C and create Java bindings using JNI for calling it from Java in-process.
Depending on the target environment, you have to assess if you can afford forking processes from Java or implementing native calls as it might be a possible security risk.

Related

Execute qpdf command from java process with in memory pdf

I have a java service that merging two pdf files using qpdf like:
qpdf --underlay file1.pdf --to=1-z --from=1-z -- file2.pdf output.pdf
The qpdf is being called from java using ProcessBuilder API
Now I need to merge these pdfs while they are sit in memory, not on physical files. However qpdf requires input to be seekable and can't read data from stdin.
My pdfs are byte[] arrays inside java so are available at once(seekable) but I have no idea how to feed them to the qpdf service using OS level tools.
Can you suggest me how to handle this using CLI, pipe or similar kind of solution from within java process?

Java API for vsd or vdx file generation

Is there any library to generate Visio files from Java?
DatadiagramML schema (vdx) is availible on http://www.microsoft.com/en-us/download/details.aspx?id=23976, but it looks very complicated and I hope for any API?
Some Options for You:
VisioAutomation.VDX
I wrote a library called "VisioAutomation.VDX" that may be of some help to you. It is written in C# but should be a straightforward conversion to Java.
You can get the source code here: https://github.com/saveenr/VisioAutomation
pkgVisio
http://pkgvisio.codeplex.com/
For the Visio 2013 XML format
Visio's own API is a COM API therefore if your application is on Windows you could use a Java to COM bridge and use Visio to generate the drawings. You may have to purchase a Visio license for each PC running you application and there are licensing restrictions on using this method in a server scenario.
An alternative which you may want to consider is using a library which generates a non-Visio file format Visio supports such as SVG.

Embed XML file into PDF

I need to embed an XML file (or simple text file) into a PDF generated via Java and Adobe LiveCycle SOAP call.
I can't use iText or another library but only HTML code submitted to LiveCycle for transformation.
How can I do?
Thank you!
If you have access to the LiveCycle server you can set up a simple process that makes use of the XSLT service bundled in Foundation (available on every LC installation) to transform the HTML to something that your PDF will consume. I can give advice but need more details on your environment and LC modules installed in your server.

Multiple file upload (even folder)

I'm looking for an easy to use (free) "module" that can upload multiple files / folders.
It must:
Support image files
be user-friendly
be customizable
It may be written in:
RoR (Ruby On Rails)
Java
Flash
Thanks in advance.
Have a look here http://jimneath.org/2008/04/17/paperclip-attaching-files-in-rails the article explains how to use Paperclip
Or you could try SWFUpload , a Javascript & Flash solution for file uploads
Uploading multiple files and folders in one go is not supported by HTML, which means that your options are Flash or a Java applet. Ruby on Rails isn't going to help you because it's a server-side framework that generates HTML.

Help in creating Zip files from .Net and reading them from Java

I'm trying to create a Zip file from .Net that can be read from Java code.
I've used SharpZipLib to create the Zip file but also if the file generated is valid according to the CheckZip function of the #ZipLib library and can be successfully uncompressed via WinZip or WinRar I always get an error when trying to uncompress it using the Java.Utils.Zip class in Java.
Problem seems to be in the wrong header written by SharpZipLib, I've also posted a question on the SharpDevelop forum but with no results (see http://community.sharpdevelop.net/forums/t/8272.aspx for info) but with no result.
Has someone a code sample of compressing a Zip file with .Net and de-compressing it with the Java.Utils.Zip class?
Regards
Massimo
I have used DotNetZip library and it seems to work properly. Typical code:
using (ZipFile zipFile = new ZipFile())
{
zipFile.AddDirectory(sourceFolderPath);
zipFile.Save(archiveFolderName);
}
I had the same problem creating zips with SharpZipLib (latest version) and extracting with java.utils.zip.
Here is what fixed the problem for me. I had to force the exclusion of the zip64 usage:
ZipOutputStream s = new ZipOutputStream(File.Create(someZipFileName))
s.UseZip64 = UseZip64.Off;
Can't help with SharpZipLib, but you can try to create zip file using ZipPackage class System.IO.Packaging without using 3rd part libraries (requires .NET 3+).
To judge whether it's really a conformant ZIP file, see PKZIP's .ZIP File Format Specification.
For what it's worth I have had no trouble using SharpZipLib to create ZIPs on a Windows Mobile device and open them with WinZip or Windows XP's built-in Compressed Folders feature, and also no trouble producing ZIPs on the desktop with SharpZipLib and processing them with my own ZIP extraction utility (basically a wrapper around zlib) on the mobile device.
You don't wanna use the ZipPackage class in .NET - it isn't quite a standard zip model. Well it is, but it presumes a particular structure in the file, with a manifest with a well-known name, and so on. ZipPackage seems to have been optimized for Office docs and XPS docs.
A third-party library, like http://www.codeplex.com/DotNetZip, is probably a better bet if you are doing general-purpose ZIP files and want good interoperability.
DotNetZip builds files that are very interoperable with just about everything, including Java's java.utils.zip. But be careful using features that Java does not support, like ZIP64 or Unicode. ZIP64 is useful only for very large archives, which Java does not support well at this time, I think. Java supports Unicode in a particular way, so if you produce a Unicode-based ZIP file with DotNetZip, you just have to follow a few rules and it will work fine.
I had a similar problem with unzipping SharpZipLib-zipped files on Linux. I think I solved it (well I works on Linux and Mac now, I tested it), check out my blog post: http://igorbrejc.net/development/c/sharpziplib-making-it-work-for-linuxmac

Categories

Resources