Search code examples
c#pdf-generationexport-to-pdfcad

PDF Export not displaying white objects when called from EPLAN API


We have a batch utility program to generate a number of deliverables from a list of EPLAN Electric P8 archive files, including a PDF export. We are in the process of updating the EPLAN version from 2.7 to 2.9 and the PDF no longer exports correctly when called from the API. White objects do not show in the print. They still show correctly when called from within EPLAN (Page -> Export -> PDF...).

NOTE: We are required to export to pdf rather than print.

We have tried calling the export function through the Export object:

string projectPath = @"<PATH TO VALID .ell/.elk FILE>";
Eplan.EplApi.DataModel.Project testProject = TESTER_OpenProject(projectPath);
Eplan.EplApi.HEServices.Export export = new Eplan.EplApi.HEServices.Export(true);
export.PdfProject(testProject, string.Empty, $"$(DOC)\\{testProject.ProjectName}.pdf", Eplan.EplApi.HEServices.Export.DegreeOfColor.BlackAndWhite, false, "en_US", true);

Also through the Command Line Interpreter:

Eplan.EplApi.ApplicationFramework.ActionCallingContext pdfContext = new Eplan.EplApi.ApplicationFramework.ActionCallingContext();

pdfContext.AddParameter("type", "PDFPROJECTSCHEME");
pdfContext.AddParameter("projectname", <projectName>);
pdfContext.AddParameter("exportfile", <pdfFileName>);
pdfContext.AddParameter("blackwhite", "1");
pdfContext.AddParameter("exportscheme", "");
pdfContext.AddParameter("useprintmargins", "1");

Eplan.EplApi.ApplicationFramework.CommandLineInterpreter cmdLineItp = new Eplan.EplApi.ApplicationFramework.CommandLineInterpreter();
cmdLineItp.Execute("export", pdfContext);

And through the Action Manager:

Eplan.EplApi.ApplicationFramework.ActionCallingContext PDFContext = new Eplan.EplApi.ApplicationFramework.ActionCallingContext();
PDFContext.AddParameter("type", "PDFPROJECTSCHEME");
PDFContext.AddParameter("projectname", <projectName>);
PDFContext.AddParameter("exportfile", <pdfFileName>);
PDFContext.AddParameter("blackwhite", "1");
PDFContext.AddParameter("exportscheme", "");
PDFContext.AddParameter("useprintmargins", "1");
PDFContext.AddParameter("Language", "en_US");

Eplan.EplApi.ApplicationFramework.ActionManager actionManager = new Eplan.EplApi.ApplicationFramework.ActionManager();

Eplan.EplApi.ApplicationFramework.Action PDFExportAction = actionManager.FindAction("export");
PDFExportAction.Execute(PDFContext);

All 3 methods above generate the same result. The pdf doesn't show the objects with a white background.

Tests were performed on a stripped down EPLAN project with a single page consisting of a green square and a white square. The pdf generated from the export command in the menubar of EPLAN shows both squares while all of the above C# code generates a pdf showing only the green square.

Relevant Files: https://filetransfer.io/data-package/2fCt26V3#link

  1. PDF export generated from inside EPLAN.
  2. PDF export generated from the EPLAN API.
  3. EPLAN archive file of the minimal example used to generate the above PDF files.

Solution

  • From the discussions it appears the source template cannot be altered, but the output PDF can.

    Changing PDF colours can be a complex task, as often the colour is set and will thus be used for all objects after that setting, before another colour is assigned. So a solution for one file type may not suit another usage.

    On checking the file lines desired to be black have been placed after a white setting thus the simplest solution would be to set ALL Lines, whatever their colour to one colour. This can be very easily done using non-commercial Coherent cpdf.

    cpdf -blacklines in.pdf out.pdf
    

    However you need to beware that any grey or other colour lines, will also be converted to the new color (default black).

    The alternative in this case, is to convert all colour definitions of white to black and the danger with that is, a white background would also become black.

    Luckily the sample is based on a transparent non white background. So bulk targeting both whites 1 1 1 RG and 1 1 1 rg works for the sample given to allow (after decompression) convert to 0 0 0 RG and 0 0 0 rg.

    Thus AGPL Artifex MuTool can be used to DE-linearize the file for editing.
    Windows latest is 64bit only 32bit is 1.20.
    For all platform releases see https://mupdf.com/releases/index.html

    mutool clean -a -c -d -gggg EXPORT_FROM_API.pdf decompressed.pdf
    

    Note do not use "-sanitise" as it will remove some of the white definitions!

    Once the file is fit for edit, we can alter by find and replace. However, my attempts with PowerShell caused corruption so that will not work out well. However quirky Fart-It works well enough and only needs to know case insensitive string.

    Fart.exe -a -i -n decompressed.pdf "1 1 1 rg" "0 0 0 rg"
    

    Correct result.

    0 0 0 RG
    0 0 0 rg
    459.385 128.769 m
    780.155 128.769 l
    S
    780.155 481.616 m
    780.155 128.769 l
    S
    459.385 481.616 m
    780.155 481.616 l
    S
    459.385 481.616 m
    459.385 128.769 l
    S
    

    There are many "find and replace" tools to test on a more complex sample, but the key is the file must NOT change size, nor be differed in any other part of the file.

    Once you have tested that outcome in a real complex multicoloured case, it is then MuTool can again be used to RE-linearize.

    mutool clean -f -i -l -z decompressed.pdf whiteISblack.pdf
    

    enter image description here

    So to wrap that all up in a Windows programmed sequence.
    usage: W2B.cmd filename.pdf

    set "mutool=C:\path to\mupdf\1.20.0\mutool.exe"
    set "fart=C:\path to\fart.exe"
    
    del /q "%temp%\de-compressed.pdf"
    "%mutool%" clean -a -c -d -gggg "%~1" "%temp%\de-compressed.pdf"
    "%fart%" -a -i -n "%temp%\de-compressed.pdf"  "1 1 1 rg" "0 0 0 rg"
    "%mutool%" clean -f -i -l -z "%temp%\de-compressed.pdf" "%~dpn1-W2B.pdf"
    
    pause