CDR to PDF conversion problem

Hi.

I’m trying to convert an Core draw file (.cdr) to PDF in my .NET 5 Web API application, but it’s not working correcly.

The file is converted but the PDF is generated with encoding problemas and some images are not loaded or loaded incorrecly

This is the .cdr file: SE Document PT.zip (5.0 MB)

This is the generated PDF in my application: 001000060 - 00 - SE Document PT.pdf (486.4 KB)

And this is the generated PDF in your website (Converter CDR para PDF Online) : SE+Document+PT.cdr.pdf (1.3 MB)

This is my source code:

    public override void Convert()
    {
        Console.WriteLine("Starting Image Converter");
        ConvertedFilePath = Path.ChangeExtension(OriginalFilePath, "pdf");

        try
        {
            using (var img = Aspose.Imaging.Image.Load(OriginalFilePath))
            {                    
                PdfOptions pdfOptions = new PdfOptions();
                pdfOptions.PdfCoreOptions = new Aspose.Imaging.FileFormats.Pdf.PdfCoreOptions();
                pdfOptions.UseOriginalImageResolution = false;

                //Não está funcionando conversão de arquivos .cdr para PDFA
                if (ConversionConfiguration.IsPDFA && !OriginalFilePath.ToLower().EndsWith(".cdr"))
                {
                    pdfOptions.PdfCoreOptions.PdfCompliance = PdfComplianceVersion.PdfA1a;
                }

                if (OriginalFilePath.ToLower().EndsWith(".cdr") && img is VectorImage)
                {
                    VectorRasterizationOptions rasterizationOptions = new CdrRasterizationOptions();
                    rasterizationOptions.PageWidth = img.Width;
                    rasterizationOptions.PageHeight = img.Height;
                    pdfOptions.VectorRasterizationOptions = rasterizationOptions;
                }

                img.AutoAdjustPalette = true;

                img.Save(ConvertedFilePath, pdfOptions);
            }
        }
        catch (Exception e) {
            Console.WriteLine("Image Converter failed: " + e.Message + " - StackTrace: " + e.StackTrace);
            throw e;
        }

        Console.WriteLine("Finishing Image Converter");

    }

In my logs I have this message: libpng warning: pHYs: CRC error

@jean.heidemann Please use version Aspose.Imaging 21.12.0, the result will be better, but not perfect either.
And in the new version the following part of the code is optional:

                   if (OriginalFilePath.ToLower().EndsWith(".cdr") && img is VectorImage)
                    {
                        VectorRasterizationOptions rasterizationOptions = new CdrRasterizationOptions();
                        rasterizationOptions.Positioning = PositioningTypes.DefinedByDocument;
                        pdfOptions.VectorRasterizationOptions = rasterizationOptions;
                    }

I have update my projectd the optional code and generated a new PDF, but the problem is the same.

@jean.heidemann you got a pdf like in my previous post?

No, i got this PDF: 001000060 - 00 - SE Document PT - Updated.pdf (486.4 KB)

@jean.heidemann Please write me what OS are you using?
A task has been created for the rest of the bugs.

I’m on Windows 10 Pro, running a .NET 5.0 Web API project with Docker

This is my dockerfile

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app

EXPOSE 6172
EXPOSE 6173

COPY . ./
RUN apt-get update && \
    apt-get install -y --allow-unauthenticated libgdiplus libc6-dev libpng-dev
RUN apt-get update && apt-get install -y curl
RUN apt-get update && apt-get install -y iputils-ping
RUN sed -i".bak" "s/$/ contrib/" /etc/apt/sources.list
RUN apt-get update && apt-get install -y ttf-mscorefonts-installer fontconfig

WORKDIR /usr
COPY Fonts/* /usr/share/fonts/

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

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SEPDFConverter.dll"]

@jean.heidemann Your application is running in docker under linux. Here you need to use libgdiplus ver >6 from mono.
My worked docker file:

FROM mcr.microsoft.com/dotnet/sdk:5.0-focal
WORKDIR /app

# begin install libgdiplus and dependencies
RUN apt-get update \
    && apt-get install -y \
        apt-transport-https \
        dirmngr \
        gnupg \
        ca-certificates

RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
    && echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" >> /etc/apt/sources.list.d/mono-official-stable.list

    
RUN apt-get update && apt-get install -y libgdiplus libc6-dev libx11-dev libfontconfig1 xfonts-utils


RUN DEBIAN_FRONTEND=noninteractive apt-get install -y ttf-mscorefonts-installer
# end ttf-mscorefonts-installer

COPY . .
ENTRYPOINT ["dotnet", "run", "Debug.csproj"]

I changed my dockerfile but got conversion error:

image.png (7.7 KB)

Here is my new dockerfile:

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app

EXPOSE 6172
EXPOSE 6173

COPY . ./



FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build

# begin install libgdiplus and dependencies
RUN apt-get update \
    && apt-get install -y \
        apt-transport-https \
        dirmngr \
        gnupg \
        ca-certificates
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
    && echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" >> /etc/apt/sources.list.d/mono-official-stable.list
RUN apt-get update && apt-get install -y libgdiplus libc6-dev libx11-dev libfontconfig1 xfonts-utils



RUN apt-get update && apt-get install -y curl
RUN apt-get update && apt-get install -y iputils-ping
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y ttf-mscorefonts-installer

WORKDIR /usr
COPY Fonts/* /usr/share/fonts/

WORKDIR /src
COPY ["SEPDFConverter/SEPDFConverter.csproj", "SEPDFConverter/"]
RUN dotnet restore "SEPDFConverter/SEPDFConverter.csproj"
COPY . .
WORKDIR "/src/SEPDFConverter"
RUN dotnet build "SEPDFConverter.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SEPDFConverter.dll"]

@jean.heidemann, Please see my worked example Example.zip (5.0 MB)

The issues you have found earlier (filed as IMAGINGNET-5096) have been fixed in this update. This message was posted using Bugs notification tool by samer.el-khatib4aspose