Mark
Mark

Reputation: 9

PDF content inside XML response file

I receive XML file that includes PDF content:

<pdf>
<pdfContent>JVBERi0xLjQKJaqrrK0KNCAwIG9iago8PCAvV.......

How can I save the content into PDF file?

I'm using C# 4.0

Upvotes: 0

Views: 4832

Answers (3)

Matthew Whited
Matthew Whited

Reputation: 22443

That string value is the PDF in base64. If you convert the base64 to a byte array you can just write that byte array to disk.

Convert.FromBase64String

var buffer = Convert.FromBase64String(xmlStringValue);
File.WriteAllBytes(yourFileName, buffer);

Upvotes: 9

Jong Bor Lee
Jong Bor Lee

Reputation: 3855

It looks like the pdf content is encoded in base64. You will have to decode it and save it to a file.

Edit: indeed, when I use base64 to encode a pdf file, the first few characters are JVBERi0x...

Upvotes: 0

Felice Pollano
Felice Pollano

Reputation: 33252

It seems encoded with Base64, But not sure. if it is, you can take that long string and convert with the function Convert.FromBase64. You will obtain a byte[] that you can save as the actual pdf.

Upvotes: 1

Related Questions