aspose file tools*
The moose likes XML and Related Technologies and the fly likes Adding pdf to a XML file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Adding pdf to a XML file" Watch "Adding pdf to a XML file" New topic
Author

Adding pdf to a XML file

suhem chauhan
Greenhorn

Joined: Jun 26, 2007
Posts: 14
Hi all,

I am trying to add a PDF file as string to XML file as below;

Charset utf8 = Charset.forName("UTF-8");
byte[] pdfBytes = outStream.toByteArray();
String pdfString = new String(pdfBytes,utf8);
I have written a method,"filterXmlString" which would filter the pdfstring for special character such as

character == 0x9 /* == '\t' == 9 */
character == 0xA /* == '\n' == 10 */
character == 0xD /* == '\r' == 13 */
(character >= 0x20 && character <= 0xD7FF)
(character >= 0xE000 && character <= 0xFFFD)
(character >= 0x10000 && character <= 0x10FFFF)

String purePDF = filterXmlString(pdfString);


once I get the purePDF I am setting this as a text in one of the tags of XML


When I see the output it is some encrypted message not I want to read and print this string back to PDF

Can someone please help me with this?

Thanks a lot in advance!
Suhem

suhem chauhan
Greenhorn

Joined: Jun 26, 2007
Posts: 14


Correcting the following sentence in my previous message

When I see the output it is some encrypted message now I want to read and print this string back to PDF.

Sorry for the confusion if any I have caused.

Thanks,
Suhem
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

No, you are on the wrong track.

A PDF is not a text file, it contains all sorts of binary data. So treating it as a text file is the wrong thing to do. ANd filtering out a few characters is just going to damage it.

To put a PDF into a text node in an XML document, you should convert the bytes to text in a systematic way. Frequently people choose Base64 to do this conversion and that would quite likely be better (and more practical) than anything you might write yourself.
suhem chauhan
Greenhorn

Joined: Jun 26, 2007
Posts: 14
Thanks a lot Paul for your reply. I shall try with base64 and post you the results soon.

Suhem
suhem chauhan
Greenhorn

Joined: Jun 26, 2007
Posts: 14
Hi Paul,

Wow!! It worked! I just had to add two lines of code and that is it.
Thank you so much for your help!

Suhem
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Adding pdf to a XML file