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

Free Support Forum - aspose.com

Convert HTML to PDF using Aspose.PDF for .NET - 0KB PDF file generated

Hi,

We have been using Aspose.pdf dll to convert HTML documents into PDF.Version - 10.1.0.0.
But one particular html document is not getting converted, a 0KB file is being generated.
The html document has font-family of - “Bradley Hand ITC”.Below is the html file.
Could you please check and advise on the issue ?

===============================================

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
	{font-family:"Bradley Hand ITC";
	panose-1:3 7 4 2 5 3 2 3 2 3;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;
	mso-fareast-language:EN-US;}
p.msonormal0, li.msonormal0, div.msonormal0
	{mso-style-name:msonormal;
	mso-margin-top-alt:auto;
	margin-right:0cm;
	mso-margin-bottom-alt:auto;
	margin-left:0cm;
	font-size:12.0pt;
	font-family:"Times New Roman",serif;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">


<p class="MsoNormal"><span style="font-size:16.0pt;font-family:&quot;Bradley Hand ITC&quot;">Test Name<o:p></o:p></span></p>

</div>

</body>
</html>
===============================================

@sudeer

Thanks for contacting support.

We have tested the scenario while using Aspose.Pdf for .NET 17.9 with following code snippet and were unable to notice the issue of 0KB file generation. The API generated valid PDF document. For your reference, we have also attached an output, generated by below code.

var loadoptions = new HtmlLoadOptions(dataDir);
Document doc = new Document(dataDir + "FontSpecific.html", loadoptions);//MergePDF(docList);
doc.Save(dataDir + "FontSpecific.pdf"); 

FontSpecific.pdf (23.4 KB)

Please note that you are using a quite old version of the API, whereas it is strongly and always recommended to use latest version. Please upgrade to latest version of the API and in case you still face any issue, please feel free to let us know.

Thanks for your reply Asad,we have now got the latest Aspose.Pdf dll - 17.9 version, but we can see that in the new version - Aspose.Pdf.Generator.Pdf is not there.We are using below code to convert html document into pdf -

Could you please advise what changes are required to use the latest version ?

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, sr.ReadToEnd());
sr.Close();
text2.TextInfo.IsUnicode = fontEmbedded;
text2.IsHtmlTagSupported = true;
section.Paragraphs.Add(text2);
pdf.Save(“Test.pdf”));

@sudeer

Thanks for your inquiry.

The old Aspose.Pdf.Generator approach has been obsoleted in the new version(s) of Aspose.Pdf and we strongly recommend to use Aspose.Pdf DOM approach. You may use HtmlFragment class, in order to add HTML string inside PDF at paragraph level. For more information, please visit “Add HTML String using DOM” article in our API documentation. In case you face any issue, please feel free to let us know.