【问题标题】:Converting docx to images using Aspose.Words使用 Aspose.Words 将 docx 转换为图像
【发布时间】:2015-03-05 14:42:08
【问题描述】:

我正在将生成的文档转换为 pdf 和 png,请参见下面的代码。但由于某种原因,字体有问题。在我的本地开发机器上,一切都是正确的,但是当部署在生产服务器上时,PNG 中的字体丢失了。我已经检查过,但它们已安装在服务器上。有人可以帮我解决这个问题吗?

var dstDoc = doc.Clone();
var newInvoice = new InvoicePdf(factuur);
var ds = newInvoice.ToDataSet();
dstDoc.BuiltInDocumentProperties.Title = newInvoice.InvoiceID;
dstDoc.BuiltInDocumentProperties.Subject = newInvoice.SendDate;
dstDoc.MailMerge.FieldMergingCallback = new HandleMergeFieldAlternatingRows();
dstDoc.MailMerge.ExecuteWithRegions(ds);

var filePath = Path.Combine(folderInvoices, newInvoice.SendDateOrginal.Year.ToString(CultureInfo.InvariantCulture));
Directory.CreateDirectory(filePath);
var fileName = string.Format("{0} - {1}", newInvoice.InvoiceID, newInvoice.DebtorCompany.ToString(true));
filePath = Path.Combine(filePath, fileName);
filePaths.Add(filePath + ".pdf");
dstDoc.Save(filePath + ".pdf", SaveFormat.Pdf);

var options = new ImageSaveOptions(SaveFormat.Png) { PageCount = 1, Resolution = 120, UseAntiAliasing = true, PrettyFormat = true, UseHighQualityRendering = true };
for (var i = 0; i < dstDoc.PageCount; i++)
{
    options.PageIndex = i;
    dstDoc.Save(string.Format("{0}_{1}.png", filePath, i), options);
}

【问题讨论】:

    标签: asp.net-mvc aspose.words


    【解决方案1】:

    如果它是共享服务器,那么很可能是安全问题。 Aspose.Words for .NET DLL 需要访问 Windows 注册表才能找到字体文件夹。详情请参考http://www.aspose.com/docs/display/wordsnet/Considerations+When+Running+on+a+Shared+Server+Environment

    一种解决方法也可以指定文件夹的路径,其中包含所有必需的字体。示例代码请见http://www.aspose.com/docs/display/wordsnet/How+to++Specify+True+Type+Fonts+Location

    我与 Aspose 合作,担任开发人员传道者。

    【讨论】:

    • 我们有自己的服务器,所以我们不共享它们。我会尝试设置文件夹的路径。但是您是否认为这是不同的,因为 PDF 是正确生成的。
    猜你喜欢
    • 2014-10-08
    • 2020-05-22
    • 2014-05-25
    • 2021-11-25
    • 1970-01-01
    • 2019-08-30
    • 2015-10-14
    • 2012-05-17
    • 2014-08-30
    相关资源
    最近更新 更多