1

我在一项 Service Fabric 服务中使用 TuesPechkin 从 HTML 生成 PDF 文件。这在我的本地开发计算机上运行良好,但是一旦我将应用程序部署到 Azure 集群并运行相同的代码,我就会收到以下错误消息:

Unable to load DLL 'wkhtmltox.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

我认为这可能是因为 TuesPechkin 依赖于 Visual C++ 2013 运行时。Azure 群集是否支持此功能?还是有其他问题?

我生成 PDF 的代码如下所示:

private static readonly IConverter _converter = new ThreadSafeConverter(
                                                        new PdfToolset(
                                                            new Win64EmbeddedDeployment(
                                                                new AssemblyFolderDeployment())));        

    public Task<byte[]> GeneratePdfFromHtml(string title, string html)
    {            
        try
        {
            var document = new HtmlToPdfDocument
            {
                GlobalSettings = {
                ProduceOutline = true,
                DocumentTitle = title,
                PaperSize = PaperKind.A4, // Implicit conversion to PechkinPaperSize
                Margins = {
                        All = 1.375,
                        Unit = Unit.Centimeters
                    }
                },
                Objects =  {
                new ObjectSettings { HtmlText = html }
                }
            };

            byte[] result = _converter.Convert(document);
            return Task.FromResult(result);
        }
        catch(Exception e)
        {
            throw e;
        }                
    }

AssemblyFolderDeployment.cs

public class AssemblyFolderDeployment : IDeployment
    {
        public string Path
        {
            get
            {
                return System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Wkhtml");
            }
        }
    }
4

0 回答 0