strickdd - thanks for the help in regards to generating a PDF from memory. The little bit of code in your reply got me on the right track. My final code to make it happen was this:
protected void GenerateErrorLog()
{
Reports.PDF pdfMaker = new Reports.PDF();
pdfDocument pdf = pdfMaker.CreateErrorLogPDF
MemoryStream stream = new MemoryStream();
pdf.createPDF(stream);
Byte[] pdfBytes = stream.ToArray();
Response.ContentType = "Application/pdf";
Response.BinaryWrite(pdfBy
Response.End();
}
Reports.PDF is a custom class I made that uses the SharpPDF.dll to create PDF documents. My CreateErrorLogPDF() method returns an object of type sharpPDF.pdfDocument. Once I have the document created, I load it into a memory stream, convert the stream to a byte array and then write the bytes directly to the browser. This way I don't actually have to save a pdf file on the server before I display it, and I don't have to worry about deleting the file when I'm done either.
To get the PDF to open in a new window/tab, I added javascript to the ASP.Net control that was responsible for generating the report:
<asp:ImageButton ID="btViewErrorLog" runat="server"
ImageUrl="App_Images/Butto
OnClick="DetermineReport"
OnClientClick="OpenReport(
//JavaScript Function:
function OpenReport()
{
window.open("Report.aspx",
}
The page the javascript opens "Report.aspx" is just a blank page with no html or asp.net controls, however it does have code behind. The code behind looks at session variables I pass from the original page (via the DetermineReport() method from above), to determine what type of report to create, and if the session variables signal PDF, it runs the GenerateErrorLog() method above.
Main Topics
Browse All Topics





by: strickddPosted on 2009-09-30 at 09:43:21ID: 25460711
//You'll have to add the content type and length as well as: leByteArra y)
Response.BinaryWrite(PdfFi
Response.End()
//This will prompt a download to the browser.