Changes between Initial Version and Version 1 of TracWikiPrintPlugin/WikiPrintXhtml2pdf


Ignore:
Timestamp:
May 20, 2021, 7:02:51 AM (3 years ago)
Author:
Cinc-th
Comment:

Move current description to a separate page because current trunk no longer uses xhtml2pdf and has a different feature set.

Legend:

Unmodified
Added
Removed
Modified
  • TracWikiPrintPlugin/WikiPrintXhtml2pdf

    v1 v1  
     1[[PageOutline(2-5,Contents,pullout)]]
     2
     3= Make Trac wiki pages printable
     4
     5== Description
     6
     7This plugin allows you to make Trac wiki pages easily printable, exporting to '''PDF''' (book or article format) or printable '''HTML''' format (page contents without Trac headers/footers). PDF export is based on pure Python libraries, such as [http://www.xhtml2pdf.com/ xhtml2pdf], instead of depending on external applications.
     8
     9Key features:
     10 * Fully customizable header/footers for PDF.
     11 * Syntax highlighting in exported format, using [http://pygments.org/ Pygments].
     12 * Customizable front page for PDF book format.
     13 * Automatic creation of Table of Contents if `[[PageOutline]]` or `[[TOC]]` macro is used.
     14 * The style of the resulting PDF or HTML can be fully customized using CSS files.
     15
     16See also TracWikiToPdfPlugin.
     17
     18== Bugs/Feature Requests
     19
     20Existing bugs and feature requests for TracWikiPrintPlugin are [report:9?COMPONENT=TracWikiPrintPlugin here].
     21
     22If you have any issues, create a [/newticket?component=TracWikiPrintPlugin new ticket].
     23
     24[[TicketQuery(component=TracWikiPrintPlugin&group=type,format=progress)]]
     25
     26== Download
     27
     28Download the zipped source from [export:tracwikiprintplugin here].
     29
     30== Source
     31
     32You can check out TracWikiPrintPlugin from [/svn/tracwikiprintplugin here] using Subversion, or [source:tracwikiprintplugin browse the source] with Trac.
     33
     34The plugin is also available on [pypi:TracWikiPrint PyPi].
     35
     36=== Patches
     37
     38If you are running Windows with the IIS web server and you need to access resources locally and not via web browser (images, fonts), you may try the #9854 hotfix. Now in testing, please keep the ticket updated with results in order to release this.
     39
     40== Installation
     41
     42The syntax highlighting library [http://pygments.org/ Pygments] is optional.
     43
     44To install the plugin:
     45
     46{{{#!sh
     47$ pip install https://trac-hacks.org/svn/tracwikiprintplugin/1.0
     48}}}
     49
     50Enable the plugin by adding '''wikiprint.* = enabled''' in the ''components'' section of your `trac.ini` file:
     51
     52{{{#!ini
     53[components]
     54...
     55wikiprint.* = enabled
     56}}}
     57
     58After enabled, two new administrative panels will be available under the '''Wikiprint''' section, and 3 new formats will be available in the ''Download in other formats'' section at the end of the wiki page:
     59
     60 * PDF Article
     61 * PDF Book
     62 * Printable HTML
     63
     64== Configuration
     65
     66If you are behind a '''proxy''', add something like this to your .wsgi file so '''remote''' resources can be downloaded when creating pdfs:
     67
     68{{{#!python
     69import os
     70os.environ['http_proxy'] = 'http://myproxy.company.com:8080'
     71os.environ['no_proxy'] = '.company.com'
     72}}}
     73
     74If you're using '''Apache with authentication''', add something like this to your Apache .conf file, so '''local''' resources can be downloaded when creating pdfs, where `your.ip.address` is to be replaced with the output of `hostname -i`:
     75
     76{{{#!apache
     77...
     78 Require valid-user
     79 Order deny,allow
     80 Deny from all
     81 Allow from 127.0.0.1
     82 Allow from your.ip.address
     83 Satisfy any
     84...
     85}}}
     86
     87Additional options can be set by creating a ''wikiprint'' section in your `trac.ini` file:
     88
     89{{{#!ini
     90[wikiprint]
     91toc_title = Table of Contents
     92css_url = /path/to/file.css
     93article_css_url = /path/to/article.css
     94book_css_url = /path/to/book.css
     95frontpage_url = /path/to/frontpage.html
     96extracontent_url = /path/to/extracontent.html
     97httpauth_user = wikiprint_user
     98httpauth_password = *password*
     99
     100rebase_links = http://anotherserver.com/path
     101omit_links = false
     102}}}
     103
     104You can specify either local paths or remote urls for css and html files.
     105
     106Most of these options can be also set from the web administrative interface:
     107
     108[[Image(wiki:TracWikiPrintPlugin:admin_options.jpg, border=2)]]
     109
     110=== Customizing styles
     111
     112!WikiPrint allows customization of documents by three different options:
     113
     114 * '''css_url''': A path or URL to a file with CSS styles that will be applied to the exported output. If left blank, a default CSS is used. If you are creating a custom CSS, use the default CSS as start, and change as needed. Some tweaking is needed to make xhtml2pdf/PISA library generate PDF correctly.
     115 * '''article_css_url''': A path or URL to a file with CSS styles that will be used only when exporting to '''PDF Article''' format. The default one defines the page margins, and creates ''header'' and ''footer'' frames, which contents will be defined in the ''extracontent_url'' file.
     116 * '''book_css_url''': A path or URL to a file with CSS styles that will be used only when exporting to '''PDF Book''' format. The default one defines the default page with no header or footer, which will be used for the front page, and a ''standard'' templage page, which will be used for successive pages, with header and footer.
     117
     118For more information about the styles that affect the PDF output, see the [attachment:"pisa-en.pdf" xhtml2pdf manual].
     119
     120=== Customizing front page, header, footer, contents
     121
     122 * '''frontpage_url''': A path or URL to a file with HTML. '''It doesn't have to be a well formed xhtml document, so don't include begin/end tags, body, etc., see the default one''', that will be used as the front page when exporting to ''PDF Book''. Some special tags can be used to insert the title, version, date, etc. See ''Tag Replacement''.
     123 * '''extracontent_url''': A path or URL to a file with HTML that will be inserted at the beginning of the document before passing it to to ''xhtml2pdf''. This should be used to define the contents of the '''header''' and '''footer'''. See xhtml2html documentation, and the default article CSS contents and default extra contents for an example.
     124
     125=== Authentication
     126
     127When using cookie based authentication, like AccountManager, the ''xhtml2pdf'' library is given a temporary cookie to authenticate the user, so the conversion process will have the same permissions as the user downloading the .pdf, but '''you must make sure that the project URL is accessible locally from the Trac server itself'''.
     128
     129Optionally, if HTTP Basic or Digest authentication is used, Wikiprint can be configured to log in using '''httpauth_user''' and '''httpauth_password''' options.
     130
     131Not available in administrative interface yet:
     132
     133 * '''rebase_links''': When generating PDF or printable HTML, change the base URL to the base URL specified with this option. Useful for changing local references (something like `http://localhost:8080`) to a global address (like `http://mycompany.com/trac`).
     134 * '''omit_links''': Remove internal wiki links from generated PDFs.
     135 * '''omit_macros''': A comma separated list of macro names that will be omitted when converting the wiki document to the selected output (PDF or printable HTML).
     136
     137== Permissions
     138
     139Wikiprint defines three new permissions:
     140
     141 * `WIKIPRINT_ADMIN`: Allow users to acces the ''Wikiprint Options'' admin page, and configure wikiprint options.
     142 * `WIKIPRINT_BOOK`: Allow users to access the ''Make Book'' admin page.
     143 * `WIKIPRINT_FILESYSTEM`: When setting up header, footer, style, etc. the user can enter a path to a file from the file system. For this to work, the user must have this `WIKIPRINT_FILESYSTEM` permission. Otherwise, this could pose a security risk, as the user might display ''/etc/passwd'' or critical files. This is not a WikiPrint problem, as anyone with `TRAC_ADMIN` permissions would be able to install and run a potentially insecure plugin. So, make sure you trust users with `TRAC_ADMIN` permissions and give `WIKIPRINT_FILESYSTEM` permission only to trusted users.
     144
     145== Exporting and formats
     146
     147!WikiPrint adds several download formats to the bottom of the wiki page. Following is the description of the available formats.
     148
     149=== PDF Article
     150
     151PDF article creates a PDF file out of the wiki page, with no ''front page''. Additional styles will be used from the CSS file defined in ''article_css'' option.
     152
     153If the page uses the ![[PageOutline]] macro, it will be replaced by a Table of Contents.
     154
     155PDF article can be used to combine several wiki pages too, from the administrative interface.
     156
     157=== PDF Book
     158
     159This format will create a book-like PDF document. A front page that can show title, subject, date and version is inserted at the beginning of the document. A 'Table of Contents' is also inserted after the front page. Any further occurrences of ![[PageOutline]] will be removed. Different wiki pages will be separated by a page break.
     160
     161This is specially useful for combining several wiki pages from the administrative interface:
     162
     163[[Image(wiki:TracWikiPrintPlugin:admin_makebook.jpg, border=2)]]
     164
     165=== Printable HTML
     166
     167This option will just convert to wiki text to HTML, and display it in the browser with some styles, so it can be printed directly from the browser.
     168
     169=== Combining pages
     170
     171When enabling the plugin, a new !WikiPrint panel will be available in the administration panel. From this panel, you can select a set of pages, and export them to any of the supported formats.
     172
     173You can specify a Title, Subject, Date and Version for the exported document.
     174
     175=== Tag replacement
     176
     177When defining the contents of the ''front page'' file (using HTML), or the ''extra contents'' file (HTML for header, footer or other frames), some special tags can be used, and they will be replaced before exporting the document.
     178
     179The following tags are supported:
     180
     181 * #TITLE: Replaced with the ''Title'' field when combining pages from the administrative interface, or replaced with the Page Name when exporting from the wiki.
     182 * #SUBJECT: Replaced with the ''Subject'' field when combining pages from the administrative interface, or blank when exporting from the wiki.
     183 * #DATE: Replaced with the ''Date'' field when combining pages from the administrative interface, or the current time when exporting from the wiki.
     184 * #VERSION: Replaced with the ''Version'' field when combining pages from the administrative interface, or the current page version when exporting from the wiki.
     185
     186== Notes
     187
     188=== xhtml2pdf special tags and styles
     189
     190!WikiPrint works by converting one or some Wiki pages to HTML, adding some CSS styles and replacing special tags, and then passing the output to the xhtml2pdf library, so in order to understand how to customize the output using CSS, and to use some special html tags used by xhtml2pdf, you'll have to check the [wiki:TracWikiPrintPlugin:attachment:pisa-en.pdf xhtml2pdf manual].
     191
     192Also, check the default ''css'' and ''extra_content'' files, as they provide usage examples. To see the contents of the default files, leave the corresponding field blank in the administration panel, and click the '''View''' button.
     193
     194=== Images and links
     195
     196!WikiPrint exports the wiki format to HTML first, then converts the HTML to PDF using the xhtml2pdf library. Links and image references in the wiki to html conversion are made as absolute URLS.
     197
     198To generate the PDF, the ''xhtml2pdf'' library will try to download the images from their absolute URL, exactly as your web browser would do. For example, if you access the Trac project from your browser using the URL `http://myserver/trac/myproject`, but the address of ''myserver'' is locally resolved at your workstation (via /etc/hosts or similar), and not globally known, then ''xhtml2pdf'' will fail to resolve ''myserver'' and won't be able to download the images from `http://myserver/trac/myproject/`. In that case, use the server IP instead.
     199
     200== Recent Changes
     201
     202[[ChangeLog(tracwikiprintplugin, 3)]]
     203
     204== Author/Contributors
     205
     206'''Author:''' [wiki:airadier] [[BR]]
     207'''Maintainer:''' [[Maintainer(TracWikiPrintPlugin)]] [[BR]]
     208'''Contributors:''' sdegrande