HTML2PDF Speicherverzeichnis festlegen

Webmensch

Grünschnabel
Hey Leute,
ich hoffe das ist der richtige Bereich, ich war mir nicht sicher ob ich es in HTML oder PHP posten soll. Naja wie auch immer ...

Ich habe mit HTML2PDF ein PDF generieren lassen. Jetzt soll es automatisch benannt und gespeichert werden.
Das Benennen klappt super, allerdings funktioniert das Speichern nicht so wie es soll.
Es soll gleich in ein angegebenes Verzeichnis gespeichert werden, aber das funktioniert nicht, bzw. ich wüsste nicht wie ich es machen soll, da des z.b. C:\xampp\htdocs\kapp in Cxampphtdocskapp umwandelt
Ich hoffe ihr könnt mir helfen.

Das sind die Teile des Codes die das PDF im Allgemeinen festlegen:

PHP:
$html2pdf = new HTML2PDF('P','A4','de', true, 'UTF-8',array($links, $oben, $rechts, $unten));
$html2pdf->setDefaultFont('Arial');
$html2pdf->writeHTML($content, false);
$html2pdf->Output('wb_'.$sernr.'_0_'.$matnr.'_'.$ip.'.pdf', 'D');
 
Hi

Ich seh zwar nicht, wo du den Pfad da angibst,
aber versuch es einmal mit doppelten \\, also
C:\\xampp\\htdocs\\kapp\\irgendwas
 
Zuletzt bearbeitet:
HTML2PDF reicht den Output-Aufruf mehr oder weniger an TCPDF weiter. Aus der TCPDF-Doku zum $dest-Parameter:

(string) Destination where to send the document. It can take one of the following values:

I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
D: send to the browser and force a file download with the name given by name.
F: save to a local server file with the name given by name.
S: return the document as a string (name is ignored).
FI: equivalent to F + I option
FD: equivalent to F + D option
E: return the document as base64 mime multi-part email attachment (RFC 2045)

Das D steht für Download. Du suchst wohl eher F.

- http://www.tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1

Ansonsten: Ja, entweder den Backslash escapen "\\" oder Slashes verwenden ("C:/xampp/htdocs/..."). Die sollten auch zum Ziel führen.
 
Das D steht für Download. Du suchst wohl eher F.
Mit F kann ich nur auf dem Server speichern, allerdings würde ich gerne in einem Laufwerk speichern, welches nicht auf dem Server ist sondern im Intranet

Mit doppelten \\ geht es leider auch nicht

Es scheint so, dass HTML2PDF alle Sonderzeichen im Pfad löscht

Kann es sein dass es etwas hiermit zutun hat?

PHP:
 protected function _tag_open_PATH($param)
        {
            if (!$this->_isInDraw) throw new HTML2PDF_exception(8, 'PATH');

            $this->pdf->doTransform(isset($param['transform']) ? $this->_prepareTransform($param['transform']) : null);
            $this->parsingCss->save();
            $styles = $this->parsingCss->getSvgStyle('path', $param);
            $style = $this->pdf->svgSetStyle($styles);

            $path = isset($param['d']) ? $param['d'] : null;

            if ($path) {
                // prepare the path
                $path = str_replace(',', ' ', $path);
                $path = preg_replace('/([a-zA-Z])([0-9\.\-])/', '$1 $2', $path);
                $path = preg_replace('/([0-9\.])([a-zA-Z])/', '$1 $2', $path);
                $path = preg_replace('/[\s]+/', ' ', trim($path));
                $path = preg_replace('/ ([a-z]{2})/', '$1', $path);

                $path = explode(' ', $path);
                foreach ($path as $k => $v) {
                    $path[$k] = trim($v);
                    if ($path[$k]==='') unset($path[$k]);
                }
                $path = array_values($path);

                // read each actions in the path
                $actions = array();
                $action = array();
                $lastAction = null; // last action found
                for ($k=0; $k<count($path);true) {

                    // for this actions, we can not have multi coordonate
                    if (in_array($lastAction, array('z', 'Z'))) {
                        $lastAction = null;
                    }

                    // read the new action (forcing if no action before)
                    if (preg_match('/^[a-z]+$/i', $path[$k]) || $lastAction===null) {
                        $lastAction = $path[$k];
                        $k++;
                    }

                    // current action
                    $action = array();
                    $action[] = $lastAction;
                    switch($lastAction)
                    {
                        case 'C':
                        case 'c':
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+0], $this->_isInDraw['w']);    // x1
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+1], $this->_isInDraw['h']);    // y1
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+2], $this->_isInDraw['w']);    // x2
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+3], $this->_isInDraw['h']);    // y2
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+4], $this->_isInDraw['w']);    // x
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+5], $this->_isInDraw['h']);    // y
                            $k+= 6;
                            break;

                        case 'Q':
                        case 'S':
                        case 'q':
                        case 's':
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+0], $this->_isInDraw['w']);    // x2
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+1], $this->_isInDraw['h']);    // y2
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+2], $this->_isInDraw['w']);    // x
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+3], $this->_isInDraw['h']);    // y
                            $k+= 4;
                            break;

                        case 'A':
                        case 'a':
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+0], $this->_isInDraw['w']);    // rx
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+1], $this->_isInDraw['h']);    // ry
                            $action[] = 1.*$path[$k+2];                                                        // angle de deviation de l'axe X
                            $action[] = ($path[$k+3]=='1') ? 1 : 0;                                            // large-arc-flag
                            $action[] = ($path[$k+4]=='1') ? 1 : 0;                                            // sweep-flag
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+5], $this->_isInDraw['w']);    // x
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+6], $this->_isInDraw['h']);    // y
                            $k+= 7;
                            break;

                        case 'M':
                        case 'L':
                        case 'T':
                        case 'm':
                        case 'l':
                        case 't':
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+0], $this->_isInDraw['w']);    // x
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+1], $this->_isInDraw['h']);    // y
                            $k+= 2;
                            break;

                        case 'H':
                        case 'h':
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+0], $this->_isInDraw['w']);    // x
                            $k+= 1;
                            break;

                        case 'V':
                        case 'v':
                            $action[] = $this->parsingCss->ConvertToMM($path[$k+0], $this->_isInDraw['h']);    // y
                            $k+= 1;
                            break;

                        case 'z':
                        case 'Z':
                        default:
                            break;
                    }
                    // add the action
                    $actions[] = $action;
                }

                // drawing
                $this->pdf->svgPolygone($actions, $style);
            }

            $this->pdf->undoTransform();
            $this->parsingCss->load();
        }


Meines Wissens nach such und ersetzt preg_replace Sachen
 
Zuletzt bearbeitet:
Ne, der Code, den du da gefunden hast, scheint was mit dem Zeichnen/Übertragen von SVG-Pfaden zu tun zu haben.

- https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths

Mit F kann ich nur auf dem Server speichern, allerdings würde ich gerne in einem Laufwerk speichern, welches nicht auf dem Server ist sondern im Intranet

Wenn ich das richtig verstehe: Du kannst einen Server nicht vorgeben lassen, dass eine Datei auf dem Client/im Client-Netz automatisch an einer bestimmten Stelle gespeichert wird. Das ist ein grundlegendes Sicherheitsfeature. Sonst könnte dir halt jeder Hansel Dateien unterjubeln, die etwa was auf deinem Rechner überschreiben oder hinzufügen und dadurch Schaden anrichten.

Du müsstest schon immer im „Speichern unter…“-Dialog das passende Verzeichnis auswählen. Oder du schreibst dir auf dem Client ein Shell-Script oder dergleichen, das das PDF abfragt (das müsste dann wieder im Anzeige- oder im Download-Modus ausgeliefert werden) und an einer bestimmten Stelle ablegt. Das könntest du dann immer aufrufen, statt über den Browser zu gehen.

Edit: Mit wget (Linux) wäre das etwa bestenfalls ein Einzeiler:

Code:
wget -O /path/to/savedir/file.pdf http://example.org/doesnotexist/file.pdf
 
Zuletzt bearbeitet:
Ok, vielen Dank für die Hilfe. Ich habe herausgefunden dass ich über den Intranetserver auch auf dads Laufwerk zugreifen kann, also hat sich das geklärt :)
 
Zurück