Change in layout and font sizes when converting to PDF from HTML

Basically, when converting the attached HTML file. (It wouldnt let me upload it as html so I have changed it to a .txt) it changes the layout and font size of some of the text in the conversion to pdf.


I would rather the final pdf look exactly like it does in html.

Is this something you can fix?

Hi there,


Thanks for your inquiry. Please note that used fonts should be available on the host machine otherwise Aspose.Pdf will use system default font. I have rendered HTML to PDF using Aspose.Pdf for .NET 10.8.0 and unable to notice any issue, please find attached sample output. Please download latest version of Aspose.Pdf, double check the fonts availability and try following code snippet, hopefully you issue will be resolved.

Document doc = new
Document(myDir + “Html_layoutfont_issue.html”,
new HtmlLoadOptions());<o:p></o:p>

doc.Save(myDir + "Html_layoutfont_issue.pdf");

Please feel free to contact us for any further assistance.


Best Regards,

This is my code, I am having the exact same problem as Kaser47…Please can you help me get to the bottom of it.

public byte[] ConvertHtmlToPdf(string html)
{
using (var outputStream = new MemoryStream())
{
var pdf = new Aspose.Pdf.Generator.Pdf();
pdf.PageSetup.PageWidth = 1250;
pdf.PageSetup.Margin = new MarginInfo() { Bottom = 5, Top = 5, Left = 5, Right = 5 };
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();

			var text = new Aspose.Pdf.Generator.Text(section, html);
			
			text.IsHtmlTagSupported = true;
			//text.IsHtml5Supported = true;
			//text.UseTextInfoStyle = true;
			//text.IfHtmlTagSupportedOverwrightHtmlFontNames = true;
			//text.IfHtmlTagSupportedOverwrightHtmlFontSizes = true;

			section.Paragraphs.Add(text);

			pdf.Save(outputStream);

			return
				outputStream.ToArray();
		}
	}

I can assure you that the fonts are installed on the host machine because we also use the word to pdf conversion and that works fine no problem. I have used the exact same html document and just saved it as a docx, run it through the word conversion and it works without an issue. Hence why I think theres an issue with your PDF conversion.



Its an issue with the H1 field.

Hi Ash,


rhodesash55:
This is my code, I am having the exact same problem as Kaser47…Please can you help me get to the bottom of it.

public byte[] ConvertHtmlToPdf(string html)
{
using (var outputStream = new MemoryStream())
{
var pdf = new Aspose.Pdf.Generator.Pdf();
pdf.PageSetup.PageWidth = 1250;
pdf.PageSetup.Margin = new MarginInfo() { Bottom = 5, Top = 5, Left = 5, Right = 5 };
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();

			var text = new Aspose.Pdf.Generator.Text(section, html);
			
			text.IsHtmlTagSupported = true;
			//text.IsHtml5Supported = true;
			//text.UseTextInfoStyle = true;
			//text.IfHtmlTagSupportedOverwrightHtmlFontNames = true;
			//text.IfHtmlTagSupportedOverwrightHtmlFontSizes = true;

			section.Paragraphs.Add(text);

			pdf.Save(outputStream);

			return
				outputStream.ToArray();
		}
	}</div></BLOCKQUOTE></font></div><div><font face="Arial" size="2"><br></font></div><div><div><font face="Arial" size="2"><br></font></div><div style=""><font face="Arial" size="2">Thanks for your inquiry. As suggested above please use new Dom Approach for <a href="http://www.aspose.com/docs/display/pdfnet/Convert+HTML+to+PDF+Format">HTML to PDF conversion</a> instead old generator(Aspose.Pdf.Generator). Please use it will resolve the issue. conversion.</font></div><div><font face="Arial" size="2"><br></font></div><div><font face="Arial" size="2">We are sorry for the inconvenience caused.</font></div><div><font face="Arial" size="2"><br></font></div><div><font face="Arial" size="2">Best Regards,</font></div></div>
Hi there,

Kaser47:
I can assure you that the fonts are installed on the host machine because we also use the word to pdf conversion and that works fine no problem. I have used the exact same html document and just saved it as a docx, run it through the word conversion and it works without an issue. Hence why I think theres an issue with your PDF conversion.

Its an issue with the H1 field.


Thanks for your feedback. As suggested above please use new DOM approach for HTML to PDF conversion. Please double check whether you are using Aspose.Pdf namespace instead Aspose.Pdf.Generator for the conversion. If the issue persist then please share your sample code here, so we will look into it and guide you according.

We are sorry for the inconvenience caused.

Best Regards,