How to Image and fonts

  1. It seems Aspose words don’t work well with docx from office 365, I am wondering about the compatibility or how to fix this.

  2. It seems the fonts are different in word and pdf, any way to set the font and weight on the application running in ECS or tomcat, do I have to introduce the fonts into my application?

Thanks!

@merlin1234

  1. Could you please attach your input and output documents here for testing? We will check the issue and provide you more information.

  2. The problem might occur because the fonts used in the source document are not available in the environment where the document is rendered to PDF. If Aspose.Words cannot find the fonts used in the document the fonts are substituted . This might lead into the layout difference, since substitution fonts might have different font metrics… You can implement IWarningCallback to get a notification when font substitution is performed.
    Also, please attach the problematic input and output documents here for testing.

1 Like

Pls review bellow files, and kindly help with the defects(from docx to pdf). Thanks.
When I open the bellow docx in office 365 or mac, it looks good, bu not in office 2007.
After converting to pdf, from anywhere the pdf is much not the same as docx.
test updated.docx (112.0 KB)
test updated.pdf (105.2 KB)

@merlin1234
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-25053

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@alexey.noskov
Thanks for putting the issue into the working list. Just a little curious, doens’t the ticket number start with WORDSJAVA as i am studiing java aspose words?
Per my digging, when I set the text wrapper outside the logo image to “in line with text” on the page header, it shows the right layout, anyway I can do that in java codes?

@merlin1234 Yes, the problem occurs because Aspose.Words does not support floating shapes in header/footer t the moment (as well as MS Word 2007). This feature has been added into MS word in 2013 version. We are currently work on it.
You can make shape inline by setting ShapeBase.WrapType to WrapType.INLINE

Hi @alexey.noskov
Thanks! With your guidance, I have moved forward to the below and stuck just right before success. Could you share more about how to make the shape align correctly?
PDF


Code

Added more information:
When i set in line with text in offcie 365, the docx shows the same as above, but in offcie 2007, it shows correctly.Maybe this is a clue.
Docx in offcie 365

Docx in offcie 2007

@merlin1234 The shape in the original document has negative left shift:

But when you make the shape inline, it is positioned according to the indent of it’s parent paragraph. So it is required to adjust the parent paragraph indent to get the correct result:

Document doc = new Document("C:\\Temp\\in.docx");

Iterable<HeaderFooter> headerFooters = doc.getChildNodes(NodeType.HEADER_FOOTER, true);
for (HeaderFooter hf : headerFooters)
{
    Iterable<Shape> shapes = hf.getChildNodes(NodeType.SHAPE, true);
    for (Shape s : shapes)
    {
        if (s.isTopLevel())
        {
            s.setWrapType(WrapType.INLINE);
            Paragraph parent = s.getParentParagraph();
            double newIndent = parent.getParagraphFormat().getLeftIndent() + s.getLeft();
            parent.getParagraphFormat().setLeftIndent(newIndent);
        }
    }
}

doc.save("C:\\Temp\\out.docx");
doc.save("C:\\Temp\\out.pdf");

out.pdf (158.7 KB)

But please note the workaround will work only for this concrete document, when the shape is the only child of the paragraph.

Hi. @alexey.noskov
Really appreciate.
As we are pursuing a quick deployment, while we are waiting for the solid fix in your future release, we now want to make it work to all of our docx templates, so currently, the workaround is an acceptable way.

Could you also check with the below template for me? It seems WrapType.INLINE or not setting will miss some parts.
Original docx
22H-000014_RPT_updated.docx (1.6 MB)
Set WrapType.INLINE, no logo

Set WrapType.INLINE, no text “Test Report”

@merlin1234 The problem in this case occurs because there are 3 floating shapes in the same paragraph in the header and setting paragraph left margin shifts the shapes outside the page bounds. If use the following code and simply change the wrap type of the shapes, they are rendered:

Document doc = new Document("C:\\Temp\\in.docx");

Iterable<HeaderFooter> headerFooters = doc.getChildNodes(NodeType.HEADER_FOOTER, true);
for (HeaderFooter hf : headerFooters)
{
    Iterable<Shape> shapes = hf.getChildNodes(NodeType.SHAPE, true);
    for (Shape s : shapes)
    {
        if (s.isTopLevel())
        {
            s.setWrapType(WrapType.INLINE);
        }
    }
}

doc.save("C:\\Temp\\out.docx");
doc.save("C:\\Temp\\out.pdf");

But position is incorrect. I am afraid there is no programmatic workaround for this case. The only way to fix this is editing your template manually in MS Word and using table to place the shapes on the different sides of the page.

Hi, @alexey.noskov
Thanks.
That solution you suggests is the best we can get to, we decide to go with that path.
More suggestions I would like to hear from you are:

  1. Will the shape table feature be supported by this year?
  2. If I want to include a fonts folder, it has a large size(>500m) when I looked at C;/WINDWOS/FONTS/ , any suggestions if we can reduce the size or only use the ones that are necessary? We have multiple templates and still increasing, so it seems not a good way to overview every template and find the fonts it use.

@merlin1234

  1. The feature of MS Word 2013 text wrapping in the document header/footer is currently under development and till be fixed in 23.4 or 24.5 version of Aspose.Words (April-May 2023).

  2. Unfortunately, there is no way to guess what fonts will be required for rendering your documents. So you can implement IWarningCallback and collect warnings about font substitutions in your documents. Such way you can collect the information about the fonts used in your templates.

Hi,@alexey.noskov:
if we are using ECS to deploy our application, where Aspose is included , any better way to manage Fonts resources supposed we have a reasonable size folder(resource)?
Could it be a configured resource or just use a relative path, or we can mount a resource folder, as I found from API documentation FontSourceBase looks not widely support different resources based on the container(like ECS)…
Thanks very much.

@merlin1234 If you are limited with disk space, you can store the fonts remotely and load them as StreamFontSource. For example you can use StreamFontSource for fonts stored in S3 like described here:
https://docs.aspose.com/words/net/integration-in-aws-lambda/#how-to-use-fonts-stored-in-s3-storage-in-aws-lambda
The example is in C#, but the main idea is the same for Java. The same approach can be used for fonts from other external sources.

Also, when you work with external font sources, it would be useful to cache font search information. Please see the following article for more information:
https://docs.aspose.com/words/net/specifying-truetype-fonts-location/#save-and-load-a-font-search-cache

1 Like

The issues you have found earlier (filed as WORDSNET-25053) have been fixed in this Aspose.Words for Java 23.5 update.