【问题标题】:Syncfusion HTML To PDF conversionSyncfusion HTML 到 PDF 的转换
【发布时间】:2018-05-10 17:56:15
【问题描述】:

我遇到了一个有趣的问题。我使用 Syncfusion Essential Studio + Web Kit 将 HTML 转换为 PDF。有时它工作得很好,但有时它完全没用。

什么意思完全没用?每次调用 HtmlToPdfConverter 的 Convert 方法时,它都会抛出 UnauthorizedException。但也不是每次都出现,只是随机出现。 这是我的代码:

        string htmlString = "";

        try
        {   // Open the text file using a stream reader.
            using (StreamReader sr = new StreamReader("PdfTemplates\\template.html"))
            {
                // Read the stream to a string, and write the string to the console.
                htmlString = sr.ReadToEnd();
            }
        }
        catch (Exception e)
        {
            _logger.Error(e,"read the template html");
            throw e;
        }

        StringBuilder sb = new StringBuilder(htmlString);

        sb.Replace("%SOMETHING%", something);
        htmlString = sb.ToString();

        _logger.Information("htmltemplate with new data created");

        PdfDocumentBase mergedPdf;
        try
        {
            var pdfDocFromHtml = _htmlConverter.Convert(htmlString, ""); // THE Problematic line
            var pdfLoadedDocument = new PdfLoadedDocument(uploadedPdfStream);

            //template generation
            _logger.Information("pdf created from html");

             //merge the generated pdf with the uploaded document
             mergedPdf = MergePdf(pdfDocFromHtml, pdfLoadedDocument);

             _logger.Information("pdf merged");

             var resultStream = PdfDocumentToStream(mergedPdf);

            pdfDocFromHtml.Close(true);
            pdfLoadedDocument.Close(true);

                    return resultStream;
        }
        catch (Exception ex)
        {
            Type typeOfE = ex.GetType();
            _logger.Error(ex, "pdfLoadedDocument from byteArray");
            throw;
        }

我在一个团队中工作,没有一个队友有问题,只有我一个。我使用的是 Windows 10 专业版。我们正在开发一个 ASP.NET MVC 应用程序。

有人知道可能是什么问题吗?

【问题讨论】:

    标签: c# asp.net-mvc syncfusion unauthorizedaccessexcepti


    【解决方案1】:

    我尝试在 Windows 10 环境中使用 MVC 应用程序将 HTML 字符串转换为 PDF 时重现未经授权的异常,但它工作正常。我们之前没有遇到过类似的异常,您能否通过 Syncfusion Direct-Trac 支持系统创建一个新事件,并提供以下详细信息。

    1. 代码 sn-p 或重现问题的示例。
    2. 输入 HTML 文件或 URL。
    3. 有关操作系统和语言规范的环境详细信息。

    同时,请尝试使用同一项目将其他一些 URL (http://www.google.com) 转换为 PDF,并告诉我结果。

    注意:我为 Syncfusion 工作

    【讨论】:

    • 我尝试转换google.com,但也失败了。我也会联系支持人员。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多