: Set to application/pdf to tell the browser the file type.
Rather than saving a file to the server's disk, it is more efficient to use a MemoryStream . This allows you to generate the PDF entirely in memory and serve it directly to the user. : Set to application/pdf to tell the browser the file type
string htmlContent = " Thank you for your purchase! "; Use code with caution. 2. Converting HTML to PDF in Memory string htmlContent = " Thank you for your purchase
Response.Clear(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=Receipt.pdf"); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.BinaryWrite(bytes); Response.End(); Use code with caution. Important Considerations Converting HTML to PDF in Memory Response
How to convert HTML to PDF using iTextSharp - Stack Overflow
Install-Package iTextSharp -Version 5.5.13.3 Install-Package itextsharp.xmlworker Use code with caution. 1. Preparing the HTML String
First, define the HTML content you want to convert. For dynamic content, use a StringBuilder to assemble the markup.