tips:pdfexport:htmldoc
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tips:pdfexport:htmldoc [2009-10-31 16:57] – Added a recursive version of the "HTMLDOC_variant" 90.184.79.243 | tips:pdfexport:htmldoc [2023-03-08 08:21] (current) – 2409:4070:4387:9f60:5d3e:e9b4:db59:c826 | ||
---|---|---|---|
Line 150: | Line 150: | ||
header(" | header(" | ||
</ | </ | ||
- | To retrieve images from the wiki server (relative links, hope that it won't cause security issues) (I had problems with PNG files, so I converted them into JPEG format). | + | To retrieve images from the wiki server (relative links, hope that it won't cause security issues) (I had problems with PNG files, so I converted them into JPEG format |
<code xml> | <code xml> | ||
$text = preg_replace("'< | $text = preg_replace("'< | ||
Line 520: | Line 520: | ||
header(" | header(" | ||
</ | </ | ||
- | |||
====== HTMLDOC recursive variant ====== | ====== HTMLDOC recursive variant ====== | ||
- | My problem was that i needed support for child page export. It therefore choose to modify / hack [[# | + | My problem was that i needed support for child page export. It therefore choose to modify / hack [[# |
- | It will thus perform a recursive export of your current page. This means, that any internal links will be followed and converted to PDF too. The internal links should copied to the PDF - meaning that they are click-able like they are in dokuwiki. | + | It will thus perform a recursive export of your current page. This means that any internal links will be followed and converted to PDF too. The internal links should copied to the PDF - meaning that they are click-able like they are in dokuwiki. |
- | * Follow the first 4 steps of [[#HTMLDOC]] (on this page) | + | * Follow the first steps of [[#An_HTMLDOC_variant]] (on this page) |
* Then insert this into " | * Then insert this into " | ||
function pdfmake($text) | function pdfmake($text) | ||
Line 536: | Line 535: | ||
$pdfmake_links = array(); | $pdfmake_links = array(); | ||
| | ||
- | | + | $pdfmake_recursion_level = 30; |
- | | + | |
$pdfmake_recursion_current = 0; | $pdfmake_recursion_current = 0; | ||
- | | + | // Now search for children. |
- | $text = pdfmake_children($text); | + | $text = pdfmake_children($text); |
- | | + | // And create the pdf |
- | pdfmake_inner($text); | + | pdfmake_inner($text); |
} | } | ||
function pdfmake_inner($text){ | function pdfmake_inner($text){ | ||
Line 555: | Line 553: | ||
# Convert text and toctitle to destination code-page | # Convert text and toctitle to destination code-page | ||
- | $text=iconv(" | + | $text=iconv(" |
# Change toctitle if needed | # Change toctitle if needed | ||
if ($conf[' | if ($conf[' | ||
Line 652: | Line 650: | ||
#convert using htmldoc | #convert using htmldoc | ||
- | $command = $conf[' | + | $command = $conf[' |
system($command); | system($command); | ||
system(" | system(" | ||
Line 661: | Line 660: | ||
header(" | header(" | ||
$fd = @fopen($filenameOutput," | $fd = @fopen($filenameOutput," | ||
+ | //Puke on error | ||
+ | if($fd == false) | ||
+ | { | ||
+ | print ' | ||
+ | exit; | ||
+ | } | ||
+ | |||
while(!feof($fd)){ | while(!feof($fd)){ | ||
echo fread($fd, | echo fread($fd, | ||
Line 667: | Line 673: | ||
#clean up temporary files | #clean up temporary files | ||
- | | + | system(" |
- | | + | system(" |
} | } | ||
Line 681: | Line 687: | ||
$links = array(); | $links = array(); | ||
| | ||
- | | + | $pdfmake_recursion_current += 1; |
- | //will contain all subpages at the end. | + | //echo ' |
- | $innerText = ''; | + | //will contain all subpages at the end. |
- | + | $innerText = ''; | |
- | //find all links on page | + | |
- | $regex_pattern = "/< | + | //find all links on page |
- | preg_match_all($regex_pattern, | + | $regex_pattern = "/< |
+ | preg_match_all($regex_pattern, | ||
//The matching pairs will be listed in matches[1]. Sort these matches, so that subnamspaces comes before their parent namespaces. | //The matching pairs will be listed in matches[1]. Sort these matches, so that subnamspaces comes before their parent namespaces. | ||
- | sort($matches[1]); | + | |
- | for($i=0; $i< count($matches[1]); | + | for($i=0; $i< count($matches[1]); |
//extract the internal dokuwiki id of the subpage. This is needed to perform the rendering | //extract the internal dokuwiki id of the subpage. This is needed to perform the rendering | ||
$link = substr($matches[1][$i], | $link = substr($matches[1][$i], | ||
+ | // echo $link, '< | ||
//Dont add a page which has already been included | //Dont add a page which has already been included | ||
if(!in_array($link, | if(!in_array($link, | ||
- | | + | |
- | if(substr($link, | + | |
- | $innerText .= p_wiki_xhtml($link,'', | + | |
| | ||
- | | + | |
- | $pdfmake_links[] = $link; | + | $pdfmake_links[] = $link; |
- | $links[] = $link; | + | $links[] = $link; |
- | } | + | |
- | } | + | |
- | } | + | } |
//Recurse into the next level of internal links | //Recurse into the next level of internal links | ||
if($pdfmake_recursion_current < $pdfmake_recursion_level) { | if($pdfmake_recursion_current < $pdfmake_recursion_level) { | ||
+ | //echo " | ||
$innerText = pdfmake_children($innerText); | $innerText = pdfmake_children($innerText); | ||
} | } | ||
Line 730: | Line 738: | ||
Remember that I only tested this on my own sever (on which it works). So expect bugs and / or strange behavior. | Remember that I only tested this on my own sever (on which it works). So expect bugs and / or strange behavior. | ||
+ | |||
+ | ===== Bug fixes ===== | ||
+ | Here follows a list of fixed bugs | ||
+ | * 2009-10-31: | ||
+ | * Fixed a bug in the command line which, on some pages, caused the PDF generation to fail. | ||
+ | * Fixed a bug with unconvertable UTF8 chars breaking pdf generation (chars like -> and <-) | ||
--- // | --- // | ||
+ | |||
====== HTMLDOC and OS X ====== | ====== HTMLDOC and OS X ====== | ||
Line 775: | Line 790: | ||
$filenameOutput=tempnam('',' | $filenameOutput=tempnam('',' | ||
</ | </ | ||
- | |||
====== HTMLDOC request ====== | ====== HTMLDOC request ====== | ||
I think that will be very useful if you can create a page with the list of wiki page to export and HTMLDOC export all these pages into a PDF file.\\ | I think that will be very useful if you can create a page with the list of wiki page to export and HTMLDOC export all these pages into a PDF file.\\ | ||
Line 789: | Line 803: | ||
So you can create pages from which you can extract a PDF file based on more wiki pages | So you can create pages from which you can extract a PDF file based on more wiki pages | ||
+ | |||
+ | **Check the** [[# | ||
===== Config problem with HTMLDOC variant ===== | ===== Config problem with HTMLDOC variant ===== | ||
Line 798: | Line 814: | ||
you have to declare all value in your '' | you have to declare all value in your '' | ||
+ | |||
+ | ===== Changes to the TOC ===== | ||
+ | |||
+ | Some recent changes in the core will break all the TOC-related code above, because [[https:// | ||
+ |
tips/pdfexport/htmldoc.1257004636.txt.gz · Last modified: 2009-10-31 16:57 by 90.184.79.243