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,244 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

18 Experts available now in Live!

Get 1:1 Help Now