Error displaying PDF to browser


#1

Im using the following code:

public void WriteDocument(HttpResponse response)

{

byte[] data = null;

FileStream inputFile = null;

FileStream outputFile = null;

try

{

// open an existing PDF form

inputFile = new FileStream(m_ClosingFormPath, FileMode.Open,
FileAccess.Read);

outputFile = new FileStream(m_OutputPath, FileMode.Create,
FileAccess.Write);



Form pdfForm = new Form(inputFile, outputFile);





// fill fields

pdfForm.FillField(“IssueDate”, m_IssueDate);



//Lender Fields

pdfForm.FillField(“LenderName”, m_LenderName);



pdfForm.FillField(“LenderAddress”, m_LenderAddress);



pdfForm.FillField(“LenderCity”, m_LenderCity);



//Agent fields

pdfForm.FillField(“AgentName”, m_AgentName);



pdfForm.FillField(“AgentAddress”, m_AgentAddress);



pdfForm.FillField(“AgentCity”, m_AgentCity);



//Transaction fields

pdfForm.FillField(“AgentFileNumber”, m_AgentFileNum);



pdfForm.FillField(“BorrowersName”, m_BorrowersName);



pdfForm.FillField(“PropertyAddress”, m_PropertyAddress);



pdfForm.FillField(“PropertyCity”, m_PropertyCity);



pdfForm.FlattenAllFields();

pdfForm.Save();



response.ClearContent();

response.ClearHeaders();



data = new byte[inputFile.Length];



inputFile.Read(data, 0, (int) inputFile.Length);

response.ContentType = “Application/pdf”;

response.AddHeader(“content-disposition”, “inline”);

response.AddHeader(“content-length”, data.Length.ToString());



response.BinaryWrite(data);

}

catch(Exception ex)

{

throw new Exception(ex.Message);

}

finally

{

response.End();

outputFile.Close();

}



and I receive 'File does not begin with %PDF- ’ in a message box when Adobe goes to open.

Any thoughts or suggestions?



#2

Thanks for considering Aspose.

We will investigate this problem later, here is a workaround for you.

===============================================

.......................

MemoryStream outputFile = null; // Please use MemorySteam instead for the result PDF document.

.......................

outputFile = new MemoryStream();

.......................

byte[] outBuf = outputFile.GetBuffer();

Response.Expires = 0;
Response.Buffer = true;
Response.ClearContent();
Response.AddHeader("content-disposition", "inline");
Response.ContentType = "application/pdf";
Response.BinaryWrite(outBuf);
outputFile.Close();
Response.End();

================================================