Opened 9 years ago

# Simplify the creation of multi-page documents

Reported by: Owned by: mvlcek Nickolas Grigoriadis high TracWikiToPdfPlugin normal patch 0.11

### Description

The patch allows the definition of a document on a wiki page like follows:

----

Anything between the two horizontal lines will be put on the title page.

The configured title page is not used.

----

In the section all linked pages are added to the document. The links must be in the following format:
* [wiki:Chapter1]
* [wiki:Chapter2]
* [wiki:Chapter3]
* ...
Everything besides the links is ignored.


### comment:1 Changed 9 years ago by mvlcek

Priority: normal → high

----

Anything between the two horizontal lines will be put on the title page.

The configured title page is not used.

----

The first header in this section is used as caption for the table of content

== Table of Content ==

In the section all linked pages are added to the document. The links must be in the following format:
* [wiki:Chapter1]
* [wiki:Chapter2]
* [wiki:Chapter3]
* ...
Everything besides the links is ignored.}}}


### comment:2 Changed 9 years ago by izzy

Will there be a similar patch (or the functionality added to the code) for 0.11?

### comment:3 Changed 9 years ago by Nickolas Grigoriadis

Owner: changed from Diorgenes Felipe Grzesiuk to Nickolas Grigoriadis new → assigned

I think that this functionality is very important for this plugin, I just don't know if this is the "right" way to do something like this.

I agree it should use a TOC-like structure, but maybe a macro/ or markup would be of more use?

Something like:

{{{
#!PDFBook
---
<Frontpage override, if you don't specify this it uses the default one>
---

Variables to replace data in frontpage.
Title = <blah>
Sub-Title = <blah>
Version = <blah>
Date = <blah>
If Date is not specified, it will automatically populate it with the generation date.

Pages = PageOne,PageTwo,Pages/*

Anything else is ignored.
}}}


The preprocessor by default returns blank back to Trac.

Download all documentation as [wiki:ThisPage?format=pdfbook PDF Book]


The issue is HOW, I'm not entirely sure how to do all this.

### comment:4 Changed 9 years ago by Nickolas Grigoriadis

mvlcek: Commit [5673] adds your patch for version 0.10 I cannot support 0.10 properly, since I didn't have a 0.10 installation for ages. Please check that is works fine. Thanks in advance, Grigi

### comment:5 Changed 9 years ago by anonymous

http://svn.ipd.uka.de/trac/javaparty/wiki/TracNav allows to specify such a page usable for the wiki.

if the macro text could be specified on the tracnav table of contents page it would be usable for both, (1) the wiki itself, and (2) printing pdf.

another possibility for specifying the contents would be the TagsPlugin, by using lists like [[ListTagged(macro -plugin)]].

### comment:6 Changed 9 years ago by Michael Medin

Keywords: patch added 0.10 → 0.11

I did a quick fix to add this support to the 0.11 branch. Now I am (as always) not a python/trac/* expert so take this for hat it is. There are also some issues with the title/subject (which are not set, but they are not set from the admin either so maybe I have configured something wrong). The relevant sections are the onse below, the patch has some other things I have played with as well (which might not be what everyone wants).

@@ -224,9 +230,48 @@
page = wiki_to_pdf(text, self.env, req, base_dir, codepage)

hfile, hfilename = mkstemp('wikitopdf')
-        os.write(hfile, page)
+       os.write(hfile, page)
os.close(hfile)

+       mo = None
+       if text.startswith('----'):
+               mo = re.match(r'\-+\r\n([^\-].*?)\r\n\-\-\-\-+\r\n([^\-].*?)\r\n\-\-\-\-+\r\n(.*)', text, re.DOTALL | re.MULTILINE)
+
+       if mo:
+               bookname = 'WikiToPdf'
+               title = 'WikiToPdf'
+               subject = 'WikiToPdf'
+               title = mo.group(2)
+               bn = re.match(r'.*?bookname\=(.*?)\r\n', mo.group(1), re.DOTALL | re.MULTILINE)
+               if bn:
+                       bookname = bn.group(1)
+               bn = re.match(r'.*?title\=(.*?)\r\n', mo.group(1), re.DOTALL | re.MULTILINE)
+               if bn:
+                       title = bn.group(1)
+               bn = re.match(r'.*?subject\=(.*?)\r\n', mo.group(1), re.DOTALL | re.MULTILINE)
+               if bn:
+                       subject = bn.group(1)
+               pages = [p for p in re.findall(r'$wiki:([^$ ]+)', mo.group(3))]
+               title_page = mo.group(1)
+
+               formats = {}
+               for provider in self.formats:
+                   for format, name in provider.wikitopdf_formats(req):
+                       formats[format] = {
+                           'name': name,
+                           'provider': provider,
+                       }
+                       self.env.log.error('TEST => Name: %s' % (name))
+
+               date = '2008-01-01'
+               version = '1.0'
+               format = 'pdf'
+
+               if not format or format not in formats:
+                       raise TracError('Bad format given for WikiToPdf output.')
+
+               return formats[format]['provider'].process_wikitopdf(req, format, title, subject, pages, date, version, bookname)
+
htmldoc_args = { 'webpage': '', 'format': 'pdf14', 'charset': codepage }
htmldoc_args.update(dict(self.env.config.options('wikitopdf-page')))