Anonymous
Not logged in
Talk
Contributions
Create account
Log in
Publication Station
Search
Editing
Web-to-print-with-pagedjs
From Publication Station
Namespaces
Page
Discussion
More
More
Page actions
Read
Edit
History
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Printing from HTML & CSS == Did you know you can design beautiful printed books, flyers etc. directly in CSS and HTML? This seems like a strange technology to use, because it is much easier to do in Indesign. However, doing it directly from HTML and CSS offers some unique possibilities: * Better hybrid publishing workflow **You can create a publication that has HTML as it's source and from there can be exported to many different formats, including a printed book, pdf file, website, web app, epub etc. Because you have one online source, it is easy to update and collaborate on without having the trouble of sending around multiple versions etc. * Customized printed publications **Printing from HTML & CSS allows you to create printed publications that are tailored to individual users because both the content and design can easily be changed programmatically. This technology is still rather niche, so many applications for it are relatively underexplored. == Why Paged.js? == For decades, CSS has included possibilities for designing printed publications. Unfortunately, browsers have stopped adhering to these standards for print CSS. This means that you can design a beautiful books in your CSS, but when you print it directly in the browser (like you are supposed to do) it will miss a lot of features that make a book a book. There are many initiatives out there that fix this issue in different ways. One way is to send the file to a server and make a pdf from it there, but this can get rather complicated. Paged.js solves it by using JavaScript to interpret you CSS and force the brower to interpret it correctly when printing. For many designers, this is the simplest solution. == How to get started with the Paged.js polyfill == The general workflow is to include a link to the Paged.js polyfill (the easiest option) in the '''head''' of your HTML document like this: <code><script src="https://unpkg.com/pagedjs/dist/paged.polyfill.js"></script></code> After that, all of your print CSS should be correctly interpreted by the browser. It will also automatically show a preview of the print version in you browser window. But be careful, it doesn't work on local files! Therefore, the easiest way to work with it is to run your HTML and CSS files in Visual Studio Code with the Live Server extension. == Writing print CSS == The documentation of print CSS is excellent on Paged.js, so I won't repeat it here. Please follow their instructions [https://pagedjs.org/documentation/5-web-design-for-print/#the-%40media-print-query here] and enjoy! == Example CSS == Here is an example of a css file that uses many different print properties. <syntaxhighlight lang="css"> body { background: red; font-size: 35px; } @media print { @page { size: A5; margin: 5mm 10mm; bleed: 6mm; marks: crop; /* background-image: url('SILVER-HOLOGRAM-scaled.jpg'); */ @top-right { content: "My beautiful book"; font-size: 15px; color: brown; } @bottom-right { content: "page "counter(page); } @bottom-center { content: string(title); } } @page chapterpage { @bottom-right { content: ""; } } @page: first { @top-right { content: ""; } @bottom-right { content: ""; } @bottom-center { content: ""; } background-image:url('SILVER-HOLOGRAM-scaled.jpg'); } @page: right { margin-right: 20mm } @page: left { margin-left: 20mm } body { background: white; } h2 { break-before: right; string-set: title content(text); page: chapterpage; } h1 { break-after: page; } .page-break { break-before: page; } } </syntaxhighlight>
Summary:
Please note that all contributions to Publication Station are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Publication Station:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation
Main navigation
Main page
Printmaking Studio
Print Studio
Dig. Publishing Studio
Namespaces
Grafiwiki
Random Page
Log in
Wiki tools
Wiki tools
Page tools
Page tools
User page tools
More
What links here
Related changes
Page information
Page logs