footer =
# category_sections = 0
forum_sections = 1
# topics_heading = 'Section heading above 30162764, 20878085, and 32279820'
work_dir = my_tps_reports
# delete = 1
url = https://example.zendesk.com
mail = pgibbons@example.com
password = dneib393fwEF3ifbsEXAMPLEdhb93dw343
is_token = true
### Usage
The script can be invoked with the following synopsis:
usage: zdf2pdf [-h] [-v] [-j JSON_FILE] [-f FORUMS] [-e ENTRIES]
[-r RUN_SECTION] [-l [FORUM_TO_LIST]] [-c CONFIG_FILE]
[-s STYLE_FILE] [-o OUTPUT_FILE] [-t TITLE] [-a AUTHOR]
[--date DATE] [--copyright COPYRIGHT]
[--title-class TITLE_CLASS] [--toc] [--pre-width PRE_WIDTH]
[--strip-empty] [-w WORK_DIR] [-d] [-u URL] [-m MAIL]
[-p [PASSWORD]] [-i]
optional arguments:
-h, --help show this help message and exit
-v, --verbose Verbose output
-j JSON_FILE Zendesk entries JSON file to convert to PDF
-f FORUMS Comma separated Forum IDs to download and convert to
PDF
-e ENTRIES Comma separated Entry IDs to download and convert to
PDF
-r RUN_SECTION Run pre-configured section in configuration file
-l [FORUM_TO_LIST] List a forum's entries by ID and title. If no forum ID
is supplied, list forums by ID and title
-c CONFIG_FILE Configuration file (overrides ~/.zdf2pdf.cfg)
-s STYLE_FILE Style file (CSS) to
-o OUTPUT_FILE Output filename (default: PCLOADLETTER.pdf)
-t TITLE Title to be added to the beginning of the PDF
-a AUTHOR Author line to be added to the beginning of the PDF
--date DATE Date line to be added to the beginning of the PDF
--copyright COPYRIGHT
Copyright line to be added to the beginning of the PDF
--title-class TITLE_CLASS
CSS class to be added to title page elements
--toc Generate a Table of Contents (default: false)
--pre-width PRE_WIDTH
Width to wrap contents of tags.
--strip-empty Strip empty tags. (default: false)
-w WORK_DIR Working directory in which to store JSON output and
images (default: temp dir)
-d, --delete Delete working directory at program exit (default: do
not delete)
-u URL URL of Zendesk (e.g. https://example.zendesk.com)
-m MAIL E-Mail address for Zendesk login
-p [PASSWORD] Password for Zendesk login
-i, --is-token Is token? Specify if password supplied a Zendesk token
Here are some basic zdf2pdf usage examples to get started:
#### Help
zdf2pdf -h
#### Listing forums
zdf2pdf -l
The output consists of a listing of forum identifiers and their titles:
20828562 Foo
20840027 Bar
Entries in a forum can also be listed:
zdf2pdf -l 20828562
The output consists of a listing of entry identifiers and their titles:
21460866 Baz
21442012 Qux
#### Generate PDF from Forums URL by Forum ID
To generate a PDF archive document directly from a particular forum URL and
save the PDF with a certain title and filename, execute zdf2pdf
with the `-f`, `-t`, and `-o` options:
zdf2pdf -f 20828562 -t "Great Justice" -o great_justice-v1.pdf
where the `-f` option specifies a Zendesk forum identifier, which is the
8-digit string that makes up part of a Zendesk forum URL. For example, in the
following URL:
https://example.zendesk.com/forums/20828562-foo
the forum identifier is **20828562**.
The `-t` option specifies a title for the PDF document, which appears in
the document text on a title page.
Finally, the `-o` option tells zdf2pdf to save the PDF with the filename
`great_justice-v1.pdf`.
#### Generate PDF from a Forums JSON File
To generate a PDF archive document from an existing JSON file containing
Zendesk forum entries, and give a custom title to the document,
execute zdf2pdf with the `-j` and `-t` options:
zdf2pdf -j my_file.json -t "Documentation Archive"
The above command will open the file `my_file.json`, and generate a PDF titled
"Documentation Archive", with the default filename PCLOADLETTER.pdf.
#### Generate PDF from Forums URL with Custom Style
To generate a PDF archive document directly from a particular forum URL, save
the PDF with a certain title and filename, and apply a custom CSS stylesheet
to the output, execute zdf2pdf with the `-f`, `-t`, `-o`, and `-s` options:
zdf2pdf -f 20828562 -t "Styled" -o styled.pdf -s ./style.css
where the `-f` option specifies a Zendesk forum identifier, which is the
8-digit string that makes up part of a Zendesk forum URL. For example, in the
following URL:
https://example.zendesk.com/forums/20828562-foo
the forum identifier is **20828562**.
The `-t` option specifies a title for the PDF document, which appears in the
document text.
The `-o` option tells zdf2pdf to save the PDF with the filename `styled.pdf`.
Finally, the `-s` option tells zdf2pdf to style the output with CSS from the
file `style.css` located in the present working directory.
## Notes
* zdf2pdf uses Zendesk API version 1 with JSON
* zdf2pdf depends on the following Python modules:
* beautifulsoup4
* httplib2
* simplejson
* xhtml2pdf
* zendesk (patched for forum support)
### TODO
I would like to pull in a templating utility and do away with all of the
command line options that provide structure and content. Additionally, I would
like for zdf2pdf and zdgrab to use the same configuration file and similar
options.
### Headers and Footers
The header and footer options are provided for the purpose of doing things like
page numbers. They provide the capability to inject HTML at the beginning of
the document which can be styled to suit various purposes. For example, page
numbers can be achieved by using an option like this in a config file:
footer =
And then using CSS such as:
@page {
-pdf-page-orientation: portrait;
-pdf-page-size: letter;
margin: 2cm;
}
@page regular {
-pdf-page-orientation: portrait;
-pdf-page-size: letter;
margin: 2cm 2cm 3cm 2cm;
@frame footer {
-pdf-frame-content: footer;
bottom: 1.5cm;
left: 2cm;
right: 2cm;
height: .6cm;
}
}
The above will result in a first page which does not contain a footer, and
following pages that do contain a footer. The footer will contain the PDF page
number.
### Resources
* zdf2pdf: https://github.com/basho/zdf2pdf
* Python Zendesk module: https://github.com/eventbrite/zendesk
* Zendesk Developer Site (For API information): http://developer.zendesk.com