Word SaveAsPDF Images missing

Posted by: m.mitchell on 13 July 2021, 2:01 am EST

    • Post Options:
    • Link

    Posted 13 July 2021, 2:01 am EST

    Hello,

    when i have da wordDocument (2007) with an image and i use the follwing Code:

    GcWordDocument.SetLicenseKey(licenseKeyWord);

    try

    {

    var wordDoc = new GcWordDocument();

    wordDoc.Load(WordDoc);

    using (var layout = new GcWordLayout(wordDoc))

    {

    PdfOutputSettings pdfo = new PdfOutputSettings();

    pdfo.CompressionLevel = CompressionLevel.Fastest;

    // save the whole document as PDF

    layout.SaveAsPdf(PDFDoc, null, pdfo);

    }

    return PDFDoc;

    }

    catch (Exception ex)

    {

    MessageBox.Show(“Error:” + ex.InnerException);

    return “”;

    throw;

    }

    everthing is fine in VS2017.

    Within my Application the Image (JPEG) ist missing and instead there is a Red Cross.

    What is missing?

    I am using the latest Version of Document for Words and Document for PDF (Vers. 4)

    Mike MItchell

  • Posted 13 July 2021, 4:40 pm EST

    Hello Mike,

    Sorry, we do not face the issue at our end. Can you please share the word file that is having the issue at your end so that we can investigate it further?

    Regards,

    Prabhat Sharma.

  • Posted 13 July 2021, 5:34 pm EST

    Documents.zip

    Included are 3 Files:

    1 Worddocument

    2 PDFFile out of Visual Studio 2017 (incl. the Image)

    3 PDFFile out of My Windows Forms Application (RedCross istead of Image)

  • Posted 13 July 2021, 11:23 pm EST

    I solved the Problem.

    In my Windows.Forms.App I had to change the config File and add the following Text:















































    Thanks for Your Help.

    Regards

    Mike Mitchell

  • Posted 14 July 2021, 8:26 pm EST

    Hello Mike,

    It is good to hear that the issue has been resolved at your end.

    If you need any other help, please feel free to ask.

    Regards,

    Prabhat Sharma.

  • Posted 20 July 2023, 5:40 am EST

    Hi Prabhat,

    We are facing the same issue, can you please let us know what was done to resolve this issue. It is kind of urgent.

    Kind Regards,

    Abdul

  • Posted 20 July 2023, 3:13 pm EST

    Hello Abdul,

    We do not face the issue at our end.

    Please find the attached sample implementing the same and share your docx file with which you are getting this issue.

    Regards,

    Prabhat Sharma.

    docxtoPdf.zip

  • Posted 20 July 2023, 11:08 pm EST

    Hi Prabhat,

    Are you running this sample locally or is it deployed on the server or in cloud? The reason being, it does work when we run the application locally but when it is deployed to Azure as an app service it is not working.

    Kind Regards,

    Abdul

  • Posted 21 July 2023, 12:08 am EST

    Hi Mitchell,

    Would you be so kind to let me know what configuration changes you made to resolve the issue? We are struggling with the same issue when we deploy the application to either a Windows server or an App Service in Azure.

    Kind Regards,

    Abdul

  • Posted 23 July 2023, 7:10 pm EST

    Hello,

    we solved this problem by adding some entries in the config file of our app.

    But recently the problem turned out to happen again. Just like yours.

    The lines we added were: (be sure to use the correct versions, this was 2021)















































  • Posted 23 July 2023, 7:11 pm EST

    Hello,

    we solved this problem by adding some entries in the config file of our app.

    But recently the problem turned out to happen again. Just like yours.

    
    The lines we added were: (be sure to use the correct versions, this was 2021)
           <dependentAssembly>
            <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="DocumentFormat.OpenXml" publicKeyToken="8fb06cb64d019a17" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.16.0.0" newVersion="2.16.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="BouncyCastle.Crypto" publicKeyToken="0e99375e54769942" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-1.8.10.0" newVersion="1.8.10.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
          </dependentAssembly>

  • Posted 24 July 2023, 4:15 am EST

    Hi Mitchell,

    After adding these config entries issue fixed and now we can see images in the PDF. But it works for only 3 images if i have more than 3 image i get blank page do you happen to get the same issue.?

  • Posted 24 July 2023, 4:17 am EST

    Hi Prabhat,

    It works up to 3 images if i have more than 3 image i get blank page .Is there any limitation on how many images we can add or is there any config we need to set to allow more images ?

    Regards,

    Anil

  • Posted 24 July 2023, 10:03 pm EST

    Hi Anil,

    It seems like you have created a duplicate case. We already responded here: CAS-42182-D2K7R7(https://www.grapecity.com/my-account/my-support/case/18eb7c24-442a-ee11-bdf4-000d3a574715)

    We will continue to the above Support case.

    Regards,

    Nitin

  • Posted 25 July 2023, 9:15 pm EST

    Hi Nitin,

    I too am having the red box issue on certain images when running:

    GcWordLayout.SaveAsPdf()

    The response to the case posted in your reply above does not seem to exist:

    CAS-42182-D2K7R7(https://www.grapecity.com/my-account/my-support/case/18eb7c24-442a-ee11-bdf4-000d3a574715)

    Could you please provide a solution for this issue?

    Kind regards,

    Brett

  • Posted 25 July 2023, 9:50 pm EST

    Hi Brett,

    Apologize for any inconvenience.

    We replicated this issue in the .Net Web API application. If you are using any other technology then please let us know.

    However, in order to resolve this red mark issue by adding the below dependencies to your Web.config file as suggested by Mitchell.

        <dependentAssembly>
            <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
          </dependentAssembly>

    Please refer the attached working sample:WordToPdf.zip

    Also, Anil is facing an issue after that. He is not able to load 3+ images on generated pdf. This issue is under investigation. [Internal Tracking Id - DOC-5622]

    Best Regards,

    Nitin

  • Posted 25 July 2023, 11:14 pm EST - Updated 26 July 2023, 5:43 pm EST

    Hi Nitin,

    Thank you for your prompt reply.

    We are using GrapeCity in an ASP .Net Core Web App (.Net 7). I have added the assembly redirects to my Web.config as follows:

    <?xml version="1.0" encoding="utf-8"?>
    
    <configuration>
        <system.web>
            <compilation debug="true"  />
            <httpRuntime  />
        </system.web>
        <appSettings>        
        </appSettings>
        <runtime>
            <assemblyBinding>
                <dependentAssembly>
                    <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
                </dependentAssembly>
                <dependentAssembly>
                    <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
                </dependentAssembly>
                <dependentAssembly>
                    <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
                </dependentAssembly>
                <dependentAssembly>
                    <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                    <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
                </dependentAssembly>
            </assemblyBinding>
        </runtime>
    </configuration>

    Which still does not work.

    Since we are using .Net 7, Mitchell’s solution is not entirely necessary. I am under the impression that assembly loading in .Net Core would fix this issue:

    “.NET Core’s simplified assembly loading means it just works.” - https://nickcraver.com/blog/2020/02/11/binding-redirects/

    Additionally, I have also tried adding:

    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

    Which still does not work.

    Please do let me know if this issue is also persistent in newer versions of .Net and if so, is there a solution?

    Sincerely,

    Brett

  • Posted 26 July 2023, 7:06 pm EST

    Hi Nitin,

    Please see my attached console app highlighting the issue:

    GCImageIssue.zip

    Additionally, I thought that the issue may be caused by the conformance level of the PDF, which may not support transparency on images (https://apryse.com/blog/pdfa-format/what-are-the-different-types-of-pdfa#:~:text=In%20addition%2C%20while%20supported%20in%20PDF%201.4%2C%20transparency%20was%20considered%20just%20“too%20new”%20at%20the%20time%20of%20PDF/A-1’s%20inception%20and%20therefore%20not%20included.).

    But increasing the conformance level on the PdfOutputSettings still did not solve the problem.

    Sincerely,

    Brett

  • Posted 26 July 2023, 8:48 pm EST

    Hi,

    a little Update.

    I noticed missing Images in SaveToPDF when using Word Documents in DOCX Format.

    I then realized, that my DOCX Documents where all in Word DOCX Compatibility Mode.

    After saving them in “non compatibility Mode”, SaveToPDF exportet my DOCX Document with all the Images. Maybe you got the same issues, and maybe GrapeCity could look this up, either trough Message “Compatibility Mode not supported” or by fixing the issue.

    Best

    M.Mitchell

  • Posted 26 July 2023, 10:47 pm EST

    Hi Brett.

    We are unable to replicate this red mark issue in ASP .Net Core Web App(.Net7).

    This issue occurs on ASP .Net Web API. And we can resolve this issue by adding dependencies on Web.config file.

    But this issue is not replicable on ASP .Net Core Web App(.Net7). Please refer the attached working sample: GcWord_net7.zip

    Also, please provide a small stripped sample replicating this behavior. Or you can update our sample to replicate this issue. So, that we can investigate and assist you accordingly.

    Best Regards,

    Nitin

  • Posted 26 July 2023, 10:50 pm EST

    Hi Nitin,

    Please see my sample provided here:

    https://www.grapecity.com/forums/documents-word/word-saveaspdf-images-missing#69208

    Kind regards,

    Brett

  • Posted 26 July 2023, 11:27 pm EST

    Hi Brett,

    Apologize for missing out the sample.

    We replicated this behavior at our end. We have escalated this issue to the development team. Will get back to you once they respond.[Intrenal Tracking Id- DOC-5634]

    Best Regards,

    Nitin

  • Posted 31 July 2023, 4:26 pm EST

    Hi Brett,

    As per the development team. The issue is EMF metafile, not a raster image. GcWordLayout cannot export metafiles. This is a limitation.

    Regards,

    Nitin.

Need extra support?

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

Learn More

Forum Channels