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

Free Support Forum - aspose.com

Pdf to docx can not work with .net 5 on linux

The code is very simple just like

var doc = new Aspose.Pdf.Document(“Src.pdf”);
doc.Save(“PdfToWord.docx”, Aspose.Pdf.SaveFormat.DocX);

Aspose.PDF Version 21.6.0

When run it on Windows it work fine. But can not work on linux. It will throw the exception

System.NullReferenceException: Object reference not set to an instance of an object.
at #=zPkTNbxeIwcv6exf1AckV2ZhX22uK5NSowwSnQ2Bfb4Kt.#=zirFs86AmQaw4()
at #=zUCCFEnc8iGlSEATxRvUz6bS3T8kCOkty4$6DOWTMQJwWb9weOw==.#=z69HBvbY=(#=zyQ3ska1peMAZxGiBMvV6Y8ZK5DDZZiJNYdS8Vo3q0zit #=zHBTHnlY=, #=z5QJuHd8g$YZKXXM2p9$2us2LxAwai0zMLdp7uDtFO72f #=z4d_pjkNg9w$G, #=zHLWW2byG7BaesBhZQERbj4uC1Yt8UQfXXQ== #=zVtZ6FgQ=)
at #=z0LKTtCfNFYTWtiha0GmMxkUPrdTsfBI8Xd1bJPN34C5MHPpa2g==.#=z69HBvbY=(#=zyQ3ska1peMAZxGiBMvV6Y8ZK5DDZZiJNYdS8Vo3q0zit #=zHBTHnlY=, #=z5QJuHd8g$YZKXXM2p9$2us2LxAwai0zMLdp7uDtFO72f #=z4d_pjkNg9w$G)
at #=zN$DY_sU7KmBnCOkR54jzGEE8VMts5W9hTT_gQaWCLU7v.#=zfdTU7KC9YDOleo4JAA==(#=zyQ3ska1peMAZxGiBMvV6Y8ZK5DDZZiJNYdS8Vo3q0zit #=zHBTHnlY=, List1 #=zwSqq6xg=) at #=zN$DY_sU7KmBnCOkR54jzGEE8VMts5W9hTT_gQaWCLU7v.#=zArcThZ1f1HhuxnnOsA==(#=zyQ3ska1peMAZxGiBMvV6Y8ZK5DDZZiJNYdS8Vo3q0zit #=zHBTHnlY=, List1 #=zwSqq6xg=)
at #=zN$DY_sU7KmBnCOkR54jzGEE8VMts5W9hTT_gQaWCLU7v.#=zkp2a2QeqUizm(#=zyQ3ska1peMAZxGiBMvV6Y8ZK5DDZZiJNYdS8Vo3q0zit #=zHBTHnlY=, List1 #=zmZgkouzXdP1_) at #=zN$DY_sU7KmBnCOkR54jzGEE8VMts5W9hTT_gQaWCLU7v.#=zHZ5AnOA=(#=z_h1Wv4h23xAzL2sgniI4AlJFsctZ #=zc_iOmH8=, #=zxlvJK7zKQ1Tn3qiwnS026a9WymQ2Cmf$Wg== #=zpalOa4g=, #=zyQ3ska1peMAZxGiBMvV6Y8ZK5DDZZiJNYdS8Vo3q0zit #=zHBTHnlY=) at #=zDaz8qphh$2t0CQqSakemUK5YHxEh4T34FA==.#=z19FBKGc=(Int32 #=zRwoRLs0=, IList1 #=zNudW0kjGjhg5CJKBuA==, #=zdb4UuzUkuTXu #=zZzfThqg=)
at #=zDaz8qphh$2t0CQqSakemUK5YHxEh4T34FA==.#=zHZ5AnOA=()
at #=zYuYKmw7gBD501x_bTbZ_s0EK1fVT.#=zVQZzHXlwdtij(Document #=zc_iOmH8=, #=zyQ3ska1peMAZxGiBMvV6Y8ZK5DDZZiJNYdS8Vo3q0zit& #=zb4_fHHjRZ$0OSComhQ==, UnifiedSaveOptions #=zlAuGxFs=, Int32& #=ztKUtVntHhsBQ, Boolean #=zfbi22Dc=)
at #=zYuYKmw7gBD501x_bTbZ_s0EK1fVT.#=zdToBbpyZp7GR2$Rr7Q==(Document #=zqTZZn1yqGvJb, #=zyQ3ska1peMAZxGiBMvV6Y8ZK5DDZZiJNYdS8Vo3q0zit& #=zHBTHnlY=, UnifiedSaveOptions #=zlAuGxFs=, Int32& #=zzjk4gB0zUixI, Boolean #=zfbi22Dc=)
at #=zePjyCUNYU_Juf9pwuZOy3$I=.#=z_aT84OQ=(Document #=zc_iOmH8=, Stream #=zQBW_97IhtfNt, DocSaveOptions #=zlAuGxFs=)
at Aspose.Pdf.Document.#=zdCmLY4i$jbR3(Stream #=zQBW_97IhtfNt, SaveOptions #=zlAuGxFs=)
at Aspose.Pdf.Document.#=zdCmLY4i$jbR3(Stream #=zQBW_97IhtfNt, SaveFormat #=zg0GdhcE=)
at Aspose.Pdf.Document.#=zdCmLY4i$jbR3(String #=zem1EdgJO4zGp, SaveFormat #=zg0GdhcE=)
at Aspose.Pdf.Document.Save(String outputFileName, SaveFormat format)
at PdfToWordTest.Program.Main(String[] args) in /test/Program.cs:line 11

I have tried it on WSL2 with Ubuntu20 and Docker with mcr.microsoft.com/dotnet/sdk:5.0. It’s not work.

The sample code with pdf file is there
PdfToWordTest.zip (200.7 KB)

@christy8074

This seems an environment-specific issue. Could you please confirm if you have installed msttcorefonts and libgdiplus packages as well. Such issues usually occur if fonts are missing in the system. These fonts should be placed in “/usr/share/fonts/truetype/msttcorefonts” directory as Aspose.PDF for .NET scans this folder on Linux like operating systems. In case operating system has another default folder/directory for fonts, you should use the following line of code before performing any operation using Aspose.PDF.

Aspose.Pdf.Text.FontRepository.Sources.Add(new FolderFontSource("<user's path to ms fonts>"));

Thank you very much. I tested it. This exception is because there is no font. Maybe the library should throw some valuable exceptions. Then user can locate problem themselves and try fix some obvious mistakes.

@christy8074

We have already logged an enhancement request as PDFNET-50116 to implement proper exception in such cases. The ticket has been linked with this forum thread so that you will be notified as soon as it is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.