带有邮件合并的 C# 应用程序生成 Aspose 错误!未设置条形码生成器

问题描述 投票:0回答:1

我有一个 C# 应用程序,它利用 Aspose 执行邮件合并并在结果文档上生成二维码。当我执行合并并查看生成的文档时,在二维码应该所在的位置,我看到一条错误消息,其中指出

Error! Bar code generator is not set.

这是我用来执行邮件合并的代码:

System.Data.DataTable dt = _repoForm.GetProtestCasesTempate(modelList, CertificationDate, SignedBy);
Aspose.Words.License license = new Aspose.Words.License();
license.SetLicense("Aspose.Total.xxxxxx.lic");
Aspose.Pdf.License oPdfLicense = new Aspose.Pdf.License();
oPdfLicense.SetLicense("Aspose.Total.xxxxxx.lic");
Aspose.BarCode.License oBarCodeLicense = new Aspose.BarCode.License();
oBarCodeLicense.SetLicense("Aspose.Total.xxxxxx.lic");

MemoryStream finalOutStream = new MemoryStream();
Aspose.Words.Document retainerDoc;
string PathToTemplate = "";
if (dt.Rows.Count > 0)
{
    IEnumerable<letter_templates> TemplatePath = _repo.FetchLetterTemplates("Protest");
    foreach (var item in TemplatePath)
    {
        PathToTemplate = item.full_file_path;
    }
    Aspose.Words.Document template = new Aspose.Words.Document(PathToTemplate);
    MemoryStream outStream = new MemoryStream();
    template.FieldOptions.BarcodeGenerator = new CustomBarcodeGenerator();
    template.MailMerge.Execute(dt);
    template.Save(outStream, Aspose.Words.SaveFormat.Docx);
    retainerDoc = new Aspose.Words.Document(outStream);
    retainerDoc.Save(finalOutStream, Aspose.Words.SaveFormat.Pdf);
    finalOutStream.Seek(0, SeekOrigin.Begin);
}

这就是我的 word docx 文件的样子:

这就是我执行代码时得到的结果:

右下角有两个合并字段的部分,我想在其中放置二维码,该部分包含在文本框中。文本框的大小是否会限制进程生成二维码的能力?

我不明白为什么我收到条形码生成器未设置错误消息。

非常感谢任何帮助。

aspose docx-mailmerge
1个回答
-1
投票

Aspose.Words 本身不渲染 DISPLAYBARCODE 字段。要呈现此类字段,您应该指定自定义条形码生成器。例如,请参阅 Aspose.Words 文档: https://reference.aspose.com/words/net/aspose.words.fields/fieldoptions/barcodegenerator/

和 Github: https://github.com/aspose-words/Aspose.Words-for-.NET/blob/b0f89864f49794ab15f264e35d41856b667143dd/Examples/ApiExamples/ApiExamples/CustomBarcodeGenerator.cs

© www.soinside.com 2019 - 2024. All rights reserved.