Download the newest Extension using the Extension Manager/Extension Repository
Install the Extension using the Extension Manager
Configure the Extension.
install additional fonts for pdflib (sometime they are also needed for fpdf, i haven't found out when exactly yet. If you see an error message that a font can't be found, install them)
Update your .htaccess if you want to use “static” PDF filenames
You don't need to install the fpdf extension, the fpdf library is already included in this one.
If you want to use PDFlib you'll have to install additional fonts. This is most easily done by installing the pdf_generator2_fonts extension. They are packaged separately from the rest to keep the extension sizes manageable.
You will need to update your .htaccess if you want the links to your PDF files be static (i.e. <alias.pdf>). This change is necessary to forward all requests to /<...>.PDF files to typo3's index.php.
ErrorDocument 404 /error.html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^typo3$ /typo3/index_re.php
RewriteRule ^[^/]*\.html$ index.php
RewriteRule ^[^/]*\.pdf$ index.php
This parameter will define whether the link to the PDF files will be a static one (i.e. <alias>.pdf) or dynamic ones (index.php?id=12&type=123). If you enable this you will need to update your .htaccess.
If this parameter is set and you have gzip-compression turned on for the Frontend ( [FE][compressionLevel] in the installation tool) the generated PDF's will not be handled by the additional gzip-compression. It is highly recomended to leave this parameter at default (on) since PDF-files incorporate their own compression and you will only gain little additional compression. Additionally you may get problems with browsers that pass the stream to acrobat without decompressing it (e.g. Netscape 4.08).
To add the a link to the PDF page you can wrap any content element in a link using stdwrap.postUserFunc. The following code gives some examples:
[...]
100 = IMAGE
100.file = fileadmin/pdf_link.gif
100.stdWrap.postUserFunc = tx_pdfgenerator2->makePdfLink
[...]
[...]
110 = TEXT
110.value = printable version
110.postUserFunc = tx_pdfgenerator2->makePdfLink
110.postUserFunc.target = _blank
[...]
[...]
temp.PDF = TEXT
temp.PDF.value = pdf
temp.PDF.postUserFunc = tx_pdfgenerator2->makePdfLink
temp.PDF.postUserFunc.include_post_vars = 1
page.120 < temp.PRINT
[...]
If you use the Template Auto-Parser extension and you want to put the link somewhere on your page, you may need to put it in a COA with another element. If you want to place it below the content for example you would change
subparts.content < styles.content.get
to something like
subparts.content = COA
subparts.content {10 = CONTENT
10 < styles.content.get
20 < temp.PDF
}
and define temp.PDF like above.
Please note that the link will be generated as a USER_INT object by default, i.e. that the link will be generated after the page has been pulled from the cache. If you want to go for maximum performance you can disable that with the parameter postUserFunc.no_user_int = 1 which will generate and cache the link. This is only recommended if you are sure that there are no USER_INT objects on the page that set POST or GET parameters. If you don't understand what i'm writing about leave it at default.
Altenatively you can also use the function tx_pdfgenerator2->openPdfLink which will generate the opening tag for the link. You will need to generate the closing </a> tag yourself´. Example:
page.36= USER_INT
page.36.userFunc = tx_pdfgenerator2->openPdfLink
page.37=TEXT
page.37.value = Link to PDF
page.38=HTML
page.38.value = </a>
If you just need the target of the pdf link you can use the function getPdfTarget. Amongst other things this can be useful with templavoila. Example:
lib.pdflink = USER_INT
lib.pdflink.userFunc = tx_pdfgenerator2->getPdfTarget
lib.pdflink.userFunc.include_post_vars = 1
The PDF is rendered based on a very simple template. You can easily update the pdf_generator page object to contain additional information or content elements on every PDF page. One especially interesting use is to add special HTML comments to control the behavior of the html2pdf conversion. See the html2pdf documentation (on http://www.tufat.com/docs/html2ps/index.html) for details. A lot of parameters can be set via the Constant Editor (see next chapter).
You don't have to put any of the following lines into your template, they are already there. They are noted here just for reference purposes.
pdf_generator = PAGEpdf_generator { typeNum = {$extension.pdf_generator.typeNum} config.pageGenScript = EXT:pdf_generator/gen_pdf.php config.admPanel = 0 config.xhtml_cleaning = 0 config.USERNAME_substToken = config.ftu = 0 config.disableCharsetHeader = 1 config.prefixLocalAnchors = 0 50 = CONTENT 50 < styles.content.get}You can set several options on a per-template basis with the Constant Editor. These options will result in parameters used for the html2pdf conversion. The following parameters can be set:
Property: | Data type: | Description: | Default: |
|---|---|---|---|
browserwidth | string | If set controlls the width of the page in pixels. Set this to control scaling of tables and pictures. It defaults to 700 which will give roughly the same resolution as pages printed from Firefox or Internet Explorer. | 700 |
size | string | Sets the size of the generated PDF. The size can be Letter, Legal, Executive, B5, Folio, A0Oversize and A0 through A10 Custom sizes are specified by the page width and length in mm separated by the letter "x" like 210x297 | A4 |
landscape | boolean | Set this to true if you want to generate the page in landscape mode | False |
top | string | Specifies the top margin in mm. | 13 |
bottom | string | Specifies the bottom margin in mm. | 13 |
left | string | Specifies the left margin in mm. | 13 |
right | string | Specifies the right margin in mm. | 13 |
pdfversion | string | Specifies the PDF version to render to. | 1.3 |
use_pdflib | boolean | If this parameter is set the rendereing will be done with pdflib instead of fpdf. This will result in slightly different rendering results and times. You'll need to install additional fonts if you want to use this. | false |
cssmedia | String | Css can contain several different medias. Here you can select which one to use. | screen |
renderlinks | boolean | Define whether links are rendered clickable. | true |
renderfields | boolean | Define whether fields are rendered editable. May not be supported with dlib depending on the pdflib version. | true |
Rederforms | boolean | Define whether forms are rendered as dynamic pdf forms. Only supported with fpdf. | false |
string_search[1-4] | string | Using this parameter together with string_replace you can remove/replace certain parts of your html-file prior to passing it to the html2pdf conversion. One example is to remove the “Back” link in the recipe extension. You can do this (when using english language) with string_search1 = “<A href="javascript:history.go(-1);">Back</A>” and string_replace1 = “” You can actually use string_search[5-n] as long as they are all set | |
string_replace[1-4] | string | See string_search[1-4] | |
regexp_search[1-4] | string | The same as string_search, but for regular expressions. The search and replace parameters must be valid regular expressions that will be passed to preg_replace. You can actually use regexp_search[5-n] as long as they are all set | |
regexp_replace[1-4] | string | See regexp_search[1-4] |
Note that not all properties make sense for all functions. For example: the getPdfTarget function doesn't support the Target property.
Property: | Data type: | Description: | Default: |
|---|---|---|---|
attachment | int | This controls the setting for the Content-Disposition header. Normally a Content-Type: application/pdf Content-Disposition: inline header is generated. If this parameter is set to 1 Content-Type: application/pdf Content-Disposition: attachment and if it is set to 2 Content-Type: application/octet-stream Content-Disposition: attachment is sent instead. Option 1 will force Internet Explorer to open the PDF file in a new Acrobat Reader window. Netscape will open it inline (same as normal). If it is set to 2 both IE and Netscape will query the user what to do with the file. (Tested on win2k with IE6 and Netscape 7) The change is created by attaching a “attachment=<...>” parameter to the URL. | 0 |
filename | string | Sets the a filename for the Content-Disposition header. Since most browsers seem to ignore this it is of limited use. | |
include_post_vars | boolean | If set to 1 the received POST variables will be appended as GET variables to the URL. This is useful if you want to generate dynamic data (like search result for example). IMPORTANT NOTE: if you set this parameter it is possible that passwords and other sensible information will get encoded in the URL and thus be logged in proxy-logs for example. | false |
no_blur | boolean | If this is set, no onFocus="blurLink(this); code is added to the link. You can also use noBlur instead. | |
no_user_int | boolean | If set the generated link will not be a non-cached USER_INT object. Use this for slightly better performance if you have no frontend plugins that act as USER_INTobjects and set GET or POST variables. If you don't understand what i'm writing leave it at default. This parameter is only supported for the makePdfLink function. | false |
simulateStaticPdf | boolean | Overrides the global setting of the extension. | |
Target | string | Sets the target for the link | |
ATagParams | string | Ads additional parameters to the <a..> tag. |
You can force a page break by inserting any one of the following commands into the HTML page:
<!--NewPage-->
<pagebreak/>
<?page-break>
It is highly NOT RECOMMENDED to use these directives inside table cells, as you can get unpredictable results.
The following command performs a “section” break”.
<sectionbreak/>
Elements that are positioned fixed (i.e. on all pages), will only show up in the section they are declared in. Basically the body tag is split at the points where this command is found, the split up parts are then inserted in the original body tag again, thereby forming several new html-documents. If you keep this in mind, you'll also understand that tis command should only show up in places that are at the level below the body tag, otherwise you'll get unpredictable results
The following fields are rendered if the render fields checkbox in the constant editor is checked (default):
Name | Replaced with |
##PAGE## | Number of current page |
##PAGES## | Total number of pages in the generated PDF file |
##FILENAME## | Filename (URL) of the source HTML |
##FILESIZE## | Size of the source file (without included files) |
##TIMESTAMP## | Date/time the PDF file have been generated |