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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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