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?
Related
I am developing a Java application through which I need to read the log files present on a server and perform operations depending on the content of the logs.
Files range from 3GB up to 9GB.
Here on stack I have already read the discussion about reading large files with java, I am attaching the link:
Java reading large file discussion
In the discussion, the files are read locally,
in my case i have to retrieve and read the file on the server, is there an efficient way to achieve this?
I would like to avoid having to download files given their size.
I had thought about using URL Reader to retrieve the files, but I have doubts about the speed of execution.
The files I need to recover are under the path C:\production\LOG\file.log
Do you have any suggestions or advice?
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.
Basically, I want to be able execute a byte stream as a file, without writing said bytes to a file.
I want to do this in a windows environment.
You could say I want a to create a file, copy the stream to the file, and open the file as an executable, but I want the file to have no physical manifestation on the disk.
Thanks
This is not possible to do using the standard Java API. You will have to rely on some OS specific native implementations, either that do the whole thing for you, or that allow you to create some sort of RAM-disk on which you can place your temporary data and execute it.
Possibly related:
write file in memory with java.nio?
Supposing you bytestream is the one of a standard exe, and you don't want to call a whole virtualisation environnement, the short answer is no because internal adresses in the code wouldn't map.
Here's a more detailled answer :
process.start() embedded exe without extracting to file first c#
Is it possible to download large files (>=1Gb) from a servlet to an applet using HttpClient? And what servlet-side lib is useful in this case? Is there another way to approach this?
Any server-side lib that allows you access to the raw output stream should be just fine.
Servlets or JAX-RS for example.
Get the output stream, get the input stream of your file, use a nice big buffer (4k maybe) and pump the bytes from input to output.
On the client side, your applet needs access to the file system. I assume you don't want to keep the 1GB in memory. (maybe we want to stream it to the screen, in which case you don't need elevated access).
Avoid client libraries that try to fully materialize the returned content before handing it to.
Example code here:
Streaming large files in a java servlet
How do I print a .dwg file from Java?
Is there is an API for accessing and passing the DWG AutoCAD file to the printer for printing?
Dwglib is a Java library for accesing DWG files. It is essentially a port from the Pythoncad DWG reading classes by Art Haas. jdwglib manages complex DWG objects allowing users to employ these objects directly in their applications.
You'll to find an API that allows you to read an AutoCAD dwg file. I haven't seen any Java ones, but you might be able to start from the .NET one following:
http://code.google.com/p/tf-net/wiki/DwgReaderWriter
Once you've found an API, then it might be as simple as printing whatever you render.