Prince - Convert HTML to PDF

Moderator: Forum moderators

Post Reply
User avatar
puppy_apprentice
Posts: 692
Joined: Tue Oct 06, 2020 8:43 pm
Location: land of bigos and schabowy ;)
Has thanked: 5 times
Been thanked: 115 times

Prince - Convert HTML to PDF

Post by puppy_apprentice »

It’s quick and simple to convert HTML to PDF with Prince. HTML is seamlessly transformed into documents you can print, download and archive. Prince enables you to typeset, format and print HTML content so you can be your own publisher.

Prince supports all the main Web Standards:

HTML, XHTML, XML, SVG
Cascading Style Sheets (CSS)
JavaScript / ECMAScript
JPEG, PNG, GIF, TIFF

https://www.princexml.com/

Quick tutorial

We make quick (short) Manual for Puppy Linux.

We need:
1. Cover page (save as cover.html):

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Puppy Manual</title>
</head>
<body>
<div align="center">
<h1>Puppy Manual</h1>
<p><a href="https://forum.puppylinux.com/viewforum.php?f=184">Read online</a></p>
<img src="https://static.vecteezy.com/system/resources/previews/005/484/042/original/dog-logo-illustration-free-vector.jpg" height="640" width="480">
</div>
</body>
</html>

2. Stylesheet (save as puppy-pdf.css):

Code: Select all

/* Hide unnecessary stuff */ 
#page-header {display: none}
.page-number {display: none}
.copyright {display: none}
hr, dd {display: none}
.date {display: none}
/* Adjust some stuff to the page */ 
img {text-align: left; width: 100%; max-width: 500px}
ol {position: relative; left: 20px}

/* Add page numbers */ 
@page {
	@bottom {
		content: counter(page);
		font-style: italic;
	}
}

3. List of pages (save as list.txt, extend the list to get full manual):

Code: Select all

cover.html
https://forum.puppylinux.com/viewtopic.php?t=5127&view=print
https://forum.puppylinux.com/viewtopic.php?t=5314&view=print
https://forum.puppylinux.com/viewtopic.php?t=5192&view=print

Now use command:

Code: Select all

prince -l list.txt -s puppy-pdf.css -o Manual.pdf 

SFS to download:
prince-14.3-i686_6.3.2.sfs
prince-14.3-x86_64_6.3.2.sfs

Attachments
Manual.pdf
Example PDF file
(262.01 KiB) Downloaded 90 times
Post Reply

Return to “Documents”