- Wkhtmltopdf — умная утилита для конвертирования веб-страниц в PDF в Linux
- Особенности Wkhtmltopdf
- Установка Evince (программа для просмотра PDF)
- Скачивание исходного кода Wkhtmltopdf
- Установка Wkhtmltopdf в Linux
- Как использовать Wkhtmltopdf?
- Конвертирование HTML-страницы в формат PDF
- Проверка сгенерированного файла PDF
- Просмотр информации о сгенерированном файле PDF
- Просмотр сгенерированного файла PDF
- Создание таблицы содержимого (Table Of Content) файла PDF
- Convert HTML Page To a PDF Using Open Source Tool [ Linux / OS X / Windows ]
- Software features
- A note about Debian / Ubuntu Linux user
- Install wkhtmltopdf on MacOS unix
- Convert html to pdf with Linux
- First step, download the web page in html
- Second step, convert the html file to pdf file
- Wkhtmltopdf – A Smart Tool to Convert Website HTML Page to PDF in Linux
- Wkhtmltopdf Features
- Install Evince (PDF Viewer)
- Download Wkhtmltopdf Source File
- Install Wkhtmltopdf in Linux
- How to Use Wkhtmltopdf?
- Convert Website HTML Page to PDF File
- View Generated PDF File
- View Information of Generated PDF File
- View Created PDF File
- Create TOC (Table Of Content) of a Page to PDF
- Wkhtmltopdf Options and Usage
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- Command Center
- Tuesday, February 7, 2012
- convert html to pdf linux
Wkhtmltopdf — умная утилита для конвертирования веб-страниц в PDF в Linux
Оригинал: Wkhtmltopdf – A Smart Tool to Convert Website HTML Page to PDF in Linux
Автор: Ravi Saive
Дата публикации: 28 января 2017 года
Перевод: А. Кривошей
Дата перевода: февраль 2018 г.
Wkhtmltopdf — простая и эффективная утилита командной строки с открытым исходным кодом, которая позволяет пользователю конвертировать любую веб-страницу в документ PDF или изображение (jpg, png и т. д.).
Wkhtmltopdf написана на C ++ и распространяется под лицензией GNU/GPL (General Public License). Она использует механизм рендеринга WebKit для преобразования веб-страниц в PDF без потери качества. Это действительно очень полезное и заслуживающее доверия решение для создания и хранения снимков веб-страниц в режиме реального времени.
Особенности Wkhtmltopdf
— открытый исходный код, кроссплатформенная утилита;
— преобразование любых веб-страниц в файлы PDF с использованием движка WebKit;
— опции для добавления верхних и нижних колонтитулов;
— опция генерации таблицы содержимого (TOC);
— обеспечивает конвертирование в пакетном режиме;
— поддержка PHP или Python через привязки к libwkhtmltox.
В этой статье мы покажем вам, как установить программу Wkhtmltopdf в Linux из исходного кода.
Установка Evince (программа для просмотра PDF)
Давайте сначала установим программу evince для просмотра PDF в Linux.
Скачивание исходного кода Wkhtmltopdf
Загрузите исходные коды wkhtmltopdf для вашей архитектуры Linux, с помощью команды Wget, также вы можете загрузить последнюю версию на странице загрузки wkhtmltopdf.
Для 64-битных систем
Для 32-битных систем
Установка Wkhtmltopdf в Linux
Распакуйте файлы в текущую рабочую директорию с помощью команды tar.
В 64-битной системе
В 32-битной системе
Установите wkhtmltopdf в директорию /usr/bin, чтобы ее можно было запускать из любого места.
Как использовать Wkhtmltopdf?
Здесь мы рассмотрим, как конвертировать HTML-страницы в PDF, верифицировать информацию и просматривать созданные файлы с помощью программы evince.
Конвертирование HTML-страницы в формат PDF
Для преобразования веб-страницы в PDF, выполните приведенную ниже команду. Он конвертирует указанную веб-страницу в файл 10-Sudo-Configurations.pdf в текущем рабочем каталоге.
Проверка сгенерированного файла PDF
Для того, чтобы проверить, что файл создан корректно, введите команду:
Просмотр информации о сгенерированном файле PDF
Чтобы просмотреть информацию о созданном файле, воспользуйтесь следующей командой:
Просмотр сгенерированного файла PDF
Давайте взглянем на содержимое созданного нами файла с помощью программы evince:
Пример созданного файла
В моей Linux Mint 17 выглядит отлично.
Создание таблицы содержимого (Table Of Content) файла PDF
Для создания таблицы содержимого PDF-файла используется опция toc.
Для проверки TOC созданного файла снова используем программу evince:
Дополнительную информацию об использовании и опциях Wkhtmltopdf можно получить с помощью команды help:
Источник
Convert HTML Page To a PDF Using Open Source Tool [ Linux / OS X / Windows ]
D o you need a simple open source cross-platform command line tool that converts web pages and HTML to a PDF file? Look no further, try wkhtmltopdf.
From the project home page:
Simple shell utility to convert html to pdf using the webkit rendering engine, and qt. Searching the web, I have found several command line tools that allow you to convert a HTML-document to a PDF-document, however they all seem to use their own, and rather incomplete rendering engine, resulting in poor quality. Recently QT 4.4 was released with a WebKit widget (WebKit is the engine of Apples Safari, which is a fork of the KDE KHtml), and making a good tool became very easy.
Software features
- Cross platform.
- Open source.
- Convert any web pages into PDF documents using webkit.
- You can add headers and footers.
- TOC generation.
- Batch mode conversions.
- Can run on Linux server with an XServer (the X11 client libs must be installed).
- Can be directly used by PHP or Python via bindings to libwkhtmltox.
A note about Debian / Ubuntu Linux user
You can install wkhtmltopdf using apt-get command:
$ sudo apt-get install wkhtmltopdf
$ sudo ln -s /usr/bin/wkhtmltopdf /usr/local/bin/html2pdf
Sample outputs:
Install wkhtmltopdf on MacOS unix
First, install Homebrew on macOS and then type the following brew command:
$ brew install wkhtmltopdf
OR
$ brew cask install wkhtmltopdf
Источник
Convert html to pdf with Linux
Written by Guillermo Garron
Date: 2010-10-07 10:36:30 00:00
When you may need to convert a complete web page in html to a pdf file, Linux can help you.
We will need two tools:
- wget — To download the complete page, including css, and others
- wkhtmltopdf — To make the real conversion from html to pdf
You should be able to install both of them using your package manager.
To be able to convert the html to pdf, we will follow a two stage process.
First step, download the web page in html
To do that enter this command:
I will first create a folder to store the page, so.
Then download the web page:
That will create a structure like this:
There you will find the file, new-branch-on-debian-1.html
Second step, convert the html file to pdf file
Enter into the folder where the html file is.
Convert the file.
Using this format
wkhtmltopdf [html file] [pdf file]
That is it, you now have converted a complete html file including format, css, etc. to a pdf file, that you can send by email, archive, or anything you want.
Note: If the page you are downloading does not have .html extension you may get errors, to solve that, just mv (rename) the file to have an .html extension. Now a days, most of the pages does not have .html extensions.
If you enjoyed the article, please share it
Источник
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
- Open source and cross platform.
- Convert any HTML web pages to PDF files using WebKit engine.
- Options to add headers and footers
- Table of Content (TOC) generation option.
- Provides batch mode conversions.
- 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.
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.
On 64-bit Linux OS
On 32-bit Linux OS
Install Wkhtmltopdf in Linux
Extract the files to a current working directory using following tar command.
Install the wkhtmltopdf under /usr/bin directory for easy execution of program from any path.
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.
Sample Output :
View Generated PDF File
To verify that the file is created, use the following command.
Sample Output :
View Information of Generated PDF File
To view the information of generated file, issue the following command.
Sample Output :
View Created PDF File
Take a look at the newly created PDF file using evince program from the desktop.
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.
Sample Output :
To check the TOC for the created file, again use evince program.
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.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
Command Center
#!/bin/GREPing a ‘[programmer][sysadmin]’ with Killer Skillz
Tuesday, February 7, 2012
convert html to pdf linux
In a previous post I wrote about using wkhtmltopdf for html to pdf conversion with Ruby and Rails.
As can by typical with components, moving them to production you hope will be straight forward but is often not. Such was the case for me on getting wkthmltopdf working on my Ubuntu Server 10.04 server from my Mac Leopard dev environment.
The first question was how to install wkhtmltopdf on the server. Since **I had not been successful** installing it on my own on my Mac (I used the PdfKit ruby gem to install it), it was not clear if I would succeed here.
I ended up finding that there is a package for wkhtmltopdf for Ubuntu:
This package did its work and it installed. It seemed too easy. And it was.
While wkhtmltopdf (v0.9.9) did install, I was soon getting the following and dreaded error:
The reason for this error is that the current incarnation of Web Kit requires a GUI. Hopefully this will change in the future.
After some research I found what looked like a solution:
Use Xvfb (‘X Virtual Frame Buffer’). Xvfb promised to create a lightweight, temporary situation that would trick wkhtmltopdf into running. Please excuse my un-technical and probably inaccurate description of what Xvfb does, but you get the point.
It worked great! At least until…. I discovered that those darned links in the converted document were not active. I could not find an answer for this, so kept googling. My sense was that this problem must have something to do with running wkhtmltopdf through xvfb.
I ended up being right, and the solution was to use a patched QT in lieu of xvfb.
So I decided to try installing the static binary of wkhtmltopdf as follows:
- Uninstall the wkhtmltopdf package:
- (in usr/local/bin)
- (in usr/local/bin)
This showed me that a certain linux source file was missing and led to resolving the problem. In short, if one of the binaries does not work, try the other.
Once I got this installed everything worked, links were rendering and the client happy.
Источник