Reputation: 33
I'm getting blank PDFs when saving signed PDF documents from DocuSign from Connect event notification. As I understand it the PDFBytes value is Base64 encoded, so this is my code to convert that into a string:
XmlNode docs = xmldoc.SelectSingleNode("//a:DocumentPDFs", mgr);
foreach (XmlNode doc in docs.ChildNodes)
{
string documentName = doc.ChildNodes[0].InnerText;
string documentId = doc.ChildNodes[2].InnerText;
string byteStr = Encoding.UTF8.GetString(Convert.FromBase64String(doc.ChildNodes[1].InnerText));
System.IO.File.WriteAllText(LOGPATH + envelopeId.InnerText + "_" + documentId + "_" + documentName, byteStr);
}
However, this produces empty PDFs. Has anyone had any success with this?
Upvotes: 2
Views: 249
Reputation: 7393
No need to encode the bytes after converting the Base64 string. Try this
byte[] fileBytes = Convert.FromBase64String(doc.ChildNodes[1].InnerText);
string filePath = LOGPATH + envelopeId.InnerText + "_" + documentId + "_" + documentName + ".pdf";
System.IO.File.WriteAllBytes(filePath , fileBytes);
Upvotes: 1