Linux url to pdf

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Convert HTML to PDF with cURL on the command line

pdfmyurl/curl_convert_html_to_pdf

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

Convert HTML to PDF with cURL on the Linux command line

The examples below use our HTML to PDF API to create PDFs from HTML or URLs. Many more options can be used to influence the layout of the PDFs as well as the way the conversion takes place.

cURL URL to PDF conversion example

Here we’re converting the example URL https://www.example.com to PDF and storing it in a file called «result.pdf».

curl -d "license=yourlicensekey" \ --data-urlencode "url=https://www.example.com" \ -o result.pdf \ -H "Content-Type: application/x-www-form-urlencoded" \ -X POST https://pdfmyurl.com/api 

You can add additional parameters by using the cURL -d parameter or the cURL —data-urlencode parameter in case you need URL encoding.

cURL HTML to PDF conversion example

This example will convert raw HTML from a file named «html.html» to a PDF with the name «result.pdf». Since you want to usually convert quite a bit of HTML to get a full page, it makes sense to store that in a file first before using cURL. Otherwise your cURL command becomes really large, just due to the html parameter.

curl -d "license=yourlicensekey" \ --data-urlencode html@html.html \ -o result.pdf \ -H "Content-Type: application/x-www-form-urlencoded" \ -X POST https://pdfmyurl.com/api 

To use this example just copy/paste it and make sure you have a file named «html.html» in the current directory that contains the HTML.

Читайте также:  Intel ich10 linux driver

About

Convert HTML to PDF with cURL on the command line

Источник

How to Convert a Webpage to PDF in Linux

Saving a webpage as a PDF comes in handy when you archive certain resources or use them for educational purposes.

But, how do you convert a webpage to PDF in Linux?

You can either choose to go the easy way out using the web browser (GUI) on every Linux distribution or use the terminal to turn a webpage into a PDF file.

Here, I shall mention both the methods to help you get the job done.

Method 1: Converting a Webpage to PDF Using Web Browser

Even though I use Mozilla Firefox for this tutorial, you can do the same thing with any of the best browsers available for Linux.

mozilla save webpage pdf

1. Load up the webpage you want to convert.

2. Head to the browser menu to find the “Print” option or use the keyboard shortcut “Ctrl + P.”

3. By default, it should let you save it as a PDF. You need to hit “Save,” and choose the destination and save the webpage.

Save webpage as PDF in Mozilla Firefox

The one major problem with this simple approach is that it includes all the elements on the page. This may include comments, footer etc. You may use a PDF editor to remove parts of it but that’s an additional task.

A better option is to utilize a browser extension like Print Friendly. It allows you to edit and remove parts of the webpage before downloading the PDF.

Method 2: Converting a Webpage to PDF or Images Using the Terminal

You probably already know that you can browse internet in Linux terminal and even download files using the command line. That’s not surprising considering you can do a lot more in the terminal, including downloading a webpage as PDF.

A nifty open-source command-line tools wkhtmltopdf and wkhtmltoimage come to the rescue that lets you convert any HTML webpage to a PDF or image file.

It utilizes the Qt WebKit rendering engine to get the task done. You can explore its GitHub page for more information.

You should be able to install it from the default repository of your Linux distribution. For Ubuntu-based distros, you can type in the command:

sudo apt install wkhtmltopdf

It is pretty straightforward to use no matter whether you want to convert it to a PDF or image file:

Читайте также:  Как удалить разделы в линукс

htmltopdf mint

To convert a webpage into a PDF, type in:

wkhtmltopdf URL/domain filename.pdf

As an example, here’s how it would look:

wkhtmltopdf linuxmint.com mint.pdf

You can choose to use the complete URL as “https://linuxmint.com” or use the domain name as shown in the example above.

The file generated will be saved in the home directory by default.

You also get a few exciting options when converting a webpage.

For instance, you can apply a grayscale filter to the PDF file, make multiple copies of the page in the same file, and exclude images during conversion.

The grayscale filter may not work on every webpage, but you can try that using the command:

wkhtmltopdf -g google.com googlepage.pdf

To make multiple copies of pages in the same PDF file, the command would be:

wkhtmltopdf --copies 2 linuxmint.com mint.pdf

And, if you want to exclude images from the web pages, just type:

wkhtmltopdf --no-images linuxmint.com mint.pdf

Additionally, if you want to convert a webpage as an image, the command would look like this:

wkhtmltoimage linuxmint.com mint.png

Note that unlike the GUI method using a browser, using these tools via the terminal has its limitation. It does not seem to convert web pages utilizing any code snippets successfully.

Sites like ours and even DuckDuckGo didn’t convert to PDF or an image. However, simple HTML sites like Linuxmint.com, Ubuntu.com, Google.com, worked like charm.

Wrapping Up

To get the best results, saving a webpage as a PDF using a browser seems to be the way to go. But, if you want more options and go through the terminal, the wkhtmltopdf utility should come in handy.

How do you prefer to convert web pages to PDF in Linux? Feel free to share your thoughts in the comments.

Источник

Wkhtmltopdf – A Smart Tool to Convert Website HTML Page to PDF in Linux

Wkhtmltopdf is an open source simple and much effective command-line shell utility that enables user to convert any given HTML (Web Page) to PDF document or an image (jpg, png, etc).

Wkhtmltopdf is written in C++ programming language and distributed under GNU/GPL (General Public License). It uses WebKit rendering layout engine to convert HTML pages to PDF document without loosing the quality of the pages. Its is really very useful and trustworthy solution for creating and storing snapshots of web pages in real-time.

Wkhtmltopdf Features

  1. Open source and cross platform.
  2. Convert any HTML web pages to PDF files using WebKit engine.
  3. Options to add headers and footers
  4. Table of Content (TOC) generation option.
  5. Provides batch mode conversions.
  6. Support for PHP or Python via bindings to libwkhtmltox.

In this article we will show you how to install Wkhtmltopdf program under Linux systems using source tarball files.

Install Evince (PDF Viewer)

Let’s install evince (a PDF reader) program for viewing PDF files in Linux systems.

$ sudo yum install evince [RHEL/CentOS and Fedora] $ sudo dnf install evince [On Fedora 22+ versions] $ sudo apt-get install evince [On Debian/Ubuntu systems]

Download Wkhtmltopdf Source File

Download wkhtmltopdf source files for your Linux architecture using Wget command, or you can also download latest versions (current stable series is 0.12.4) at wkhtmltopdf download page.

Читайте также:  Linux black screen after login
On 64-bit Linux OS
$ wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
On 32-bit Linux OS
$ wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-i386.tar.xz

Install Wkhtmltopdf in Linux

Extract the files to a current working directory using following tar command.

------ On 64-bit Linux OS ------ $ sudo tar -xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz ------ On 32-bit Linux OS ------ $ sudo tar -xvzf wkhtmltox-0.12.4_linux-generic-i386.tar.xz

Install the wkhtmltopdf under /usr/bin directory for easy execution of program from any path.

$ sudo cp wkhtmltox/bin/wkhtmltopdf /usr/bin/

How to Use Wkhtmltopdf?

Here we will see how to covert remote HTML pages to PDF files, verify information, view created files using evince program from the GNOME Desktop.

Convert Website HTML Page to PDF File

To convert any website HTML web page to PDF, run the following example command. It will convert the given webpage to 10-Sudo-Configurations.pdf in current working directory.

# wkhtmltopdf https://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/ 10-Sudo-Configurations.pdf
Sample Output :
Loading pages (1/6) Counting pages (2/6) Resolving links (4/6) Loading headers and footers (5/6) Printing pages (6/6) Done

View Generated PDF File

To verify that the file is created, use the following command.

$ file 10-Sudo-Configurations.pdf
Sample Output :
10-Sudo-Configurations.pdf: PDF document, version 1.4

View Information of Generated PDF File

To view the information of generated file, issue the following command.

$ pdfinfo 10-Sudo-Configurations.pdf
Sample Output :
Title: 10 Useful Sudoers Configurations for Setting 'sudo' in Linux Creator: wkhtmltopdf 0.12.4 Producer: Qt 4.8.7 CreationDate: Sat Jan 28 13:02:58 2017 Tagged: no UserProperties: no Suspects: no Form: none JavaScript: no Pages: 13 Encrypted: no Page size: 595 x 842 pts (A4) Page rot: 0 File size: 697827 bytes Optimized: no PDF version: 1.4

View Created PDF File

Take a look at the newly created PDF file using evince program from the desktop.

$ evince 10-Sudo-Configurations.pdf
Sample Screenshot :

Looks pretty nice under my Linux Mint 17 box.

View Website Page in PDF

Create TOC (Table Of Content) of a Page to PDF

To create a table of content for a PDF file, use the option as toc.

$ wkhtmltopdf toc https://www.tecmint.com/sudoers-configurations-for-setting-sudo-in-linux/ 10-Sudo-Configurations.pdf
Sample Output :
Loading pages (1/6) Counting pages (2/6) Loading TOC (3/6) Resolving links (4/6) Loading headers and footers (5/6) Printing pages (6/6) Done

To check the TOC for the created file, again use evince program.

$ evince 10-Sudo-Configurations.pdf
Sample Screenshot :

Take a look at the picture below. it looks even more better than the above.

Create Website Page to Table of Contents in PDF

Wkhtmltopdf Options and Usage

For Wkhtmltopdf more usage and options, use the following help command. It will display list of all available options that you can use with it.

Источник

Оцените статью
Adblock
detector