How to Convert HTML to PDF or XLS.
Converting HTML to PDF or XLS can be a little bit challenging especially when the output size of the PDF is large.
In fact, not having control of the layout and styles of individual pages of your document can be very annoying. Tables and images will mess up your document.
Today, I will tell you how to convert HTML to PDF without sweat.
DocRaptor is an online service that can be used to generate PDF, XLS files from HTML at an affordable price.
There’s a 7-day free trial so you can have a chance to try it out first before paying for a plan.
They are so affordable that you pay 9 cents per document when you pay for a professional plan.
Here are docraptor plans and pricing below.
Converting HTML to PDF with Docraptor
DocRaptor has libraries for PHP, Python(supports for both 2.x and 3.x), Node.js, Ruby, Java, .NET, and JavaScript/jQuery, etc for converting HTML, CSS and Javascript into PDF and XLS documents.
You can easily install DocRaptor library with
After installing, all you need to do to use Docraptor is to submit a POST request, supplying certain options and the document you want to convert, giving the content directly or providing a URL. You also need the API Key supplied with your paid account.
Some of these options are:
- type: this is the type of document you want to generate. It can be PDF or excel files
- document_content: this is the HTML code snippet you want to convert to PDF or XLS
- document_url: this is the webpage url to convert to PDF or XLS files.
- name: this option can be ignored. It is a string to describe and identify the document
Other options are found here.
HTML with only tables are converted to XLS files.
Python123456789101112131415 | importdocraptordocraptor.configuration.username="YOUR_API_KEY_HERE"# docraptor.configuration.debug = Truedoc_api=docraptor.DocApi()response=doc_api.create_doc({"document_url":"https://coolpythoncodes.com/full-stack-developer-guide/",# converting a webpage url to pdf"name":"fullstack-guide.pdf",# help you find a document later"document_type":"pdf",})withopen('pythonbook.pdf',"wb")asf:f.write(response) |
The above code snippet generates a PDF from one of my blog post urls and creates a pdf file named pythonbook.pdf. It also generates the PDF synchronously.
Pin7Tweet32 Shares