Returning a dynamic pdf without saving to disk

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v8)  /  Re: Returning a dynamic pdf without saving to disk

DynamicPDF CoreSuite for .NET (v8) Forum

Can anyone tell me how I can return a CETE Document class object via a stream without saving it to disk? Currently I have the following approach:

public ActionResult PDF(int? id)
{
    ParameterDictionary parameters = new ParameterDictionary();
    parameters.Add("BillID",id);

    DocumentLayout reportDocument = new DocumentLayout(Server.MapPath(@"\PDF\bill2015-v1.1.dplx"));
    Document document = reportDocument.Run(parameters);
    document.DrawToWeb(Server.MapPath(@"\PDF\mynewreport3.pdf"));
    return File("~/PDF/mynewreport3.pdf", "application/pdf");
}

I know I can use the FileContentResult to return a file I am just not sure how I can create a stream from the Document class, is there any methods for this?
Posted by a ceTe Software moderator
Hello,

Overloads available for Document.Draw() method allows for saving the PDF to a byte array or memory stream.

Thanks,
ceTe Software Support Team.
I have tried the memory stream approach as follows:

DocumentLayout reportDocument = new DocumentLayout(Server.MapPath(@"\PDF\bill2015-v1.1.dplx"));
Document document = reportDocument.Run(parameters);               
MemoryStream stream = new MemoryStream();
document.Draw(stream);
return File(stream, "application/pdf");

But this is failing to return a document, only a blank PDF screen
Posted by a ceTe Software moderator
Hello,

We have verified the Draw method overload that saves the PDF to a memory stream and it is working as expected and produces a valid memory stream of the PDF. The File() method you are calling to which you are passing the PDF memory stream is not a part of our library and we are not sure what it does.

If your goal is to display the PDF directly in the browser, try the following code snippet. Make sure you have a functional PDF viewer plug-in installed in the browser otherwise the browser is not capable of displaying the PDF.

Document document = report.Run();
byte[] pdfBytes = document.Draw();
HttpResponseBase response = context.RequestContext.HttpContext.Response;
response.Clear();
response.ContentType = "application/pdf";
response.BinaryWrite(pdfBytes);
response.End();

Thanks,
ceTe Software Support Team.
I tryed your implementation, and i am still getting blank pdf file with correct num of pages, like i am getting with File() method ???
Posted by a ceTe Software moderator
Hello,

Please send the following information to support@cete.com so we can look into it further.

1. Code used.
2. dplx file.
3. Output PDF.
4. Version & build number of DynamicPDF dll. You can get this information in dll reference properties (Version and description fields) in Visual Studio.

Thanks,
ceTe Software Support Team.
Did you resolve this isue, currently I have the same problem
Posted by a ceTe Software moderator
Hello,

Currently there are no known issues that result in a blank PDF.

We provide two different Draw method overloads (Byte Array & Memory Stream) that will allow you to keep the generated PDF in memory for further processing by your application.   
 
If you are running into this type of issue where you are generating a PDF byte array or memory stream and processing it further, you may try the following to locate the issue.

To test whether the Draw method is generating the PDF correctly or not, right after you call the Draw method save the resulting byte array or memory stream to a file path and open that PDF file and check.

If the PDF saved to disk is displays correctly, then the Draw method has correctly created the PDF byte array or memory stream, in this case it is likely that your application code that is processing this PDF byte array or memory stream is somehow corrupting the PDF and causing the blank page issue.

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 7:22 PM.