Solved

How to create a PDF file using binary strings in C#? or converting Binary String to System Stream, etc.

Posted on 2008-06-24
2
2,229 Views
Last Modified: 2012-06-27
So i receive a xml from a web service.  The web service documentation claims that

( The response element returns the binary string that contains the pdf Summary Report image. You must have a method for converting the binary string to human-readable PDF file.)

The binary string that is returned starts like this
( <Image pdf=\"JVBERi0xLjMKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVyIC9GbGF0 ............ ) (attached the full xml )

I am wondering what is the best way to create this pdf file. We also use a tool (PDF4NET) that can accept streams to generate the pdf files.. But not sure the following methods to play with the returned xml..

Thank you

Response2.txt
0
Comment
Question by:beos1907
2 Comments
 
LVL 10

Accepted Solution

by:
Marcjev earned 500 total points
ID: 21859710
The data is base64 encoded. You should make a string of it and pass it thrue Convert.FromBase64String. (see that " is NOT part of the data at start and end!)
See my sample and result file. The actual data is replaced by ... to keep it smaller..
The resulting file is attached.
string pdf = "JVBE...Rgo=";

byte[] outArray = new byte[60000];

outArray = Convert.FromBase64String(pdf);

System.IO.FileStream sw;

sw = new System.IO.FileStream (@"c:\temp\een.pdf",System.IO.FileMode.CreateNew);
 

for (int i = 0; i < outArray.Length; i++)

   sw.WriteByte(outArray[i]);

sw.Close();

Open in new window

een.pdf
0
 

Author Closing Comment

by:beos1907
ID: 31470381
Thank you very much for taking care of this, it worked great..

Is it possible to remove the attached files..
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now