Free Support Forum - aspose.com

DOCX to PDF conversion issue with image rendering using .NET | Chrome PDF viewer

Hi,

When converting a DOCX with a picture to PDF. I noticed the dotted lines in the picture is broken when opening the PDF from Chrome.

Code:

        var doc = new Document(@".\test.docx");
        doc.LayoutOptions.TextShaperFactory = HarfBuzzTextShaperFactory.Instance;
        doc.Save(@".\asposepdf.pdf");

The issue seems to only happen when opening the PDF from Chrome, it does not happen if I used Acrobat Reader.

Therefore, I initially suspected it is just a Chrome PDF viewer issue. However, when I converted the PDF manually by using ‘save as’ in Word, I noticed the dotted line in the Chrome PDF viewer was actually looking fine.

I’ve attached the test files and a screenshot for your reference. Could you please help to take a look?

test.zip (141.3 KB)
image.png (68.3 KB)

Thanks,

@ServerSide527

We have reproduced this issue at our end and logged it in our issue tracking system as WORDSNET-20749 . You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@ServerSide527

It is to inform you that your issue has been resolved and its fix will be available in next version of Aspose.Words i.e. 20.8.

By using Aspose.Words 20.8, you need to set the PdfSaveOptions.OptimizeOutput flag to get desired output.

The issues you have found earlier (filed as WORDSNET-20749) have been fixed in this Aspose.Words for .NET 20.8 update and this Aspose.Words for Java 20.8 update.

Hi,

I have today upgrade my Aspose.Words to its latest version and tested with the original test file and code. However, I saw the issue still exists.

Attached the new output (as you can see the PDF property it used Aspose.Words 20.9.0) and a screenshot on my Chrome application for your reference.

Test.pdf (38.5 KB)
image.png (60.7 KB)

Thanks,

@ServerSide527

We have tested the scenario using the latest version of Aspose.Words for .NET 20.9 and have not found the shared issue. Have you used the PdfSaveOptions.OptimizeOutput property as shown below? Please use this property to get the correct output.

var doc = new Document(MyDir + @"test (1).docx");
doc.LayoutOptions.TextShaperFactory = HarfBuzzTextShaperFactory.Instance;

PdfSaveOptions saveOptions = new PdfSaveOptions { OptimizeOutput = false };
saveOptions.OptimizeOutput = true;
doc.Save(MyDir + @"20.9.pdf", saveOptions);

@tahir.manzoor

Thanks for your update. I found the flag was not set properly on my previous tests. After applying the flag properly I could now see the output is correct.

Thanks again!

When I read the description of the new option. It suggested ‘The accuracy of the content display may be affected if setting to true’. Could you provide a bit more details on the risk of using this flag, what kind of accuracy would possibly be affected?

Thanks,

@ServerSide527

This flag indicates whether it is required to optimize output. If this flag is set redundant nested canvases and empty canvases are removed, also neighbor glyphs with the same formatting are concatenated.

Please note that the accuracy of the content display may be affected if this property is set to true.

@tahir.manzoor thanks for your reply.

I could see this comment when I used the code. Would it be possible to share a bit more info on what exactly the accuracy would be affected? Do we have an example of DOCX to PDF where turning on this flag could result in an inaccurate content display?

@ServerSide527

We are working over your query and will get back to you soon.

@ServerSide527

Currently there are to optimizations controlled by this flag. The first one is concatenation of neighboring glyphs. This may produce minor inaccuracies in glyph positioning in some viewer application. The second one is optimization of metafile vector graphics by removing redundant canvases, collapsing transformation and so on. This may produce minor differences with the unoptimized output related to peculiarities of vector graphics rendering in viewer application (like the one reported by you). From our experience optimized metafile graphics seems to be displayed more consistently in Adobe Reader (which we use as a reference viewer application).

Hope this clears the detail of OptimizeOutput property.

1 Like

Thanks for your additional info. I will take this as a reference.

@ServerSide527

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.