We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Centering images when generating PDF from HTML

Hi, I am generating a PDF from HTML and I have an image that has been vertically aligned at the top of the page using this code.

<img src="https://www.example.com" style="display: block; margin: 0 auto; max-width: 350px; text-align:center" />

The above code displays the image vertically aligned when viewed in a browser but when rendered as a PDF the image is left aligned.

Is there a workaround for this or specific CSS needed to keep the image vertically aligned?

Thank you,
We are using .NET Aspose.Pdf, Version


Thank you for contacting support.

Would you please share source and generated files as single ZIP archive along with narrowed down code snippet so that we may try to reproduce and investigate it in our environment.

Moreover, please note that support is provided based on latest available version and we always recommend using latest version because it includes more features and bug fixes. Therefore, please ensure using Aspose.PDF for .NET 19.1 before sharing requested data.

Furthermore, you may also visit Convert HTML to PDF for your kind reference.

We tried updating the the latest version but this broke a lot of things for us. However if we were able to come up with a fix.

If you put your <img> tab inside a center tag (<center></center>) then this will center the image for you. I know that the <center> tag is obsolete but it seems to work perfectly for this situation.

Hope this helps anyone who comes across this.


Thank you for your kind feedback.

We are glad to know that things started working in your environment. Please keep using our API and in event of any further query, feel free to ask.

A post was split to a new topic: Convert HTML to DOC using Aspose.Words - Problem with centering of the images