getreidemuehlen
-


Hinweise


Antwort
 
LinkBack Themen-Optionen Thema durchsuchen
Alt 27.07.2004, 13:58   #1
TP-Supporter
 
Benutzerbild von CB.NET
 
Registriert seit: Jun 2003
Ort: Fürth
CB.NET macht sich hier sehr viel Mühe
Lightbulb

Workshop: Dynamische Erstellung von PDF mit php via LaTeX.


Hier folgt in Kürze ein Tutorial von feuervogel
__________________
Die perfekte Web-Applikation ist: sicher,skalierbar,schnell, anwenderfreundlich,intuitiv, wiederverwendbar,flexibel,transparent,umfassend,dynamisch, zuverlässig,einfach,modular,effizient, stabil,handhabbar,verteilt,robust, persistent,kollaborativ,mächtig,intelligent,leicht verwendbar,portierbar,erweiterbar,
fehlerfrei, und zu guter Letzt billig

Geändert von CB.NET (27.07.2004 um 15:10 Uhr).
CB.NET ist offline   Mit Zitat antworten
Linktipp

Alt 27.07.2004, 15:55   #2
TP-Senior
 
Registriert seit: Jun 2004
Ort: leipzig
feuervogel macht alles soweit korrekt
hallo!

da ich vermehrt beobachtet habe, dass das verlangen nach der erstellung von pdf-dateien via php besteht, hier mal eine kleine anleitung, auf die in späteren threads verlinkt werden kann.

pdfLaTeX ist ein programm, welches auf den meisten linux-kisten installiert ist. es benutzt so genannte .tex-dateien, welche mit jedem einfachen editor erstellt werden können, um daraus pdf-dateien zu erstellen. diese anleitung funktioniert aber auch unter windows, wenn latex installiert ist.

Wie diese tex-dateien aufgebaut sind, erkläre ich an dieser stelle nicht. es sei so viel gesagt: es ist eine html-ähnliche sprache um text zu formatieren. wer also html beherrscht, wird latex mit etwas fleiß schnell lernen.
Man kann sich in diesem tutorial einen kleinen überblick verschaffen.

ich empfehle folgenden weg, um sich diese tex-dateien zusammenzubasteln:
  1. man nehme eine template-engine , mit der man den inhalt eines templates nicht nur ausgeben, sondern auch in eine variable schmeißen kann.
  2. den inhalt dieser variablen schreibt man nun in eine temporäre datei mit der endung .tex .
  3. Nun lässt man den server für sich arbeiten. man übergibt nun dem programm pdflatex diese .tex-datei. dies kann auf 2 wegen geschehen:
    PHP-Code:
    //ohne ausgabe der systemmeldungen von pdflatex
    exec"pdflatex ./datei.tex" );
    //oder mit ausgabe
    system"pdflatex ./datei.tex" );
    //während der entwicklung sollte mit system() gearbeitet werden, damit man eventuelle fehlermeldungen sieht 
  4. Nun gibt es im verzeichnis der .tex datei eine gleichnamige .pdf datei und noch ein paar dateien mehr, was die genau bedeuten, kann man sich in einem latex-handbuch anlesen.
    diese datei kann wie folgt zum download angeboten werden (bei mir hat es zumindest so geklappt):
    PHP-Code:
    header("Content-Type: application/octet-stream");
    header("Content-Length: ".filesize"dateiname.pdf" ));
    header("Content-Disposition: attachment; filename=dateiname.pdf");
    readfile"./dateiname.pdf" ); 
    oder mit header() einfach auf die datei weiterleiten.

fehlerquellen:

* Schwierige Fragen zu LaTeX kann ich hier nicht beantworten, sucht euch dafür bitte ein Latex-Forum
* Falls schon eine pdf-datei besteht, die den namen der übergebenen .tex hat, wird keine neue pdf-datei erstellt. einmalige und temporäre dateinamen verwenden!
* Natürlich muss man system-befehle ausführen können, dürfte also nicht mit jedem mini-acount klappen.
* Die Pfadangabe zu der tex-datei ist relativ zum ausführenden php-script anzugeben!

so, ich hoffe, das hat ein paar menschen weiter gebracht, für anregungen/verbesserungsvorschläge/tipps bin ich offen und sie können hier gerne gepostet werden.

Problem Nr. 1: LaTeX muss mehrmals ausgeführt werden, falls ein Inhaltsverzeichnis erstellt werden soll.
__________________
BeCreated - Geduld und Zeit für Ihre Wünsche

Geändert von feuervogel (27.07.2004 um 16:00 Uhr).
feuervogel ist offline   Mit Zitat antworten
Alt 28.12.2004, 09:38   #3
TP-Newbie
 
Benutzerbild von Bedek
 
Registriert seit: Dec 2004
Ort: Poland
Bedek macht alles soweit korrekt
Hello - do you speak english ?
I'm poor in german.
I'm doing system which can create pdf from database data.
I'v got few problems, system works, but I don't now if can I ask you in english ?
Answer please on email bedek@o2.pl
Bedek ist offline   Mit Zitat antworten
Alt 28.12.2004, 10:12   #4
TP-Moderator
 
Benutzerbild von Stuck Mojo
 
Registriert seit: Feb 2001
Ort: Helmstedt/Wolfsburg
Stuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKE
Zitat:
Zitat von Bedek
Hello - do you speak english ?
I'v got few problems, system works, but I don't now if can I ask you in english ?
Try it ...but please stay in the forum...
Stuck Mojo ist offline   Mit Zitat antworten
Alt 29.12.2004, 09:53   #5
TP-Newbie
 
Benutzerbild von Bedek
 
Registriert seit: Dec 2004
Ort: Poland
Bedek macht alles soweit korrekt

pdflatex + php + smarty = pdf + :)


1) Get data from DB into variable $data

Code:
$data = array("A" => "green", "B" => "brown", "B" => "blue");
problems: none

2) Assign this data to Smarty:

Code:
$smarty->assign('data', $data);
problems:
1 - this works without problems until variable "$data" have no special (for latex) chars like # $ % .. which need to be replaced by \# \$ \% -this is needed for work of pdflatex with no crashes - it looks like it is trivial problem but it is not (for me) because if table "$data" has very complicated and unknown structure then replacing special chars in every its element can be problem.

solution:
1- needed :) very much !

3) Run the Smarty:

Code:
$contents = $smarty->fetch('main.tex');
where:
"$contents" - contents of tex file which later will be saved to "file.tex"
"main.tex" - smarty template

problems:
1 - in Smarty alike as in Latex there are this same special chars !!! : "}" and "{"

solution:
1 - in template for char "{" I use "<" and for char "}" I use ">" - this is very uncomfortably !! and makes template code very unclear

4) Save to file "file.tex" variable "$contents" (in this point I use simplification - you should use temporary and unique file name - this is needed for appropriate work of pdflatex)

5) Run pdflatex

Code:
exec('
TEXMFOUTPUT='.$temp_dir.' &&
export TEXMFOUTPUT &&
TEXINPUTS=:'.$temp_dir.' &&
export TEXINPUTS &&
'.$pdflatex_path.'  --interaction=batchmode '.$latex_file_path);
where:
"$temp_dir" - temporary directory with input .tex file and output .pdf file (and few other generated by pdflatex), this directory is unaccessible from web and writable/readable for server apache user
"$pdflatex_path" - path to the executable programm "pdflatex"
"$latex_file_path" - path to the .tex file - must be in "$temp_dir"

problem:
1 - this is not working in safe mode :( -
2 - "pdflatex" has no option to to set input and output directory

solution:
1- needed :) very much !
2 - I guess that there is way to change source code of pdflatex and add additional options to set output and input directory but if someone else would like to use this method of generating .pdf will need to have this changed source code of "pdflatex" :( - so only authors of "pdflatex" can change it in new version so all people will have this additional oprions

Some explanations:

I put input .tex file "file.tex" and output .pdf file into "$temp_dir" - this directory in unaccessible from web - very important !!! then outpu .pdf file is readed into webbrowser by using:

Code:
header('Content-type: application/pdf');
header('Content-Length: '.filesize($unique.'.pdf'));
readfile($unique.".pdf");
this is made to protect from reading .pdf file by other webusers (hint: use as "$unique" session_id of user)

Option "--interaction=batchmode" is absolutely needed ! - without it in most cases we will get no output .pdf file, because if "pdflatex" detect even smalles problems (this is often) will stop.

While debuging don't remove files from "$temp_dir" and if there is no output .pdf file (or the file is damaged) read carefully .log and .tex files.
After debuging add removing all old files from "$temp_dir" (there will be .log, .tex, .pdf, .aux and other)

problem:
There is additionally BIG problem if we use pictures in .pdf file - picture file need to be puted into "$temp_dir" and coverted into suitable format for latex -best is .jpg. For converting I'm using "convert" from ImageMagick but there are sometimes problems - "convert" hangs when picture file has resolution [DPI] set to 0 or 1. Normaly this is not happening.

solution:
help me

Code:
$cmd = $convert_path." -quality 100 -resample 72x72 -geometry '".$max_x."x".$max_y.">'"
." "$file_path
." ".$temp_dir.session_id().".".jpg;
where:
"$convert_path" - path to executable "convert"
"$max_x" - maximal horizontal size of picture (if is smaller there is no conversion)
"$max_y" - maximal vertical size of picture (if is smaller there is no conversion)
"$file_path" - path where oryginal file is stored

This conversion keeps proportion of picture.
Bedek ist offline   Mit Zitat antworten
Alt 29.12.2004, 10:14   #6
TP-Moderator
 
Benutzerbild von Stuck Mojo
 
Registriert seit: Feb 2001
Ort: Helmstedt/Wolfsburg
Stuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKE
ok... that was a long post

Here we go:

to 2.) Problem 1
write your own modifier for smarty - it is very easy... you should look at some modifiers that are already shipped by smarty. So you can use the modifier in the template. Another solution could be a recursive replace through this array.

to 3.) Problem 1
Try to find another kind of start- and endtags for smarty. Smarty supports also more than one character for its tags... <!-- and --> for example... or <# and #> ...

to 5.) Problem 1
Only possible if pdflatex and the directories are trusted by php... contact your admin.

Problem 2
Don't needed at all, cause you define it by the systemvars... what's the problem?

to ImageMagick)
Couldn't you test the DPI before converting? I don't really know ImageMagick... and... what is an Image with 1 or 0 DPI? 0 is impossible in an image...

Cu
Jan
Stuck Mojo ist offline   Mit Zitat antworten
Alt 29.12.2004, 12:16   #7
TP-Newbie
 
Benutzerbild von Bedek
 
Registriert seit: Dec 2004
Ort: Poland
Bedek macht alles soweit korrekt
to 2.) Problem 1
write your own modifier for smarty - it is very easy... you should look at some modifiers that are already shipped by smarty. So you can use the modifier in the template...


I'm not sure if this is good idea beacaus:
1) I will need to modify smarty - what is not good, this makes all method not transferable - all who whant to use this method of generating .pdf will need to modify their smarty
2) I'm not sure if smarty modifier will work with multidemntional arrays structure - i think that they are good for single variables.
3) Using modifier is problem becasu I will need to use it i every template file - no there are 30 templates in my system but there will be more


...Another solution could be a recursive replace through this array

Yes that's the solution for my but how to replace recursive if I've got already filled with data array and I don't now its structure ?


to 3.) Problem 1
Try to find another kind of start- and endtags for smarty. Smarty supports also more than one character for its tags... <!-- and --> for example... or <# and #> ...


Sorry but this is not fixing the problem - the problem is still - unclear look of template source


to 5.) Problem 1
Only possible if pdflatex and the directories are trusted by php... contact your admin....


1) I'm the admin of my server
2) The is no problem with trusted directories - the problem is that if you even run such code:
Code:
system('
TEXMFOUTPUT='.$temp_dir.' &&
export TEXMFOUTPUT &&
TEXINPUTS=:'.$temp_dir.' &&
export TEXINPUTS &&
set);
in safe_mode it will give nothing - no error as well as no effect- so this command can't be executed in safe_mode


Problem 2
Don't needed at all, cause you define it by the systemvars... what's the problem?


1) Systemvars are different the my temporary directory wich must be accesible by apache user
2) Where you whant set this systemvars (in wich file) ? Command is executed for apache user ! not for user which is ovner of php source files.


to ImageMagick)
Couldn't you test the DPI before converting? I don't really know ImageMagick... and... what is an Image with 1 or 0 DPI? 0 is impossible in an image...


1) ImageMagic is one of the best progrmas for command line to convert image but fails in case if image has resolution 1 o 0 DPI.
2) It is possible that image has wrong header which describes image - 1 for 100 from internet - this makes no problems if you whant to open this image but if you whant to print them or conver it crash.
Bedek ist offline   Mit Zitat antworten
Alt 29.12.2004, 12:36   #8
TP-Moderator
 
Benutzerbild von Stuck Mojo
 
Registriert seit: Feb 2001
Ort: Helmstedt/Wolfsburg
Stuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKEStuck Mojo ist ein richtiges Arbeitstier - DANKE
@recursive:
PHP-Code:
function str_replace_rec($search$replace, &$subject) {
    if (
is_array($subject)) {
        foreach(
$subject AS $k => $v)
            
str_replace_rec($search$replace$subject[$k]);
    } else {
        
$subject str_replace($search$replace$subject);
    }

...not tested but this like it should run...

@unclear look of template source:
ehm... but you know that it woudn't work without that?

@safe mode:
If you're the admin of the server and set safe mode to on, you should know what you're doing ;-) ...Informations about safe mode can be found on http://www.php.net/manual/en/features.safe-mode.php ...especially the directive "safe_mode_exec_dir"
Stuck Mojo ist offline   Mit Zitat antworten
Antwort

  Aktuelles Thema
  TP Hilfe Forum > Web-Editoren & Coding > Traum-Dynamik > Workshops und Tutorials
Workshop: Dynamische Erstellung von PDF mit php via LaTeX. Workshop: Dynamische Erstellung von PDF mit php via LaTeX.
« PHP Tutorials von Mike als Offline Version | [Tutorial] Tokenizer »

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
 
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
PDF Datein zurückverwandeln.. Flixxtoras Webdesign & Co. 13 22.11.2004 14:16
Problem mit Einbau von FW htm Datein in DW puritive.de Fireworks 2 08.01.2004 23:45
Beginner Workshop: Einstieg in PHP & MYSQL mike Traum-Dynamik 24 22.11.2003 13:33
mit php auf dem Kriegsfuss (echo Befehl?) Storm Traum-Dynamik 4 26.02.2003 13:16
einfache dynamische Seite mit PHP erstellen... adrian Traum-Dynamik 0 28.04.2002 16:46


Alle Zeitangaben in WEZ +2. Es ist jetzt 00:40 Uhr.

Powered by: vBulletin Version 3.7 (Deutsch)
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd. / Search Engine Friendly URLs by vBSEO 3.2.0 RC7 ©2008, Crawlability, Inc.
Traum-Projekt.com | Suchen | Archiv | Impressum | Kontakt | | | Nach oben |



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67