Latest Version of Aspose.Pdf
Using the PdfContentEditor and attempting to replace text on certain files throws an “Object reference not set to the instance of an object” error.
image.png (190.1 KB)
image.png (120.3 KB)
image.png (63.6 KB)
private async Task ReplaceAttachmentWithSignatures(CompileAttachment compileAttachment, string filePath)
{
await _azureProvider.DownloadToFileAsync(compileAttachment.AzurePdfPath, filePath);
var document = new Aspose.Pdf.Document(filePath);
var editor = new PdfContentEditor();
editor.BindPdf(document);
if (compileAttachment.MagicTags != null)
{
List<MagicTag> magicTags = compileAttachment.MagicTags.Where(x => x.Tag == "{{item.number}}" || x.Tag == "{{section.number}}").ToList();
editor.ReplaceTextStrategy.ReplaceScope = ReplaceTextStrategy.Scope.ReplaceAll;
foreach (var magicTag in magicTags)
{
//Replace all the matching keys in the text
editor.ReplaceText(magicTag.Tag, magicTag.Value ?? "");
}
ELSLogHelper.InsertInfoLog(ELSLogHelper.AsposeLogMessage("Save"), MethodBase.GetCurrentMethod()?.Name, MethodBase.GetCurrentMethod().DeclaringType?.Name, Environment.StackTrace);
editor.Save(filePath);
editor.Document.FreeMemory();
editor.Document.Dispose();
editor.Dispose();
editor = null;
}
}
Here is the attachment it is attempting to process.