Html – download html file as pdf using abcpdf

abcpdfasp.netdownloadhtmlpdf

How can I download an HTML file as a PDF using abcpdf in ASP.Net, C#?

Best Answer

The following ASP.NET example in C# shows how you might create a PDF from a web page and stream it to a web browser...

<% @Page Language="C#" %>
<% @Import Namespace="WebSupergoo.ABCpdf7" %>
<%
Doc theDoc = new Doc();
theDoc.AddImageUrl("http://www.example.com");
byte[] theData = theDoc.GetData();
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline; filename=MyPDF.PDF");
Response.AddHeader("content-length", theData.Length.ToString());
Response.BinaryWrite(theData);
Response.End();
%>

Changing content-disposition from 'inline' to 'attachment' will change the behavior.

There's some further information in the product documentation on the Doc.GetData() function that you'll need to be aware of, and you may also find the 'Paged HTML Example' helpful.