我正在使用Expertpdf库将pdf页面转换为html页面,并且该函数给出了错误“ WebKit Navigation timeout”。
public void ConvertHTMLStringToPDF(string compHTML)
{
var isIE8 = Request.Browser.Browser == "IE" && Request.Browser.MajorVersion <= 8;
string htmlString = compHTML.Replace("valuesss", "value").Replace("scheckedss", "checked")
.Replace("<link href='includes/Print.css' />", "<style>\n" +
System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("includes/Print.css")).Replace("../images/", "images/") + "</style>");
//Create the PDF converter. Optionally you can specify the virtual browser
//width as parameter. 1024 pixels is default, 0 means auto detect
string baseURL = this.Request.Url.ToString();
var pdfConverter = new PdfConverter(0);
//pdfConverter.DrawBackColors = true;
pdfConverter.DrawBackground = true;
pdfConverter.PdfDocumentOptions.EmbedFonts = true;
pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
pdfConverter.LicenseKey = "78Tdz9fP3d/cz9bB38/c3sHe3cHW1tbW";
// set the converter options
pdfConverter.PdfDocumentOptions.AutoSizePdfPage = true;
pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
pdfConverter.PdfDocumentOptions.TopMargin = 10;
pdfConverter.PdfDocumentOptions.BottomMargin = 1;
pdfConverter.PdfDocumentOptions.LeftMargin = 1;
pdfConverter.PdfDocumentOptions.RightMargin = 1;
pdfConverter.PdfDocumentOptions.SinglePage = SinglePagePDF;
pdfConverter.AvoidTextBreak = true;
pdfConverter.AvoidImageBreak = true;
if (PrintinLandScape)
{
pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Landscape;
}
else
{
pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait;
}
//pdfConverter.PdfDocumentOptions.EmbedFonts = true;
pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = false;
pdfConverter.PdfDocumentOptions.JpegCompressionEnabled = false;
//FOOTER OPTIONS
pdfConverter.PdfDocumentOptions.ShowFooter = true;
pdfConverter.PdfFooterOptions.FooterHeight = 10;
pdfConverter.PdfFooterOptions.FooterTextColor = Color.Black;
pdfConverter.PdfFooterOptions.FooterTextFontType = PdfFontType.HelveticaOblique;
pdfConverter.PdfFooterOptions.FooterTextFontSize = 6;
pdfConverter.PdfFooterOptions.DrawFooterLine = true;
pdfConverter.PdfFooterOptions.PageNumberText = "Page";
pdfConverter.PdfFooterOptions.PageNumberTextColor = Color.Black;
pdfConverter.PdfFooterOptions.PageNumberTextFontType = PdfFontType.HelveticaBold;
pdfConverter.PdfFooterOptions.PageNumberTextFontSize = 6;
pdfConverter.PdfFooterOptions.PageNumberYLocation = (float)2.0;
pdfConverter.PdfFooterOptions.ShowPageNumber = true;
pdfConverter.ImgTransparency = 0;
//System.IO.File.WriteAllText(Server.MapPath("abc.html"), htmlString);
var objpdf = pdfConverter.GetPdfDocumentObjectFromHtmlString(htmlString, baseURL);
SavePrintHtmlOnFile(htmlString); //save print html string in print.html file
var attach = "inline";
var content = "application/pdf";
var filename = GetDownloadFileName + DateTime.Now.Ticks + ".pdf";
var fpath = SessionFolder + "\\" + filename;
if (RenderIn == RenderMode.PRINTPDF)
{
objpdf.OpenAction.Action = new ExpertPdf.HtmlToPdf.PdfDocument.PdfActionJavaScript("this.print({bShrinkToFit: true});");
Response.AddHeader("Content-Disposition", "inline; filename=" + pdfPageName);
}
else
{
if (isIE8)
{
attach = "attachment";
ScriptManager.RegisterStartupScript(this, this.GetType(), "asdfw3safsd", "window.location.href=('Download.aspx?name=" + (Server.UrlEncode(GetDownloadFileName + ".pdf")) + "&file=" + Server.UrlEncode("sessionfolders/" + Session.SessionID + "/" + filename) + "&content=" + Server.UrlEncode(content) + "');", true);
}
else
{
attach = "attachment";
ScriptManager.RegisterStartupScript(this, this.GetType(), "asdfw3safsd", "window.open('Download.aspx?name=" + (Server.UrlEncode(GetDownloadFileName + ".pdf")) + "&file=" + Server.UrlEncode("sessionfolders/" + Session.SessionID + "/" + filename) + "&content=" + Server.UrlEncode(content) + "');", true);
}
}
Response.ContentType = "application/pdf";
Response.ClearContent();
objpdf.Save(Response.OutputStream);
Response.End();
}
它在点上给出了错误
var objpdf = pdfConverter.GetPdfDocumentObjectFromHtmlString(htmlString, baseURL);
例外细节与其他人一样
at ExpertPdf.HtmlToPdf.ImgConverter.GetMetafileFromHTMLStringWithWebKit(String htmlString,String baseUrl,String internalLinksDocUrl,ᦕ[]&fonts,ᥲ&htmlParseInfo) 在ExpertPdf.HtmlToPdf.PdfConverter.ConvertAndGetPdfDocument(字符串url,字符串htmlString,字符串baseUrl,字符串internalLinksDocUrl,布尔fromUrl) 在ExpertPdf.HtmlToPdf.PdfConverter.GetPdfDocumentObjectFromHtmlString(String htmlString,String urlBase) 在D:\ GIT \ HondaBikeWeb \ ClearViewAPP \ BusinessLayer \ SkyviewPage.cs:line 768中的ThemeablePage.ConvertHTMLStringToPDF(String compHTML) 在D:\ GIT \ HondaBikeWeb \ ClearViewAPP \ Export.aspx.cs中的Export.Refresh()中:第61行 在D:\ GIT \ HondaBikeWeb \ ClearViewAPP \ Export.aspx.cs:第14行的Export.Page_Load(Object sender,EventArgs e)中 在System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,EventArgs e) 在System.Web.UI.Control.OnLoad(EventArgs e) 在System.Web.UI.Control.LoadRecursive() 在System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)