BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
//Export the document after saving document.Save("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open); |
return doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open);
Use the below helper. http://www.syncfusion.com/downloads/support/forum/123489/ze/PdfResult2014998850 |
Response.Clear(); MemoryStream ms = new MemoryStream(pdfContent); //Pass the rendered byte array from back end. Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=Sample.pdf"); Response.Buffer = true; ms.WriteTo(Response.OutputStream); Response.End(); |
Thank you, can you tell me what is the problem with this file, I can not open it ?(attachment)
|
Here the attached document is not in proper PDF structure. It just contains the byte values. Hence it causes the document to be corrupted. |
//ms.Close(); By the way is closing and disposing useful here ? |
Yes, it will help to reduce the memory consumed by the application. |
Hi,
The document which you have sent is not a valid PDF document, you can check this by opening the PDF document in the Adobe Reader. We suspect that the code "result.Content.ReadAsByteArrayAsync().Result" does not returns proper PDF bytes as it contains only junk content. Could you please check the implementation of this in your code base.
Regards,
Karthikeyan.C
public HttpResponseMessage Post() { PdfDocument document = new PdfDocument(); // Add a page to the document PdfPage page = document.Pages.Add(); // Create Pdf graphics for the page PdfGraphics graphics = page.Graphics; // Create a solid brush PdfBrush brush = new PdfSolidBrush(Color.Black); // Set the font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20f); // Draw the text graphics.DrawString("Hello world!", font, brush, new PointF(20, 20)); using (MemoryStream customStream = new MemoryStream()) { document.Save(customStream as Stream); document.Close(true); HttpResponseMessage result = new HttpResponseMessage(); result = Request.CreateResponse(HttpStatusCode.OK); result.Content = new ByteArrayContent(customStream.ToArray()); result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileName = "Sample" + ".pdf"; return result; } } |