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

Free Support Forum - aspose.com

Throws exception converting when Html to Pdf for custom fonts

Hi

I am trying to export HTML to PDF document. Sometimes HTML contain custom fonts that is not installed on the machine. In such case Aspose.Pdf throws exception. I have already set IsFontNotFoundExceptionThrown flag to false.

I am using Aspose.Pdf version 8.8.0

Exception details:

System.ApplicationException was unhandled by user code
HResult=-2146232832
Message=The embedded font ‘crisp’ is not found. Make sure that you set correct path to the font file.
Source=Aspose.Pdf
StackTrace:
at . . (String , Boolean , String , Exception )
at . . ( , String , String , Boolean , Boolean , Boolean , String , Boolean )
at . . (String , String , Boolean , Boolean , Boolean , String , Boolean )
at . . (TextInfo )
at . . (Text , Pdf )
at . . (Pdf , Section , Table , Row , Cell , Text , , , Boolean )
at . . (Pdf , Section , HeaderFooter , Table , Row , Cell , Text , , , Boolean )
at . . (Pdf , Section , Table , Row , Cell , , )
at . . (Pdf , Section , Table , Row , , )
at . . (Pdf doc, Section currentPart, HeaderFooter hf, Table table, assignInfo, useType, Boolean isFirst, & breakTableNextPart)
at . . (Pdf , Section , )
at . . (Pdf )
at . . ( , Pdf )
at Aspose.Pdf.Generator.Pdf.Save(Stream stream)
at HelpSTAR.BusinessRule.Core.clsRequestViewer.ExportRequestDetailsToPdf(Int32 requestId, Boolean publicMemoOnly, String excludedAuthors, String excludeTransactionTypes, hsSortDirection sortDirection, String whereClause, Int32 currentUserId) in c:\Development\HSSilverlight2012\BusinessRule\Core\clsRequestViewer.cs:line 1137
at HelpSTAR.Server.Factory.ServiceRequestFactory.ExportRequestDetailsToPdf(Int32 requestId, Boolean publicMemoOnly, String excludedAuthors, String excludeTransactionTypes, hsSortDirection sortDirection, String whereClause, Int32 currentUserId) in c:\Development\HSSilverlight2012\HelpSTAR.Server.Factory\ServiceRequestFactory.cs:line 5951
at HelpSTAR.Server.Services.LongTimeTransactionScopeService.ExportRequestDetailsToPdf(String userSessionKey, Int32 requestId, Boolean publicMemoOnly, String excludedAuthors, String excludeTransactionTypes, hsSortDirection sortDirection, String whereClause, Int32 currentUserId) in c:\Development\HSSilverlight2012\HelpSTAR.Server\Services\LongTimeTransactionScopeService.svc.cs:line 289
at SyncInvokeExportRequestDetailsToPdf(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
InnerException: System.ApplicationException
HResult=-2146232832
Message=Font ‘crisp’ not found. Please make sure the customer font file is correctly set.
Source=Aspose.Pdf
StackTrace:
at . . ( , String , String , Boolean )
at . . ( , String , String , Boolean , Boolean , Boolean , String , Boolean )
at . . ( , String , String , Boolean , Boolean , Boolean , String , Boolean )
InnerException:

Thanks,

Binoy

Hi Binoy,


Thanks for your inquiry. We have already noticed this issue and logged an investigation ticket, PDFNEWNET-35818, for the purpose. We will update you via this forum thread as soon as it is resolved.

Moreover, please try following DOM approach for HTML to PDF conversion. Hopefully it will help you to resolve your issue.

HtmlLoadOptions options = new HtmlLoadOptions();<o:p></o:p>

// use the new conversion engine<o:p></o:p>

options.UseNewConversionEngine = true;<o:p></o:p>

// load HTML file<o:p></o:p>

Document pdfDocument = new Document(myDir + “Sample.html”, options);<o:p></o:p>

// save output as PDF format<o:p></o:p>

pdfDocument.Save(myDir + “HTMLtoPDF_DOM.pdf”);<o:p></o:p>

<o:p>
</o:p>

<o:p>Please feel free to contact us for any further assistance.</o:p>


Best Regards,

I have updated the code. It is working with missing font but now I am getting another exception (DOM approach). This works correctly using Pdf generator though.

System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=Token DTD in state Element Start Tag would result in an invalid XML document.
Source=System.Xml
StackTrace:
at System.Xml.XmlWellFormedWriter.ThrowInvalidStateTransition(Token token, State currentState)
at System.Xml.XmlWellFormedWriter.AdvanceState(Token token)
at System.Xml.XmlWellFormedWriter.WriteDocType(String name, String pubid, String sysid, String subset)
at . . (String , String , String , String )
at . . ()
at . . ( )
at . . ( )
at . . ( )
at . . ( )
at . . ( )
at . . ()
at . . ( )
at . . ( )
at . . ( )
at . . ( )
at . . ( )
at . . ( )
at . . ( , )
at . . (String , )
at . . (Stream , Document , )
at Aspose.Pdf.Document. (Stream , LoadOptions )
at Aspose.Pdf.Document…ctor(Stream input, LoadOptions options)
at HelpSTAR.BusinessRule.Core.clsRequestViewer.ExportRequestDetailsToPdf(Int32 requestId, Boolean publicMemoOnly, String excludedAuthors, String excludeTransactionTypes, hsSortDirection sortDirection, String whereClause, Int32 currentUserId) in c:\Development\HSSilverlight2012\BusinessRule\Core\clsRequestViewer.cs:line 1124
at HelpSTAR.Server.Factory.ServiceRequestFactory.ExportRequestDetailsToPdf(Int32 requestId, Boolean publicMemoOnly, String excludedAuthors, String excludeTransactionTypes, hsSortDirection sortDirection, String whereClause, Int32 currentUserId) in c:\Development\HSSilverlight2012\HelpSTAR.Server.Factory\ServiceRequestFactory.cs:line 5951
at HelpSTAR.Server.Services.LongTimeTransactionScopeService.ExportRequestDetailsToPdf(String userSessionKey, Int32 requestId, Boolean publicMemoOnly, String excludedAuthors, String excludeTransactionTypes, hsSortDirection sortDirection, String whereClause, Int32 currentUserId) in c:\Development\HSSilverlight2012\HelpSTAR.Server\Services\LongTimeTransactionScopeService.svc.cs:line 289
at SyncInvokeExportRequestDetailsToPdf(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
InnerException:

Thanks,
Binoy

Hi Binoy,


We are sorry for the inconvenience caused. Please share your sample project/code and resource HTML here. So we will test the scenario at our end and will provide you more information accordingly.

Best Regards,

Hi Tilal



Thanks for your email. Here is a code that I tried as suggested:



Aspose.Pdf.HtmlLoadOptions htmlOptions = new Aspose.Pdf.HtmlLoadOptions(embeddedImageLocation);

htmlOptions.UseNewConversionEngine = true;

using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(requestHtml.ToString())))

using (Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(ms, htmlOptions))

using (MemoryStream pdfStream = new MemoryStream())

{

pdfDocument.PageInfo.IsLandscape = true;

pdfDocument.PageInfo.Margin = new Aspose.Pdf.MarginInfo(30, 10, 10, 30);

pdfDocument.Save(pdfStream);

pdfStream.Flush();

returnValue.Data = pdfStream.ToArray();

}





I have attached sample html with embedded images.



Thanks,

Binoy

Hi Binoy,


Thanks for sharing sample code. I have tried your sample code and unable to notice the reported issue. Please share a sample project to replicate the issue. So we test the scenario and investigate it further.

Aspose.Pdf.HtmlLoadOptions htmlOptions = new Aspose.Pdf.HtmlLoadOptions(myDir

  • “Sample (3)/”);<o:p></o:p>

htmlOptions.UseNewConversionEngine = true;

System.IO.StreamReader htmlFile = new System.IO.StreamReader(myDir + "Sample (3)/test.html");

string html = htmlFile.ReadToEnd();

using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(html)))

using (Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(ms, htmlOptions))

using (MemoryStream pdfStream = new MemoryStream())

{

pdfDocument.PageInfo.IsLandscape = true;

pdfDocument.PageInfo.Margin = new Aspose.Pdf.MarginInfo(30, 10, 10, 30);

//pdfDocument.Save(pdfStream);

pdfDocument.Save(myDir+"HTMLtoPDFDOM.pdf");

//pdfStream.Flush();

//returnValue.Data = pdfStream.ToArray();

}


We are sorry for the inconvenience caused.


Best Regards,

Hi Tilal



I can reproduce the issue. I have attached the solution that shows the issue.



PS: I am running Windows 8.1 64 bit



Thanks,

Binoy

Hi Binoy,


Thanks for sharing sample project. It is working fine over Win 7 64 bit after applying license file and setting output path, just added an additional “” as I was getting Illegalcharacters exception in path.

However, I am testing the scenario over Windows 8 and will get back to you with results soon.

We are sorry for the inconvenience caused.

Best Regards,

Hi Tilal

Do you have any updates? Can you please send me the updated project that is working on win7?

Thanks,
Binoy

Hi Binoy,


We are working on preparing a sample project and will share it shortly.

Hi Nayyer



Thanks for the feedback, I managed to get it working. So it now generates the PDF without any issue. Only issue is the generated PDF has huge page size. I have attached a sample that illustrate the issue. See the generated PDF and page size is 97.51 x 11.69 in



Can you assist me to fix this?



Thanks,

Binoy

Hi Binoy,


Thanks for your feedback. It is good to know that you are able to convert HTML to PDF without any exception.

In reference to Page size issue you can use SetPageSize() method as suggested in this document. But I am afraid it is not working as expected, so we have logged an investigation ticket PDFNEWNET-36350 in our issue tracking system for the purpose. We will notify you via this forum thread as soon as it is resolved.

We are truly sorry for the inconvenience caused.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-36350) have been fixed in Aspose.Pdf for .NET 9.1.0.

For further details, you may check this blog post.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Binoy,


Thanks for your patience.

We have further investigated the issue PDFNEWNET-36350 reported earlier and it does not seem to be an issue with Aspose.Pdf for .NET. Please notice that source html has large width so in order to generate correct output, you need to increase the width of PDF file. Please try using following code line

[C#]
page.SetPageSize(1024f, 800f);


PS,when using above code line, there are no missing parts in the generated layout.