Rendering PageDocument in Linux Problem

Posted by: rafael.mandler on 26 February 2021, 8:54 pm EST

    • Post Options:
    • Link

    Posted 26 February 2021, 8:54 pm EST

    Hi,

    I’m using this method to render a PageDocument (from an already set up RDLX file with parameters and/or datasets) in a Linux Docker container:

    	pageReport.Document.Render(pdfRenderingExtension, outputProvider, pdfSetting);
    

    This came from an example here: https://www.grapecity.com/activereportsnet/docs/v15/online/rendering-to-pdf.html.

    This works fine when running locally on Windows. However, if I try to run in a Linux Docker container I get this error:

    An unexpected error occurred. Additional information: ‘TextFormat has no associated Font, and a default font could not be found. To avoid this situation, assign an available font to FontCollection.SystemFonts.DefaultFont if it is null.’

    I’m trying to generate the PDF as a response from a Web Api as well, and the response has this error:

    Could not load file or assembly ‘System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’. The system cannot find the file specified.

    Do I need to handle rendering in Linux differently? I found this other thread where perhaps we need to add some default fonts to the Docker container (https://www.grapecity.com/forums/documents-word/saveaspdf-problems). This has not yet worked for me, though.

  • Posted 1 March 2021, 12:17 am EST

    Hello,

    To fix such error you will need to put a font into container and register it as a default using this code:

    var customFonts = new GrapeCity.Documents.Text.FontCollection();
    customFonts.RegisterDirectory("/usr/share/fonts"); // specify right dir
    GrapeCity.Documents.Text.FontCollection.SystemFonts.AppendFallbackFonts(customFonts.ToArray());
    GrapeCity.Documents.Text.FontCollection.SystemFonts.DefaultFont = customFonts[0]; // 
    

    Thanks,

    Mohit

  • Posted 2 March 2021, 6:19 pm EST

    Thanks! Ultimately I didn’t have to add this code because I was able to include the fonts in the Docker container as such:

    RUN sed -i’.bak’ ‘s/$/ contrib/’ /etc/apt/sources.list

    RUN apt-get update; apt-get install -y ttf-mscorefonts-installer fontconfig

    This added the truetype fonts to the /usr/share/fonts directory in my container.

  • Posted 3 March 2021, 12:12 am EST

    Hello,

    I am glad that your issue is solved now.Please free to revert if you are facing any issue.

    Thanks,

    Mohit

  • Posted 3 March 2021, 9:30 pm EST

    Hi,

    I’m now having some difficulty with the licensing in a Docker container. Do I need to build/publish outside the container, or can I add the licensing tool to the container and handle everything there? Also, I’ve seen some notes about building with the license and then de-activating it after the build, i.e. if doing so from a build server. (https://www.grapecity.com/activereportsnet/docs/v15/online/licensing-with-pipelines.html) But do you need an active license while running the application as well, or just having built it?

    Here is a sample of 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/sdk:5.0-buster-slim AS base
    
    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
    EXPOSE 443
    
    FROM mcr.microsoft.com/dotnet/core/sdk:5.0-buster AS build
    WORKDIR /src
    COPY ["MyProject/MyProject.csproj", "MyProject/"]
    
    RUN dotnet tool install -g GrapeCity.LicenseManagerTool
    ENV PATH="$PATH:/root/.dotnet/tools"
    
    RUN gclm "AR15-PRODUCTID" -a "MY-PRODUCT-KEY"
    
    RUN dotnet restore "MyProject/MyProject.csproj"
    COPY . .
    WORKDIR "/src/MyProject"
    RUN dotnet build "MyProject.csproj" -c Release -o /app/build
    
    FROM build AS publish
    RUN dotnet publish "MyProject.csproj" -c Release -o /app/publish
    
    RUN gclm "AR15-PRODUCTID" -d "MY-PRODUCT-KEY"
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app/publish .
    ENTRYPOINT ["dotnet", "MyProject.dll"]
    
    
    

    Thanks again.

  • Posted 4 March 2021, 11:10 am EST

    Hello,

    Please follow the below steps to create build license in your application.

    1: Run cmd as administrator

    2: Switch to C:\ProgramData\GrapeCity\gclm folder

    3: gclm.exeproduct guid-lcoutput dir.gclicxentry assembly name.calling assembly name.dl

    4:Enter the following: gclm.exe “e88c1aa3-2781-44bb-b639-765c9ef6d15c” -lc ./.gclicx [assembly name].dll"

    5.Check that .gclicx file is generated in C:\ProgramData\GrapeCity\gclm folder.

    6. Open the project

    7. Add .gclicx file to the above project and make it embedded.

    Also, Please add the following line in the csproj file to disable the generating the license:



    True

    You need to do the step in your development machine. After that, you can build your application in the Docker Image without license issue.

    Hope it helps.

    Thanks,

    Mohit

  • Posted 26 March 2023, 1:42 am EST

    Hello,

    I also have a problem when I switched from windows to docker container linux. Here is my code and error:

    		using var htmlRenderer = new GcHtmlRenderer(html);
                    var pdfSettings = new PdfSettings
                    {
                        DefaultBackgroundColor = System.Drawing.Color.White,
                        FullPage = true,
                        WindowSize = new Size(1000, 0),
                    };
    
                    var memoryStream = new MemoryStream();
                    htmlRenderer.RenderToPdf(memoryStream, pdfSettings);
                    return memoryStream;

    Error:

    GcHtml is not supported on the current platform. System.NotSupportedException: GcHtml is not supported on the current platform.

    Thanks for any help!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels