Combining pdfs into one pdf [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a web app that I am changing to use xPressions from EMC2. There is a point where xPressions returns a pdf document inside a java servlet. Before we added xPressions, we would combine several of these pdfs into one large pdf and send it back to the user/screen. But xPressions can only process one pdf at a time. It is returning the pdf as a byte[] array. So I am trying to find a way to take the byte[] arrays and combine them into one large pdf to send back to the user/screen. Before we had xPressions we were using an old version of Big Faceless (bfo.com) to combine the individual pdfs into one pdf in the servlet. I have not been able to get the byte[] array to a valid pdf using the old bfo.com software. I have searched on Google and here on stack overflow for another technique. I have found answers that are close but most are using Linux or c#. Also, these pdfs are created inside the java servlet and are not existing on a hard drive where I could read them in and convert them. I have to take the byte[] array and work with that. So, does anyone have any ideas for me ? Thanks in advance !

You can use PDFBox for merging your pdf files. PDFMergerUtility class has a method addSource which takes in an inputstream, you can convert the byte array to inputstream and add that as a source.
PDFMergerUtility merger = new PDFMergerUtility();
merger.addSource(...);
merger.addSource(...);
merger.setDestinationFileName(...);
merger.mergeDocuments();

Related

how to append data in an existing pdf? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to add some data to a PDF with iText 7 in a Java application.
I don't succeed in opening the pdf in append mode. I looked for some solutions online but all concerned iText5 (and use classes that doesn't exist any more.)
What can I do?
It depends on what you want specifically:
merge two documents:
https://developers.itextpdf.com/content/itext-7-examples/itext-7-merging-pdf-documents
add content at the end of a document:
Similar to before, you could create a new document (to a byte output stream), and merge the two together
add content to an existing page:
Hard to do, since that typically requires re-layout of the document, which no PDF-engine can currently do.
fill in forms in the document:
https://developers.itextpdf.com/content/itext-7-examples/itext-7-form-examples
add an attachment to the document:
https://developers.itextpdf.com/examples/miscellaneous/clone-embedded-files
extra (3):
Adding content to a PDF, in the middle of existing content is extremely hard.
To understand why, here is some information on how PDF documents are built internally:
PDF documents contain instructions for a viewer to render, rather than plain text
instructions and their arguments are grouped in 'objects'
objects can be compressed to reduce file size
a PDF document keeps an internal index of all of these objects, this is called the XREF table
the index inside a PDF document uses byte-offsets to tell a renderer where (in the file) an object can be found
Suppose you want to change (or add) something.
You'd mess up all the byte-offsets in the XREF. No viewer would be able to find any object again.
Then there is the fact that the PDF does not contain layout information. If you added something new, and existing content would need to move, you need layout information (what objects make a sentence? which sentences make a paragraph?). Only by having layout information can you sensibly re-layout the document.

read Java doubles from binary file into Python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have several matrices in Java that I would like to transfer to Python as efficiently as possible, without requiring anything but standard libraries on both the Java and Python sides.
Currently I serialize them to file using the writeDouble function to write the entries out one by one, and writeInt to write the dimensions of the matrices. Now I would like to read these matrices back into Python. I can get the integers using struct.unpack, but Java's serialization of doubles does not correspond to an algorithm that struct.unpack can implement.
How can I decode a Java double in the binary format that writeDouble uses? I have trouble even finding a specification for the encoding that writeDouble uses.
You're overengineering it; DataOutputStream.writeDouble() and related methods are for manually serializing a Java Object, so it can be re-read as a Java Object. If all you need is to transfer data, you can simply write them out as text (or bytes), then read them back in. Common formats are CSV, JSON, XML, and ProtoBuf.
If all you're doing is trying to transfer a list of doubles, you can even just write them out one per line, and read them right back in with Python.

How can I redirect java program output to another program? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to write my own desktop keyboard, that can be used to work with some programs like excel. I've already written all graphical stuff, but i can't find any information about redirecting program output to another program. I found Apache POI, but it can be used only to work with Microsoft documents. Is there, for example a buffer, where can I send my letters or chars in ASCII? And next to be shown in my document or note?
Is there, for example a buffer, where can I send my letters or chars in ASCII?
Yes. It's called the Clipboard. You can call Toolkit.getDefaultToolkit() and then use Toolkit.getSystemClipboard() to get it.
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents("Some ASCII Text", this);
Note that this is the same buffer used for copy (ctrl-c) and paste (ctrl-v) (or their platform specific counterparts).

How to compare two PDFs based on visual differences programmatically? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I need to compare and get all the visual differences in the two PDF files. I know there are some questions related to this on stack overflow but they are not fulfilling my need.
I'm currently using PDFBox to generate images for pages in PDF and comparing the bytes of the images.
By this approach I'm able to know that particular page is differing.
But I need to find to know some more fine details such as font size of some text, for say - "The text" is differing in the page number, say 6 in the PDFs.
Not only for text but I need to take care of all the visual differences such as images, text in the charts etc.
Please suggest me someway to achieve this.
PS: I tried using Apache Tika but I'm getting the sense that it could be used to get structured text in XHTML and metadata. But I'm seeing the fine details such as font size, font eight is not appearing in structured text. Please correct me if I'm getting it wrong.
PDF to image using Java
Convert PDF to thumbnail image in Java (there's an example of pdf-renderer use here)
https://www.google.com.br/search?q=PixelGraber&ie=utf-8&oe=utf-8&rls=org.mozilla:pt-BR:official&client=firefox-a&gws_rd=cr&ei=K1PhUqD2Jei0sQTQs4DoAw
A good library for converting PDF to TIFF?
Convert jpeg/png to an array of pixels in java
int pixels array to bmp in java
Finding pixel position
Get Pixel Color around an image
For extraction of text using PDFBox: Extracting text from PDF file using pdfbox
There are classes in PDFBox for detecting font position, type, size and maybe (didn't search deeper) other settings. (Links below) You could, then, extract text from both PDFs, compare them to check if texts are equal, then - if they are equal - compare their format. If there's something different, mark for display into another text, image or PDF.
http://pdfbox.apache.org/docs/1.8.3/javadocs/org/apache/pdfbox/util/TextPosition.html
http://pdfbox.apache.org/docs/1.8.2/javadocs/org/apache/pdfbox/pdmodel/graphics/PDFontSetting.html
Check out this Java package: https://java.net/projects/pdf-renderer
You can convert the pdf to an image and then traverse the image as a 2D array and compare differences like that.

Get code from JPEG or other image file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am currently trying to write an application which allows me to get the code of an image just like when you open an image in a text editor.
I thought about changing the extension of the file and setting up a bufferedreader?
I have no idea how to accomplish this. The best would be having the code from the image in a String or an array.
Any ideas?
Thanks in advance.
I don't know exactly what you mean by "code", but I suggest you use any kind of image library. Maybe this can help you. In the library you can then call methods such as getSize() and more.
EDIT: Is this the code you are looking for?
<x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:creator><rdf:Seq xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:li>Corbis</rdf:li></rdf:Seq>
</dc:creator><dc:rights><rdf:Alt xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:li xml:lang="x-default">© Corbis. All Rights Reserved.</rdf:li></rdf:Alt>
</dc:rights></rdf:Description><rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:tiff="http://ns.adobe.com/tiff/1.0/"><tiff:artist>Corbis</tiff:artist></rdf:Description><rdf:Description xmlns:xmp="http://ns.adobe.com/xap/1.0/"><xmp:Rating>3</xmp:Rating><xmp:CreateDate>2008-03-14T13:59:26.540</xmp:CreateDate></rdf:Description><rdf:Description xmlns:MicrosoftPhoto="http://ns.microsoft.com/photo/1.0/"><MicrosoftPhoto:Rating>50</MicrosoftPhoto:Rating></rdf:Description></rdf:RDF></x:xmpmeta>
Try regex and read the file as you suggested. Otherwise a JaxB parser might help if you manage to set it up right.
Text-Files != Binary-Files
First line from BufferedReader-Docu sais: "reads text ..."
Ok, we know images are not text. So you need to use any InputStream, so you have a File, you need the FileInputStream. Be warned: If you print those binary-data to console, it is automatically converted into text, some special binary-data may be skipped. You can not paste it into notepad and save the output as image again.

Categories

Resources