We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Exception when converting XFA Dynamic form to Standard On Linux

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);

            }

        }

    }

@PeteLee

Thanks for contacting support.

We were able to replicate the issue in our environment as shown in attached screenshot NETCoreExceptionn.png (162.9 KB). We have logged this issue as PDFNET-45722 in our issue tracking system for the sake of detailed investigation. We will look into details of the issue and keep you posted with the status of its resolution. Please be patient and spare us little time.

We are sorry for the inconvenience.

The issues you have found earlier (filed as PDFNET-45722) have been fixed in Aspose.PDF for .NET 19.7.

@PeteLee

While using latest release of the API, please also try installing msttcorefonts in your system and use following code snippet:

Aspose.Pdf.Text.FontRepository.Sources.Clear();
Aspose.Pdf.Text.FontRepository.Sources.Add(new FolderFontSource(@"/usr/share/fonts/truetype/msttcorefonts/"));