Adding FontSettings Object to Document Corrupts Images

The fontsettings object on the document is null by default. This was causing all of my fonts in the document to be ignored. Setting the FontSettings object as such caused the images in my html to be squished on the document when they appear at the bottom of a page:

FontSettings fontSettings = new FontSettings();
fontSettings.setDefaultFontName(“Arial”);
doc.setFontSettings(fontSettings);

This seems to be the same issue as PDFJAVA-36147, but for the words platform instead.

The font issue was not present in words version 16.2.0, but the image squishing issue was still present. I am now on Words 16.11.0.
Hi Elaine,

Thanks for your inquiry. Could you please ZIP and attach your input Word document, output HTML file, related Font files and piece of code to reproduce this issue on our end? We will investigate the issue on our end and provide you more information.

Best regards,

Here is the html I am trying to convert and a class with the code used to convert it to a pdf. I am not sure what you want for Font files. The document should only have Arial and Times New Roman in it, which should be on any windows machine. What exactly do you mean by that?

Also as for the code, removing those three lines I had in the original post will cause the fonts in the whole document to change, despite the styling setting it to Arial or Times New Roman. It almost looks like it selects Papyrus or some other strange font.

Hi Elaine,


Please refer to the following sections of documentation:

How Aspose.Words Uses True Type Fonts
How to Specify True Type Fonts Location

Secondly, no images are visible in your html. Please ZIP and attach those images as well.

I have also generated two Pdf files (with and without those 3 problematic lines) from this Html using your code and attached them here for your reference.

I have also “Save As” your Html to Pdf format by using MS Word 2016 and attached it here for your reference. Please tell if the output produced by MS Word 2016 (msw-2016.pdf) is acceptable for you?

Best regards,

The images being not visible is completely fine; you could use any old image link and it will behave the same. If you look at the output, it still demonstrates the issue I described; the red X image in the version with the 3 lines is squished, and the font is that strange papyrus font style in the other document.

The word 2016 export is perfect. It even captures the additional image in the

  • tag. How would I be able to reproduce that with aspose?

    Thanks!
  • Hi Elaine,

    Thanks for your inquiry. For the sake of any correction, we have logged this problem in our issue tracking system as WORDSNET-14561. Our product team will further look into the details of this problem and we will keep you updated on the status of this issue. We apologize for your inconvenience.

    Best regards,

    Are there any updates on this or can I get an ETA as to when this will be resolved? Thanks.

    Hi Elaine,

    Thanks for your inquiry. Unfortunately, your issue is not resolved yet. We have asked the ETA of this issue from our product team and will update you as soon as any estimates are available. We apologize for your inconvenience.

    Best regards,

    We were really hoping for some sort of an update on the status by now. Is there any way to escalate an issue as a priority support subscriber? Thanks.

    Hi Elaine,

    Please always use your priority support account to post your critical issues in the priority support forum since only issues posted in the priority support forum are treated with that much priority. You can post a new thread in priority support forum if you want to raise priority of any of your existing issues.

    Regarding WORDSNET-14561, we have observed the following two issues with your document:

    1. The image at the bottom of the first page is located on the page margin and is cropped.

    The image is floating (Shape.WrapType = WrapType.None), because the corresponding element in the source HTML document is located inside an absolutely positioned . The paragraph that the image is anchored to is located at the very bottom of the first page so the image appears on the page margin and gets cropped. It is expected behavior for floating images. As a workaround, you could do any of the following:

    a) Make all images inline after import (Document Load).
    foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
    {
        shape.WrapType = WrapType.Inline;
    }

    Note that MS Word also makes all images of this document inline.

    b) Insert a page break to HTML just before the paragraph with the problematic image.

    This will force the anchor paragraph of the image to start at the top of the second page so the image won't be located at the page margin.

    Note also that Aspose.Words does actually import all three images. The first image, however, is not visible, because its parent has 'margin-left: 1108px', which shifts the image to the left by more than 11 inches. As a result, the image can only be seen if page width is big enough.

    Our product team has completed the work on this issue and has come to a conclusion that this is not a bug in Aspose.Words. So, this issue will be closed with 'Not a Bug' resolution.

    2. Text is exported to PDF in the Fanwood font.

    This looks like a bug in Aspose.Words for Java.

    Fanwood is the Aspose.Words' last resort font and the fact it is used in the resulting PDF document indicates that Aspose.Words has currently failed to enumerate fonts installed on the local machine. We didn't manage to reproduce this error with Aspose.Words for .NET but it is reproducible with Aspose.Words for Java on a Windows machine (tested on Windows 7).

    The error occurs in the following simple scenario:
    Document doc = new Document("in.html");
    doc.save("out.pdf");
    

    However, adding just a single line fixes the error:
    Document doc = new Document("in.html");
    doc.setFontSettings(new FontSettings());
    doc.save("out.pdf");
    

    Interestingly enough, in the following scenario fonts are incorrect either:
    LoadOptions loadOptions = new LoadOptions();
    loadOptions.setFontSettings(new FontSettings());
    Document doc = new Document("in.html", loadOptions);
    doc.save("out.pdf");
    

    Our product team will analyze this second issue further. We will keep you posted on any further updates. We apologize for any inconvenience.

    Best regards,

    Thanks for the clarification on the first issue we were having. It wasn’t apparent what was happening.

    As for the second issue, that fix in conjunction with setting wraptype seems to give us very close to the results we were looking for.

    Thanks!

    FYI to anyone else that has this issue, we found using this code helped preserve the layout of the page better than switching the images purely to inline:


    for(Object obj : document.getChildNodes(NodeType.SHAPE, true)) {
    Shape shape = (Shape) obj;
    if(shape.getWrapType() == WrapType.NONE) {
    shape.setWrapType(WrapType.TIGHT);
    shape.setAnchorLocked(false);
    shape.setAllowOverlap(false);
    }
    }

    Hi Elaine,


    Thanks for your feedback. Please let us know if you have any troubles and we will be glad to look into this further for you.

    Best regards,

    Hi Elaine,


    It is to update you that we are no longer able to reproduce this issue on our end when testing with latest version of Aspose.Words for Java 17.2.0. Please upgrade to the latest version:
    http://downloads.aspose.com/words/java

    Hope, this helps.

    Best regards,