This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Adding pdf to a XML file  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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
  • 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: 24368
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!