Custom font issue in HTML to PDF conversion with Node.Js using Aspose.PDF REST API

Hi,


I was trying to add an specific font to an html file with the cloud service. I used the Node.js SDK example:
var name = root.key+".pdf";
var templateFile = root.key+".html";
var templateType = “html”;
try {
//upload file to aspose cloud storage
storageApi.PutCreate(templateFile, null, null, data_path + templateFile , function(responseMessage) {
assert.equal(responseMessage.status, ‘OK’);

//invoke Aspose.Pdf Cloud SDK API to create PDF file from HTML
pdfApi.PutCreateDocument(name, templateFile, null, templateType, null, null, function(responseMessage) {
assert.equal(responseMessage.status, ‘OK’);
//download pdf from cloud storage
storageApi.GetDownload(name, null, null, function(responseMessage) {

assert.equal(responseMessage.status, ‘OK’);

var response = {
href: root.href,
name: name,
body: responseMessage.body
};

deferred.resolve(response);
});
});
});

}catch (error) {
console.error("Exception in convertToPDF: " + error);
deferred.reject(error);
}
The html file look likes:

@font-face{
font-family:‘Shadows Into Light’;
src: url(data:application/font-ttf;charset=utf-8;base64,BASE_64_CODE) format(‘truetype’);
}
.cool{
font-family: ‘Shadows Into Light’
}

Some text I would like to see with Shadows Into Light font.


BASE 64 Images are being correctly showed in the final PDF, but it is not working with BASE 64 fonts…

Is there any way to put the font I would like to use in the PDF ?

Thanks,
Pablo

Hi Pablo,


Thanks for contacting support.

Please note that our forums are dedicated for the support of own API’s and the above code snippet do not appear to be related to our API’s. However besides using Node.js, we recommend you to please try using Aspose.Pdf for Cloud as it offers the feature to Create PDF from HTML so all related resources of HTML file will be referenced in resultant PDF document.

Please try using our API’s and in the event of any related query, please feel free to contact.

PS, now concerning to query related to Node.js, you may consider raising the query in their respective forums.

Hi Nayyer, thanks for your answer.


I would like to tell you that the code I’m using is the exact example of the documentation for Node.js in the link you give me Create PDF from HTML → SDK Examples → Node.js

I attached 3 html files (I had to append an .txt to upload it, remove it please to see the original html) with 3 differents way of setting a custom font. if you open the 3 of them in your browser you will see a simple text with a custom font.

Then I used Aspose Cloud PDF and I convert each of them, and I attached the 3 generated pdfs. As you can see there is no pdf with the custom font as they have in the html.

So, Is there anyway to tell the api that I want to use an specific font ? This is really a key question for me.

Thanks in advance,
Pablo

Hi Pablo,


Thanks for sharing the resource file. We are working on testing the scenario and will get back to you soon.

@xpitr256

Kindly note we have improved the document conversion in the latest API Version 3.0 of Aspose.PDF Cloud. Please zip upload all the HTML resources to Cloud storage and convert it to PDF document. Please check the sample unit test from Aspose.PDF Cloud SDK for Node.js for reference. Please let us know if you still face the issue.