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

Free Support Forum - aspose.com

How to solve Aspose PDF generation issue in AWS Lambda

Hi Team,

I have used Aspose PDF API to generate PDF file. Below code is working fine in local environment. I am getting below error while generating PDF file from AWS environment.

Code:

Document doc = new Document();
Page page = doc.Pages.Add();
Aspose.Pdf.Table pdfHeaderTable = new Aspose.Pdf.Table();
page.Paragraphs.Add(pdfRecapSeasonHeaderTable);
doc.PageInfo.Width = 1800;
MemoryStream msReportPDF = new MemoryStream();
doc.Save(msReportPDF); // getting error here

Error Message:

[Error] API.Controllers.ReportController: at #=zzs9vGkvHtSmO4YPG008gvMq88QuR.#=z6LLdLJQ=(#=zFM29MJhyQPmqJgoU6qka1abtq4hl #=znGGrn01lb2pa)
at #=zWZJ5vhZv3c5dnfUO21p9wIE=.#=zGJQ$zEM=(#=zFM29MJhyQPmqJgoU6qka1abtq4hl #=znGGrn01lb2pa)
at #=q83NpF9vbA6eJ6gJaQav9pBAwYHibOsgW4ckA4FzQya0=.#=zN7HULMam9Ff3a6iaxOAPip9frtfFxlkMqSsjc9_uDCkG(Object #=zouhVpmI=)
at #=q83NpF9vbA6eJ6gJaQav9pBAwYHibOsgW4ckA4FzQya0=.#=zVX3QfpLyJ4U_5FstytzjI6iPUJ0PWMv_7gHy0FpNHJZ4(MethodBase #=zouhVpmI=, Boolean #=zfR0wXCg=)
at #=q83NpF9vbA6eJ6gJaQav9pBAwYHibOsgW4ckA4FzQya0=.#=zD4ad5j4Vf30qW8IoPJxMqDRGcE3f(#=q83NpF9vbA6eJ6gJaQav9pBAwYHibOsgW4ckA4FzQya0= #=zouhVpmI=, #=qRS04_XS2IOd4iTAlE7VaFPYnhPi8cn9Wi9Rm_r2KJbw= #=zfR0wXCg=)
at #=q83NpF9vbA6eJ6gJaQav9pBAwYHibOsgW4ckA4FzQya0=.#=zR3LHPE87Kl2vvRGdbrvCpGeIrYVLmTm6x9ryVPg=()
at #=q83NpF9vbA6eJ6gJaQav9pBAwYHibOsgW4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=ztNjUcZyQ9k0nZ0Ty2VCMAwnkNNU2ITGtkLHl9m0=(Boolean #=zouhVpmI=)
at #=q83NpF9vbA6eJ6gJaQav9pBAwYHibOsgW4ckA4FzQya0=.#=ztNjUcZyQ9k0nZ0Ty2VCMAwnkNNU2ITGtkLHl9m0=(Boolean #=zouhVpmI=)
at #=q83NpF9vbA6eJ6gJaQav9pBAwYHibOsgW4ckA4FzQya0=.#=zVHUg7Luib_Ye412KXQFmff6BHAxopSaobNiiVlA=()
at #=q83NpF9vbA6eJ6gJaQav9pBAwYHibOsgW4ckA4FzQya0=.#=zq$E0lBmYH4Q_Y2OIyKEYFLA=(Object[] #=zouhVpmI=, Type[] #=zfR0wXCg=, Type[] #=zYBo6frg=, Object[] #=zCpFY5R0=)
at #=q83NpF9vbA6eJ6gJaQav9pBAwYHibOsgW4ckA4FzQya0=.#=zu27hUU8yaiFolr$9s5Av6fpAcuNr6CI1wcN7X0Q=(Stream #=zouhVpmI=, String #=zfR0wXCg=, Object[] #=zYBo6frg=, Type[] #=zCpFY5R0=, Type[] #=zBBC3zOs=, Object[] #=zPfoKf38=)
at #=q83NpF9vbA6eJ6gJaQav9pBAwYHibOsgW4ckA4FzQya0=.#=zPxuq84wk6iIu1wdCpRLvQhE0OEuzGOBZSgoqccQ=(Stream #=zouhVpmI=, String #=zfR0wXCg=, Object[] #=zYBo6frg=)
at #=q83NpF9vbA6eJ6gJaQav9pBAwYHibOsgW4ckA4FzQya0=.#=ze35YgJCG7TdqLLcDxAlKeg2QMNbu0tQ8bQ==(Stream #=zouhVpmI=, String #=zfR0wXCg=, Object[] #=zYBo6frg=)
at Aspose.Pdf.Document.#=zmniJKg8KxzO4(Stream #=zx3TUUig=, SaveOptions #=zP2WvqAuwr1F5)
at Aspose.Pdf.Document.Save(Stream output)

Above error message is encrypted in AWS CloudWatch logs. Also I am getting font ‘Lucida Sans’ was not found issue. Please refer below code.

FontSource fs = new Aspose.Pdf.Text.FolderFontSource(@“D:\Fonts\dejavu”);
FontRepository.Sources.Add(fs);
TextState tinfo = new TextState();
tinfo.Font = FontRepository.FindFont(“Lucida Sans”); // getting font “Lucida Sans” was not found error

Please help me to resolve above mentioned issues.

@SenthilRG27

Would you kindly make sure that all Windows essential fonts are present/installed in the system where you are processing the PDF files. You can install or copy/paste the fonts in the targeted system and try again. In case issue still persists, please let us know.

@asad.ali,

We are getting error message in encrypted format in AWS CloudWatch logs. We are not able to understand the error message because the error message is in encrypted format. Is Aspose team implemented encryption concept for error message and if yes please explain above error message why PDF generation is failed?

@asad.ali

We have faced same issues in AWS Lambda when I tried to download Excel report by using Aspose Cells API. We have created a layer in AWS Lambda and configured fonts and solved “The type initializer for ‘Gdip’ threw an exception” in AWS environment. I have opened below threads in Aspose and StackOverflow forums to solve Excel download issue by using Aspose Cells API.

https://forum.aspose.com/t/system-dllnotfoundexception-unable-to-load-shared-library-libgdiplus-or-one-of-its-dependencies/216902/3

@SenthilRG27

The stack trace related to internal/protected components of the API is used to be encrypted usually. However, in case of non-Windows environment, we recommend installing all windows essential fonts and libgdiplus package in order to avoid errors. Please note that most of the errors in such environments caused by missing fonts.

Would you please share some more details about the environment where you are using the API e.g. OS Name and version.

It seems like you have sent a private message to other member of our team and you will be assisted accordingly. In case you need further assistance regarding Aspose.PDF, please let us know.

@asad.ali

I have resolved PDF generation issue in AWS Lambda by adding required .ttf file in the Lambda layer. Thank you for your support.

@asad.ali

Could you please provide font names list needs to be installed by default (FontRepository) in non Windows system?

@SenthilRG27

All windows essential fonts are needed to be installed in the environment. Usually, the list contains following fonts:

  • Andale Mono
  • Arial Unicode MS
  • Arial Black
  • Comic Sans MS
  • Courier New
  • Georgia
  • Impact
  • Times New Roman
  • Trebuchet MS
  • Verdana
  • Webdings

Please also note that different fonts may be required in some cases of the PDF generation and in case you face any issue while using the API, please let us know. We will investigate the scenario and address the issue accordingly.