• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Adding pdf to a XML file

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Sheriff
Posts: 28365
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Paul for your reply. I shall try with base64 and post you the results soon.

Suhem
 
suhem chauhan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You don't like waffles? Well, do you like this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic