Rotativa Pdf generation does not respect HTML character spacing
Asked Answered
D

1

5

I am converting from MVC HTML to Pdf using Rotativa. In HTML everything looks good, but in Pdf format, the characters spacing is not well formatted, as it is too little. This reduces the readability of the documents considerably.

In the following image is a string in HTML:

AND

and here is the same string generated with Rotativa:

enter image description here

I have tried to increase the character spacing from css, but when I changed it to 1px, on the HTML side everything looks even better, but in Pdf all the strings mess-up and gain a spacing more than 10px splitting along the divs and overlapping with each other.

I found that this could be one of the Rotativa issues, like in this one, which does not help me so much as it is solved only for Debian Sid operating system, and I am using Windows, and I have installed Rotativa 1.64 using Nuget.

Does anyone know a fix for letter spacing using Rotativa?

Dilworth answered 6/7, 2016 at 16:31 Comment(6)
Unfortunately, this sort of thing is very common . . . And it isn't at all peculiar to Rotativa.Jackfruit
@MikeRobinson do you know a fix or even a workaround for it?Dilworth
Unfortunately not. You should use whatever CSS type-spacing specifications you can come up with, and hope that the engine recognizes them and "does the right thing." You can also try a different engine. (Adobe's Acrobat product is very good, and priced accordingly ...) Sorry to be the bearer of bad news.Jackfruit
I still hope it can be solved without changing the actual engine, as it works better than all the other based on itextsharp that I have tried. I have seen that the guys that build it themselves from the github succeded to solve this issue with a little of modifications, but this was not on Windows, and it's pretty unclear to me what the solve was.Dilworth
GitHub forums, and maybe direct messages sent to GitHub users, might put you into contact with other Windows users who have satisfactorily solved your common problem. Maybe one of them's even got an executable . . .Jackfruit
It seems this answer helps even with rotativa: https://mcmap.net/q/1175631/-html-to-pdf-with-wicked-pdf-and-letter-spacing-issuesGradey
D
5

I have solved this issue after i changed the font-family with one imported from google. The idea came to me after I have read this article in which is described how changing font-family with a given one by url solved a wkhtmltopdf similar problem.

The code I have used to fix this is the following:

@import url('https://fonts.googleapis.com/css?family=Open+Sans');
body {
    font-family: "Open Sans";
}
Dilworth answered 7/7, 2016 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.