When running the following code .NET CORE Linux (AWS lambda environment) on file:
I get the exception below
The code runs find on Windows. I see a reference to fonts … maybe does not work when certain
fonts are missing?
Document pdf = new Document(sourceFile);
if (pdf.Form.Type == FormType.Dynamic)
{
// Convert Dynamic XFA form to standard form
pdf.Form.Type = FormType.Standard;
pdf.Save(localTempFile);
}
Object reference not set to an instance of an object.: NullReferenceException
at …ctor(FontCollection , )
at Aspose.Pdf.Forms.Form.(String , String , String )
at Aspose.Pdf.Forms.Form.set_Type(FormType value)
at PdfSplit.Function.LoadPdf(PdfLoadRequest request) in C:\Users\Administrator\Documents\GitHub\ingest-pdf-split\PdfSplit\PdfSplit\Function.cs:line 71
at PdfSplit.Function.PdfLoadHandler(Dictionary`2 input, ILambdaContext context) in C:\Users\Administrator\Documents\GitHub\ingest-pdf-split\PdfSplit\PdfSplit\Function.cs:line 29
at lambda_method(Closure , Stream , Stream , LambdaContextInternal )
PS:
Font inspection on the XFA Dynamic PDF (using code below) only returns standard font Times-Roman
Font found in the PDF XFA_Dynamic.pdf document: Times-Roman
public static void GetFontsList(string sourcePdf)
{
Document pdf = new Document(sourcePdf);
HashSet<string> fontNames = new HashSet<string>();
for (int i = 1; i <= pdf.Pages.Count; i++)
{
foreach (Font font in pdf.Pages[i].Resources.Fonts)
{
if(!fontNames.Contains(font.FontName))
fontNames.Add(font.FontName);
}
if (pdf.Pages[i].Resources.Forms.Count > 0)
ProcessXForms(pdf.Pages[i].Resources.Forms, fontNames);
}
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
foreach (string fontName in fontNames)
{
Console.WriteLine("Font found in the PDF "+ sourcePdf+"document: "+ fontName);
}
pdf.Dispose();
}
public static void ProcessXForms(XFormCollection forms, HashSet<string> fontNames)
{
foreach (XForm form in forms)
{
if (form.Resources.Fonts!=null && form.Resources.Fonts.Count != 0)
{
foreach (Font font in form.Resources.Fonts)
{
if (!fontNames.Contains(font.FontName))
fontNames.Add(font.FontName);
}
// recursive call
if (form.Resources.Forms.Count > 0)
ProcessXForms(form.Resources.Forms, fontNames);
}
}
}