Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
2,455 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

916 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