I am using Adobe's EchoSign API to retrieve a string representation of a PDF file. The problem I am running into is that writing the file to disk is working properly. The file length is a much different length than the string and won't open as a PDF.
As a test, I used an existing PDF file - one that I know is a true PDF, and tried to pull the contents of the file as a string like their API provides and then write it back to another file. The result is the same. I can open the "real" PDF using Adobe, but the new file will not open. This should be simple, but I am obviously missing something.
Here is what I have done to test this out: Scenario 1: Using string received from the API
File.WriteAllText(fileName, PDFstring, new UTF8Encoding(false));
Scenario 2: Using string received from the API. Yeah, it seemed dumb, but nothing has been working.
using (var sw = File.CreateText(fileName))
{
for (int p = 0; p < PDFstring.Length; p++)
{
var c = PDFstring.Substring(p, 1);
sw.Write(c);
}
}
Scenario 3: Use a known good PDF file and try to copy it by creating a string and writing it to a new file.
var filename = @"C:\Adobe\GoodDocument.pdf";
var newFile = @"C:\Adobe\Rewrite.pdf";
var fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
var file = new StreamReader(fs);
var allAdobe = file.ReadToEnd();
fs.Close();
File.WriteAllText(newFile, allAdobe, new UTF8Encoding(false));
All three scenarios gave the same results. I cannot use the new file. The file lengths are all longer than they should be. Attempting to open the new file asks for a password where the original does not.
Obeservation: I just ran scenario 3 again. Accept this time using the copied (incorrect) file as the original. The result was an exact duplicate! What gives? Is Adobe playing tricks with me?