Web pages to print media — solutions?

大城市里の小女人 提交于 2019-12-05 07:14:19

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.

http://www.princexml.com/

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

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.).

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.

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.)

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}
</style>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!