Web pages to print media — solutions?

0 votes
asked Jan 15, 2009 by andrew-flanagan

I've been a big fan of MediaWiki and similar wiki-based text editors. I like the ability to quickly add text, collaborate, and share. However, there's always still the need for nicely formatted print output. Things like headers and footers (that say what I want them to say), page breaks, margins, etc.

Most solutions I've seen involve some sort of conversion to a intermediate print-media format (maybe MediaWiki to Microsoft Word or maybe some custom scripting that generates a PDF from the contents of a web page (with a lot of hard-coded references).

Is there any more generic solution that exists for this problem? Any framework that seeks to merge HTML and web content in general into a print media output format?

Any solutions, discussion regarding the pro's or con's, or whatever is welcome.


Update: I think CSS will only get me so far though... I've used CSS for similar type output (MediaWiki by default has a print format that hides much of the nav bar stuff). Think of a MediaWiki article though -- imagine me being able to tweak a tag in the content or something similar and now my margin is 1 inch instead of .5 inches. That's more along the lines of what I'm aiming for.

6 Answers

0 votes
answered Jan 6, 2009 by pfctdayelise

You may have heard of PediaPress, a company that has done a "wiki to print" (i.e PDF, but also ODF) deal with the Wikimedia Foundation. (See "Wikis Go Printable".) Their code is designed to work with MediaWiki and is open source.

But! It's even better than that. Check out this bookmarklet. You can use it to create PDFs or ODFs of any publicly-accessible MediaWiki page (maybe it needs the API to be enabled too...). And you can bundle multiple pages, from a single MediaWiki or multiple MediaWikis, into a single document. It's pretty freaking awesome in my book. :)

ETA: PediaPress have put significant work into making something that looks really nice to read. It's not just the equivalent of MediaWiki's printable version converted to PDF.

0 votes
answered Jan 15, 2009 by michael-haren

Using print CSS files is a really slick approach to reformatting pages for printing.

A lot of people fall back to PDF because it can be more powerful and easier.

For most things, though, I think CSS markup is simpler and easier.

Look at the source for pages in StackOverflow and you'll see references to media="print" (print.css)--a set of styles applied only when a browser prints the page.

<link href="/Content/print.css" rel="stylesheet" media="print" type="text/css" />

You can use these to hide navbars, ads (or show different ads). Do some basic pagination, etc.

If you need more control over things like margins, you have to go outside the browser (PDF, Word, XPS, etc.).

0 votes
answered Jan 15, 2009 by hudson

I've written a MediaWiki to LaTeX converter that tries to maintain the document structure of the source text. The document is then typeset with pdflatex to produce a very high quality, paginated document. Math markup is directly rendered by LaTeX, so the equations look great. The LaTeX documentclass / stylesheet is configurable from specialized commands in the wiki to directly control margins, page layout, fonts, extra packages and so on. This would fall in your second category of a custom script rather than a generic framework.

There are many others, such as the Extension:Pdf_Export that uses htmldoc. While it is more general, it does a very poor job of pagination and creates lots of widows and orphans, doesn't do optimal text justification and doesn't do indexes, figures, self-references, etc. Additionally, if you use <math> markup in MediaWiki it only includes the low-res PNG files.

princexml is specialized for MediaWiki and produces good looking documents, but isn't available under a Free license. Since it is a closed-source product, your ability to control the output is limited.

0 votes
answered Jan 15, 2009 by spas


could be something for you. It converts xml and html pages to pdf documents.

0 votes
answered Sep 15, 2017 by tgr

In general, use CSS print styles + some webpage-to-PDF tool (headless Chrome, Electron, wkhtmltopdf, Prince XML, or just your web browser's print to PDF feature if you don't need to automate it).

Specifically for MediaWiki, the ElectronPdfService extension does this for you. (Also, print styles are being rewritten right now; check back in a month or two for improved presentation.)

0 votes
answered Sep 15, 2017 by safavi
<style type="text/css">
    @media print {
        /***css rules for print mode ***/
        aside#sidebar, header[role="banner"], footer, #comments, #respond, #header-v1, .breadcrumbs, #footer-v1,.topbar-v1,.header-v1,.fcbtnremove {
            display: none;

        .container.content-xs {
            width: 98%;
            margin: 0px;
            padding: 0px;

    @media screen {
        /***css rules for screen , it is sometiems opposite of print mode ***/
        #header-v1, .breadcrumbs, #footer-v1,.topbar-v1,.header-v1 {
            display: block;

    table td , table th{text-align:center;vertical-align:middle}
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter