Word SaveAsPDF Images missing

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

    • Post Options:
    • Link

    Posted 13 July 2021, 11: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 14 July 2021, 1:40 am 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 14 July 2021, 2:34 am 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 14 July 2021, 8:23 am 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 15 July 2021, 5:26 am 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, 2:40 pm 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 21 July 2023, 12:13 am 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 21 July 2023, 8:08 am 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, 9: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 24 July 2023, 4:10 am 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 24 July 2023, 4:11 am 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, 1:15 pm 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, 1:17 pm 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 25 July 2023, 7:03 am 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 26 July 2023, 6:15 am 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 26 July 2023, 6:50 am 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 26 July 2023, 8:14 am EST - Updated 27 July 2023, 2:43 am 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 27 July 2023, 4:06 am 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 27 July 2023, 5:48 am 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 27 July 2023, 7:47 am 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 27 July 2023, 7:50 am 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 27 July 2023, 8:27 am 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 1 August 2023, 1:26 am 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