我正在使用以下代碼使用iTextSharp SelectPDF將大型HTML內容轉換爲PDF。沒有一個HTML頁面被正確轉換。數據在6頁之後消失到PDF中。所有的HTML頁面都不會轉換爲PDF與SelectPdf
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);
}
}
有一個在iTextSharp的沒有'HtmlToPdf'類,所以你的問題不應該被標記爲iText的問題。我不知道'HtmlToPdf'是關於什麼的(我是iText的原始開發者;如果iTextSharp中存在這樣的類,我就知道了)。另外:如果你不共享HTML,不要期待答案。 –
看起來像SelectPDF給我:http://selectpdf.com/html-to-pdf/demo/convert-html-code-to-pdf.aspx我會更新標籤,你可以批准我的編輯布魯諾? –
也許OP是SelectPDF的當前用戶,但不滿意它?也許他們想切換到iText並且正在探索技術支持? –