Hello,
I am trying to edit pdf file via trial version of Aspose.Pdf to explore functionality for project needs. But it doesn’t want to run correctly and NullReferenceException occurs.
I’ve tried to use dockerfile from aspose official site (spoiler it doesn’t work for me):
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
RUN apt-get update && apt-get install -y libgdiplus
RUN sed -i'.bak' 's/$/ contrib/' /etc/apt/sources.list
RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig
WORKDIR "/app"
EXPOSE 80 82 84
ENV ASPNETCORE_URLS=http://+:80;http://+:82;http://+:84
COPY "./artifacts/app" "."
ENTRYPOINT ["dotnet", "SampleProject.dll"]
Now I am trying to experiment with additional libs (spoiler: sadly it doesn’t work too):
FROM mcr.microsoft.com/dotnet/aspnet:6.0
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
locales locales-all \
fontconfig \
libc6-dev \
libgdiplus \
ttf-mscorefonts-installer \
libx11-dev \
&& rm -rf /var/lib/apt/lists/* \
&& fc-cache -f -v
WORKDIR "/app"
EXPOSE 80 82 84
ENV ASPNETCORE_URLS=http://+:80;http://+:82;http://+:84
COPY "./artifacts/app" "."
ENTRYPOINT ["dotnet", "SampleProject.dll"]
When I try to create new pdf:
var d = new Document();
var p = d.Pages.Add();
p.Paragraphs.Add(new TextFragment("Hello World!"));
var ms = new MemoryStream();
d.Save(ms);
return ms.ToArray();
I got exception:
System.ArgumentNullException: Value cannot be null. (Parameter 'key')
at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
at #=zqn$fLDCyLGRr8pu2uUNDw91Cghzzuh4SOw==.#=z8B2_dYQ=(#=zVw4Kmpo= #=ze$nSJ1c=)
at #=zvP80FvsbIYWEjk4y0$u1K7fSruiME656xQ==.#=zSB_8WahestFL.#=zceHUMjm1p8Ka(#=zVw4Kmpo= #=ze$nSJ1c=, #=z_RXnnCY=& #=zj4PCPBc=)
at #=zSSCy0lmpQTJJyCEjUNDbboIErkV427mkgHFP1js=.#=zdUTbZ7WbCDyC(#=zfLB4U9tmn6cS3dbXTUNyCg6q51Xy #=zMiqcpTKMe$oL)
at #=zrB3Wryav4TRWIsccmCRA$5K0T8wj$8tvsFJk3X8f62G4.#=zUZNGbxn5pIEY()\n at #=zrB3Wryav4TRWIsccmCRA$5K0T8wj$8tvsFJk3X8f62G4.#=zyxshG1k=()
at #=zW5Xa4oeC9xkdrg53c7m_9ET9PbQ2U4fMlLwzl5UQCuB6.#=zEyZT$u4=(#=zoNYLGirF2GZ_26BfjxGA0yHDcIlX #=zaVZxQu0=, #=zJ7mqFOeX8tyl7GEYBXHhthL_dFsmFOSHOA== #=zugiTLEs=, #=z5wmixPgpid2CI$g7rMTfGvRodRnNvyTQCLJbq93Lh3sL #=zUdQiiDs=)
at Aspose.Pdf.Page.CalculateContentBBox()\n at Aspose.Pdf.Page.#=zdDezmno=(Page #=zugiTLEs=)
at Aspose.Pdf.Document.ProcessParagraphs()\n at Aspose.Pdf.Document.#=zfHSRt87og8RA(Stream #=zdOSrDSY=, SaveOptions #=zgp3uxjz$DQt5)
at Aspose.Pdf.Document.Save(Stream output)
If I try to open pdf and edit it:
await using var inputPdf = new MemoryStream(request.Pdf);
using var pdfDocument = new Document(inputPdf);
var page = pdfDocument.Pages[1];
page.PageInfo.Margin = new MarginInfo(10, 10, 10, 10);
await using var outputPdf = new MemoryStream();
pdfDocument.Save(outputPdf);
return outputPdf.ToArray();
I got this exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at #=z1NC5bGfOtG5Spahf93YivZn6$0GD.#=zVUCl61U=(#=zfLB4U9tmn6cS3dbXTUNyCg6q51Xy #=zMiqcpTKMe$oL)
at #=z5cKxuexnqDQ9RNwZ23esmHg=.#=zXXYY2sg=(#=zfLB4U9tmn6cS3dbXTUNyCg6q51Xy #=zMiqcpTKMe$oL)
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=z0PzUBkyvU_7nJn$0Ll2UExL0hUNP6BuZWpUh$po=(Object #=zN8L8sZ8=)
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=zR7S2UpSDvbHBXj8jqC6vNcRoLEag1quTlj7EYbg=(MethodBase #=zN8L8sZ8=, Boolean #=zvhFewtQ=)
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=z3v2khBATe2hlZ$0yWVYKHik=(#=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0= #=zN8L8sZ8=, #=q41WHVdZY0DOqLHlgkNSlGKXYqAqBI7PyEcC9rXx9BxM= #=zvhFewtQ=)
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=zrgv_EvFdDLuTSPmrurQq5D7Z4kRYLm0qLw==()
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=zSN9fxqikJMkRcO0m1d3eLN_G1KITEhhjgQ==(Boolean #=zN8L8sZ8=)
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=z0PzUBkyvU_7nJn$0Ll2UExL0hUNP6BuZWpUh$po=(Object #=zN8L8sZ8=)
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=z9T7L214txsC0PfsJdQwvKAV_OsMeuktmDOQjHM$gLHFi()
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=z4grFK9RgbVH87fBrzyiA8RGF5sKBw9z$4A==(#=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0= #=zN8L8sZ8=, #=q41WHVdZY0DOqLHlgkNSlGKXYqAqBI7PyEcC9rXx9BxM= #=zvhFewtQ=)
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=zrgv_EvFdDLuTSPmrurQq5D7Z4kRYLm0qLw==()
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=zSN9fxqikJMkRcO0m1d3eLN_G1KITEhhjgQ==(Boolean #=zN8L8sZ8=)
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=z0PzUBkyvU_7nJn$0Ll2UExL0hUNP6BuZWpUh$po=(Object #=zN8L8sZ8=)
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=z9T7L214txsC0PfsJdQwvKAV_OsMeuktmDOQjHM$gLHFi()
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=zwOSkuMu6iA_xoe9Wva_YfPY1uT07(Object #=zN8L8sZ8=, UInt32 #=zvhFewtQ=)
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=zSN9fxqikJMkRcO0m1d3eLN_G1KITEhhjgQ==(Boolean #=zN8L8sZ8=)
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=zSN9fxqikJMkRcO0m1d3eLN_G1KITEhhjgQ==(Boolean #=zN8L8sZ8=)
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=zy_lRdo2RWswSyYeeoCZXhLXi6YstPKBOm2KdKl4=(Object[] #=zN8L8sZ8=, Type[] #=zvhFewtQ=, Type[] #=z2kCS$PI=, Object[] #=zAPuDuog=)
at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=zZ7FoPd7sa6aOKR36srVv_JafqThBqPsXLw==(Stream #=zN8L8sZ8=, String #=zvhFewtQ=, Object[] #=z2kCS$PI=)\n at #=qbuqhvGzuec_0VaILCCKCpK9HKNen9454QCJx5O09gR0=.#=zDVjo1QWQXxwBunhL9pM8RD2gAGmWd2YDojWzbNs=(Stream #=zN8L8sZ8=, String #=zvhFewtQ=, Object[] #=z2kCS$PI=)
at Aspose.Pdf.Document.#=zfHSRt87og8RA(Stream #=zdOSrDSY=, SaveOptions #=zgp3uxjz$DQt5)
at Aspose.Pdf.Document.Save(Stream output)
I don’t know is problem depends on fonts or it’s trial version behavior or something else.
Please let me know how I can fix it. I would like to use licensed version but I have to test trial version before and should know that it will be work fine in linux docker containers.
P.S. It looks like this is the same problem as this thread