HTML转换器问题

时间:2018-10-04 17:59:56

标签: c# html

有人可以告诉我为什么我遇到以下错误 “由于当前线程不在单线程单元中,因此无法实例化ActiveX控件'8856f961-340a-11d0-a96b-00c04fd705a2'。” 当我尝试运行以下代码时。请记住,我正在使用syncfusion名称空间。它会在使用htmlconverter行时出错。

private void CreatePdfPage(ref PdfDocument doc, string targetUrl, bool addSection)
{
    PdfPage page;
    if (addSection)
    {
        page = doc.Sections.Add().Pages.Add();
    }
    else
    {
        page = doc.Pages.Add();
    }
    SizeF clientSize = page.GetClientSize();
    float number = new PdfUnitConvertor().ConvertToPixels(page.GetClientSize().Width, PdfGraphicsUnit.Point);
    using (HtmlConverter converter = new HtmlConverter())
    {

        converter.EnableJavaScript = true;
        converter.AutoDetectPageBreak = true;
        converter.EnableHyperlinks = true;
        HtmlToPdfResult result = converter.Convert(targetUrl, ImageType.Metafile, (int)Math.Round((double)Conversion.Fix(number)), -1, AspectRatio.KeepWidth);
        PdfMetafile metafile = new PdfMetafile(result.RenderedImage as Metafile)
        {
            Quality = 100L
        };
        PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat
        {
            Break = PdfLayoutBreakType.FitPage,
            Layout = PdfLayoutType.Paginate,
            SplitTextLines = false,
            SplitImages = false
        };
        result.Render(page, format);
    }
}

0 个答案:

没有答案