Hi, I’m looking at updating from Aspose.Words (2009.08.05) to the latest; However, when converting from html, I have an issue that “font-size: 9px;” used to convert to 6.5pt, now converts to 7pt when saved as Word. (Ultimately I’ll save as pdf but it was easier to see why my document layout changed going to Word as I could check the size).
Is there a default factor for converting px to pt that I can amend? It is quite important that the same source html files render exactly the same when moving to the new latest Aspose.Words.
This is the code I’m running:
Aspose.Words.Document doc = new Aspose.Words.Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.PageSetup.PaperSize = PaperSize.A4;
builder.PageSetup.Borders.ClearFormatting();
builder.MoveToDocumentEnd();
builder.InsertHtml("<html><body><p><span style=\"font-size: 9px; font-family: Verdana; color: #000000;\">This is some simple text, what size is it?</span></p></body></html>");
builder.MoveToDocumentEnd();
using (FileStream fs = new FileStream(@"c:\docfile.doc", FileMode.Create, FileAccess.Write))
{ doc.Save(fs, SaveFormat.Doc); }
@davidpitt000,
This is the expected behavior. In this case, both MS Word 2019 and Aspose.Words 19.6 detect the font size of text in HTML as Verdana 7 points. You can try converting this HTML to PDF (use Save As option) by using MS Word 2019 on your end to verify the correctness of Aspose.Words. Sample input/output documents produced on our end are attached here for your reference.
Docs.zip (26.3 KB)
docsCompare.zip (79.9 KB)
Hi, thanks for the reply; I’m not so much concerned by what Word 2019 might do, but in order to be able to migrate to a newer version, I need to be able to maintain the existing behaviour of Aspose.Words 2009 in converting to 6.5pt, for backward compatibility.
Is there some way, without changing the input html, to have Aspose.Words 2019 as a drop in replacement for Aspose.Words 2009 and still produce the same output from the same input. eg, maintain 9px font outputting as 6.5pt when saved as pdf.
I’ve changed the code as such to save the files side by side to compare as an example
#if newAsposeWords
string fn = "v2019";
#else
string fn = "v2009";
#endif
using (FileStream fs = new FileStream($@"c:\{fn}docdocfile.doc", FileMode.Create, FileAccess.Write))
{ doc.Save(fs, SaveFormat.Doc); }
using (FileStream fs = new FileStream($@"c:\{fn}pdffile.pdf", FileMode.Create, FileAccess.Write))
{ doc.Save(fs, SaveFormat.Pdf); }
@davidpitt000,
We have logged your requirement/problem in our issue tracking system. Your ticket number is WORDSNET-18775. We will further look into the details of this issue and will keep you updated on the status of the linked issue.
@davidpitt000,
Regarding WORDSNET-18775, we have completed the work on your issue and concluded to close this issue as ‘Not a Bug’. Please see the following analysis details.
MS Word and Aspose.Words have the same behavior now during converting points to half points. It is impossible to revert back to very older (I think, 2009.08.05) version. As we can see previously, Aspose.Words used different formulas for converting pixels to points.
Current formula is the following:
Points = pixels / resolution * PointsPerInch;
6.75 = 9px / 96 * 72;
Font size rounding behavior was changed long ago to match behavior of MS Word. Now all fractional font sizes are rounded up to the nearest half point value and there is no option that would restore the old behavior.
Unfortunately, there is no workaround that would make newer versions of Aspose.Words round font sizes as before. We apologize for any inconvenience.