Error PDF to Docx - c# NET core

API .Net Core 3.1 - Docker

Trying PDF to Docx:


// Aspose Pdf document to save into word
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(memoryStreamPDFFile);

// output Memorystream
MemoryStream outputMs = new MemoryStream();

// memorystream PDF to WORD
pdfDocument.Save(outputMs, Aspose.Pdf.SaveFormat.DocX);

byte[] b = outputMs.ToArray();

return b;

Exception:

Error:
Value cannot be null. (Parameter ‘key’)

Inner Exception:

at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)

at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)

at #=zNawrcDrnSEee$MjqH3JyuoW2OWHiXby$QA==.#=zMuYqLfU=(#=zgBaXOuo= #=zhGxDZT0=)

at #=z9DiL2QZ0kYIGZ6COT76ebT4DMLjzSWV4hA==.#=zQXXu9OUp_drb`2.#=zTfhZsfm9_Vwt(#=zgBaXOuo= #=zhGxDZT0=, #=zBHP90$U=& #=zK0PB78E=)

at #=zhfFzHyoLjgGM8gSKVriSUTIGGhpcJUm6FHOAbkE=.#=z0tiU5y52MDry(#=zVFJ2an3uzvnf8npQrQteGbcskn8L #=zuMWPc9wntIxQ)

at #=zvaP52qSylGBC3Nbwnn5COmPUpR4wbn0Nubpw$AL_dBZb.#=zFEBNoM_QlKIt()

at #=zvaP52qSylGBC3Nbwnn5COmPUpR4wbn0Nubpw$AL_dBZb.#=zt8HR8rY=()

at #=zQ1QRfnYGY_Cf6TD93PUWH$ywpSJCHHAX6VHK60NvO0CI.#=ztFDpuUo=(#=zLddFn9Q2DICjd859gbl8nwmP8mvQ #=zWSWMwpI=, #=zELMwkqufAmt6AlqpGYl3U96Ze5J8rVt7VQ== #=zrKM3PGU=, #=zIiLJFlmpyWhFpRxTGDlVzgjD$q0YZ_iIoFA_ygw1OswO #=zm3eKfM0=)

at #=zHE0hpllHKmxdg7IfhSSuNVtcFIS0wmiEBg==.#=z9eyn$ls=(Int32 #=zVB1rgdk=, IList`1 #=ztUv4fQKA$K5gWEGxgg==, #=zgu2311$AmpO2 #=zMcH9ap0=)

at #=zHE0hpllHKmxdg7IfhSSuNVtcFIS0wmiEBg==.#=ztFDpuUo=()

at #=zIQshx$k1WL1J5YDCvS_Lkwn0kV4e.#=zvR9KMq4aEDHn(Document #=zWSWMwpI=, #=zIiLJFlmpyWhFpRxTGDlVzgjD$q0YZ_iIoFA_ygw1OswO& #=zrpHMiH8dF7sWN4Ojkg==, UnifiedSaveOptions #=z48c_1lM=, Int32& #=z4CoMxxO3EEJD, Boolean #=zxe8hevM=)

at #=zIQshx$k1WL1J5YDCvS_Lkwn0kV4e.#=zLu0vit7_hyx5s4K_Kg==(Document #=zEf3DAEXah6Y7, #=zIiLJFlmpyWhFpRxTGDlVzgjD$q0YZ_iIoFA_ygw1OswO& #=zm3eKfM0=, UnifiedSaveOptions #=z48c_1lM=, Int32& #=zdrvoQ9Lw2IfX, Boolean #=zxe8hevM=)

at #=zBPyAG7Fx6bTHkkHdmJHwVng=.#=zmuvS0so=(Document #=zWSWMwpI=, Stream #=zzLWoftMiV2$R, DocSaveOptions #=z48c_1lM=)

at Aspose.Pdf.Document.#=zxUcMrARBMU09(Stream #=zzLWoftMiV2$R, SaveOptions #=z48c_1lM=)

at Aspose.Pdf.Document.#=zxUcMrARBMU09(Stream #=zzLWoftMiV2$R, SaveFormat #=zP07Vl5E=)

at Aspose.Pdf.Document.Save(Stream outputStream, SaveFormat format)

at EAVM.Report.BLL.ReportService.GetWORDFromPDF(MemoryStream memoryStreamPDFFile) in C:_work\Projects\EAVM_MSA\EAVM.Report\EAVM.Report\BLL\ReportService.cs:line 338


Any idea??

@alejandroaspose

It seems to be an issue with PDF file while saving to Docx. Can you please share the source file reproducing the issue on your end.

Hello, thank you for your quick reponse.

Here is the pdf I am trying to transform into docx:

report_futuro.pdf (930.9 KB)

(There is no problem using ASPOSE Online PDF converter.)

Thanks and regards

@alejandroaspose

I can not reproduce the issue with latest version of API. I request you to upgrade and share your feedback.

It seems an error when linux dockerizing.
Here are my steps when converting from PDF to WORD to get the error:

  1. Create a .NET Core 3.1 console application with Visual Studio 2019

  2. Add Nuget package “Aspose.PDF” version 21.7.0

  3. In the project´s root place my file “report_futuro.pdf”

  4. In Visual Studio, in the project, go to this file + Properties, Advanced / Copy to output directory = Copy always

  5. Change Program.cs
    from:

     using System;
    
     namespace ASPOSEConsole
     {
         class Program
         {
             static void Main(string[] args)
             {
                 Console.WriteLine("Hello World!");
             }
         }
     }
    

To:

using Aspose.Pdf;
using System;

namespace ASPOSEConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Starting conversion");

                // For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
                // Open the source PDF document
                Document pdfDocument = new Document("report_futuro.pdf");

                // Instantiate DocSaveOptions object
                DocSaveOptions saveOptions = new DocSaveOptions
                {
                    // Specify the output format as DOCX
                    Format = DocSaveOptions.DocFormat.DocX
                    // Set other DocSaveOptions params
                    // ....
                };
                // Save document in docx format
                pdfDocument.Save("ConvertToDOCX_out.docx", saveOptions);

                Console.WriteLine("Finalizing conversion");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

IT WORKS!!! Leaves a ConvertToDOCX_out.docx on C:_work\Projects\ASPOSEConsole\bin\Debug\netcoreapp3.1 and has same design.

  1. Now on project: Add docker Support LINUX

  2. Here is the docker file:

#See Customize Docker containers in Visual Studio - Visual Studio (Windows) | Microsoft Learn to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/runtime:3.1 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["ASPOSEConsole.csproj", "."]
RUN dotnet restore "./ASPOSEConsole.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "ASPOSEConsole.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ASPOSEConsole.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ASPOSEConsole.dll"]
  1. Execute Docker_Desktop installed in my computer

  2. Debug Docker

  3. It runs the container on Docker Desktop:

image.png (14.0 KB)

  1. But an exception occurs:
    image.png (64.3 KB)

error.message =

Value cannot be null. (Parameter ‘key’)

e.StackTrace =

at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at System.Collections.Generic.Dictionary2.TryGetValue(TKey key, TValue& value)
at #=zNawrcDrnSEee$MjqH3JyuoW2OWHiXby$QA==.#=zMuYqLfU=(#=zgBaXOuo= #=zhGxDZT0=)
at #=z9DiL2QZ0kYIGZ6COT76ebT4DMLjzSWV4hA==.#=zQXXu9OUp_drb2.#=zTfhZsfm9_Vwt(#=zgBaXOuo= #=zhGxDZT0=, #=zBHP90$U=& #=zK0PB78E=) at #=zhfFzHyoLjgGM8gSKVriSUTIGGhpcJUm6FHOAbkE=.#=z0tiU5y52MDry(#=zVFJ2an3uzvnf8npQrQteGbcskn8L #=zuMWPc9wntIxQ) at #=zvaP52qSylGBC3Nbwnn5COmPUpR4wbn0Nubpw$AL_dBZb.#=zFEBNoM_QlKIt() at #=zvaP52qSylGBC3Nbwnn5COmPUpR4wbn0Nubpw$AL_dBZb.#=zt8HR8rY=() at #=zQ1QRfnYGY_Cf6TD93PUWH$ywpSJCHHAX6VHK60NvO0CI.#=ztFDpuUo=(#=zLddFn9Q2DICjd859gbl8nwmP8mvQ #=zWSWMwpI=, #=zELMwkqufAmt6AlqpGYl3U96Ze5J8rVt7VQ== #=zrKM3PGU=, #=zIiLJFlmpyWhFpRxTGDlVzgjD$q0YZ_iIoFA_ygw1OswO #=zm3eKfM0=) at #=zHE0hpllHKmxdg7IfhSSuNVtcFIS0wmiEBg==.#=z9eyn$ls=(Int32 #=zVB1rgdk=, IList1 #=ztUv4fQKA$K5gWEGxgg==, #=zgu2311$AmpO2 #=zMcH9ap0=)
at #=zHE0hpllHKmxdg7IfhSSuNVtcFIS0wmiEBg==.#=ztFDpuUo=()
at #=zIQshx$k1WL1J5YDCvS_Lkwn0kV4e.#=zvR9KMq4aEDHn(Document #=zWSWMwpI=, #=zIiLJFlmpyWhFpRxTGDlVzgjD$q0YZ_iIoFA_ygw1OswO& #=zrpHMiH8dF7sWN4Ojkg==, UnifiedSaveOptions #=z48c_1lM=, Int32& #=z4CoMxxO3EEJD, Boolean #=zxe8hevM=)
at #=zIQshx$k1WL1J5YDCvS_Lkwn0kV4e.#=zLu0vit7_hyx5s4K_Kg==(Document #=zEf3DAEXah6Y7, #=zIiLJFlmpyWhFpRxTGDlVzgjD$q0YZ_iIoFA_ygw1OswO& #=zm3eKfM0=, UnifiedSaveOptions #=z48c_1lM=, Int32& #=zdrvoQ9Lw2IfX, Boolean #=zxe8hevM=)
at #=zBPyAG7Fx6bTHkkHdmJHwVng=.#=zmuvS0so=(Document #=zWSWMwpI=, Stream #=zzLWoftMiV2$R, DocSaveOptions #=z48c_1lM=)
at Aspose.Pdf.Document.#=zxUcMrARBMU09(Stream #=zzLWoftMiV2$R, SaveOptions #=z48c_1lM=)
at Aspose.Pdf.Document.#=zxUcMrARBMU09(String #=zzPdnIPDxw5oo, SaveOptions #=z48c_1lM=)
at Aspose.Pdf.Document.Save(String outputFileName, SaveOptions options)
at ASPOSEConsole.Program.Main(String[] args) in C:_work\Projects\ASPOSEConsole\Program.cs:line 27

Could you please help me? Do you have an example of a linux docker for that?

I have also installed some additional packages for Linux native assets:
image.png (7.8 KB)
But same error occurs.

@alejandroaspose

We need to further investigate the issue in details from perspective of Docker environment. For the purpose, an investigation ticket as PDFNET-50271 has been logged in our issue tracking system. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

Thank you for your quick reponse.

Just to let you know I have tried several images in the DockerFile:

FROM mcr.microsoft.com/dotnet/runtime:3.1 AS base
FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build

Debian 10
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS bas
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build

Ubuntu 18.04
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic AS base
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic AS build

Alpine 3.1
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine AS base
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build

You can find them here: https://hub.docker.com/_/microsoft-dotnet-aspnet

You may find this documentation useful: https://marcroussy.com/2020/05/01/docker-build-process-for-dotnet/

But still getting the same error.

Regards

@alejandroaspose

We have noted your comments and will surely inform you as soon as the logged ticket is resolved.

Adding some libraries over an Ubuntu 18.04 image on docker file:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic AS base

RUN apt-get update
RUN apt-get install -y libgdiplus libc6-dev  
RUN ln -s libgdiplus.so gdiplus.dll
RUN apt-get install -y libicu-dev libharfbuzz0b libfontconfig1 libfreetype6  
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections
RUN apt-get install ttf-mscorefonts-installer --yes --quiet --quiet
RUN apt-get install fonts-liberation 

Removes the error but a memory capacity issue is displayed.

Hope it helps,

Thanks in advance,

@alejandroaspose

I request you to share some more details about the memory capacity issue.

Hi all,

Here is the new error I am facing after adding libraries above:

image.jpg (197.0 KB)

Hope it helps,

Thanks in advance.

@alejandroaspose

We have recorded your feedback and will let you know as soon as the logged ticket is resolved.