Reputation: 41
I am using the following code to convert large HTML content to PDF using iTextSharp SelectPDF. None of the HTML pages are correctly converted. The data vanishes after 6 pages into the PDF.
public static void CreatePDFFromHTMLFile(string HtmlStream, string FileName)
{
try
{
// read parameters from the webpage
string htmlString = HtmlStream;
string baseUrl = "";
string pdf_page_size = "A4";
PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize),
pdf_page_size, true);
string pdf_orientation = "Portrait";
PdfPageOrientation pdfOrientation =
(PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation),
pdf_orientation, true);
int webPageWidth = 1024;
int webPageHeight = 0;
HtmlToPdf converter = new HtmlToPdf();
// set converter options
converter.Options.PdfPageSize = pageSize;
converter.Options.PdfPageOrientation = pdfOrientation;
converter.Options.WebPageWidth = webPageWidth;
converter.Options.WebPageHeight = webPageHeight;
// create a new pdf document converting an url
PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl);
doc.Save(FileName);
doc.Close();
}
catch (Exception ex)
{
Tracing.HandleException(ex);
}
}
Upvotes: 3
Views: 3448
Reputation: 109
That is happening because you are using the community edition of SelectPdf which is free with the limitation that you can only convert to pdf up to 5-6 pages long, if you need more than that you will need to use the non-free one instead from here https://selectpdf.com/downloads/
Upvotes: 3
Reputation: 295
The problem is that you are using SelectPdf community edition. According to SelectPdf (http://selectpdf.com/community-edition/), the free version is limited to 5 pages.
If you want to convert longer pages, you need to use the commercial edition, but that is not free.
Upvotes: 1