Forums

TCPDF - Multipage with background images and text from form field

gatekeepa123 28 Mar, 2018
I'm trying to have a chronoforms form generate a pdf document with two pages, then send this file via email and delete it on the server.

The pdf file is a template with one big image at the top of the first page and a small image in the bottom right corner of the second page, the message from the form field should be displayed starting at the second half of the second page (see attached images).




I think the simplest solution would be just to populate the second page of a pdf template with the message, but i dont know how to accomplish that.

So i'm working on a different aproach, where the pdf file is generated via TCPDF. I created two a4 fullpage jpgs (2480x3508 px, 300dpi) and added the following code to the TCPDF-action in the "submit" area in the chronoforms backend (the form field via the message has the value "nachricht" in the designer tab "name" and "id" fields:
​[pre]<style type="text/css"> * {margin:0; padding:0; text-indent:0; }
</style>[br][br]<img width="794" height="1123" alt="image" src="/administrator/pdf_images/Image_001.jpg"/>[br][br]<img width="794" height="1123" alt="image" src="/administrator/pdf_images/Image_002.jpg"/>[br][br]{nachricht}[/pre]

Screenshots of the chronoforms settings:








To get rid of the tcpdf header and footer I commented the following lines from /librariers/cetcpdf/tcpdf/tcpdf.php

Lines 4200 - 4208
 // print an ending header line - modified
//$this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
//$this->SetY((2.835 / $this->k) + max($imgy, $this->y));
//if ($this->rtl) {
// $this->SetX($this->original_rMargin);
//} else {
// $this->SetX($this->original_lMargin);
//}
//$this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');


Lines 4266 - 4273
 //Print page number - modified
if ($this->getRTL()) {
$this->SetX($this->original_rMargin);
// $this->Cell(0, 0, $pagenumtxt, 'T', 0, 'L');
} else {
$this->SetX($this->original_lMargin);
// $this->Cell(0, 0, $this->getAliasRightShift().$pagenumtxt, 'T', 0, 'R');
}

The first problem is, that the message from the form {nachricht} isn't shown in the generated PDF document, it just shows {nachricht}.

My second problem is, that the generated PDF file is generated with five (5!!!) pages:

1. first page is blank
2. second page shows the first image, which is correct
3. third page is blank
4. fourth page shows the second image, which is correct
5. fifth page shows {nachricht}

Can anyone help me with this?

Also, is it possible to use e.g. divs with background-image:"", so I can get the message to the right place on the PDF?

Thank you very much in advance,

Best regards!
[br]Joomla 3.8.6
Chronoforms Component 6.0.17
Max_admin 09 Apr, 2018
Hi gatekeepa123,

For the shortcode issue, you need to use {data:nachricht} instead to get the value from the form field.

What happens when you remove the style tags in the TCPDF content box ? make the code start with the <img tag directly, no spaces.

Best regards
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gatekeepa123 09 Apr, 2018
Hi,

{data:nachricht} works so far, thank you!

I removed the style tags and my TCPDF content now looks like this:
<p><img src="/pdf/Image_001.jpg" alt="image" width="794" height="1123" /> <img src="/pdf/Image_002.jpg" alt="image" width="794" height="1123" /> {data:nachricht}</p>
- First page is blank
- Second page shows only the content of {data:nachricht} in the top left corner

- The paragraph tags are added automatically, is that okay?
- Its very strange, that no image is shown now - what did I do wrong?
- Also, is it possible to use e.g. divs with background-image:"", so I can get the message on top of the fullscreen a4 image on the second page?
Max_admin 11 Apr, 2018
Hi Marc,

You can disable the editor to avoid changing your HTML, is the image path correct ?

The TCPDF library tries to render the HTML but you may need to do some testing in order to reach the output you like.

Best regards
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gatekeepa123 11 Apr, 2018
Hey Max,

path was correct and after some testing I got the result I wanted now; I think I had some problems because of the browser cache. Also the width and height attributes for the img-tags caused the problems with the blank pages.

For anyone interested, this is my dirty solution now:
<img src="/pdf/Image_001.jpg">
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<table cellpadding="0">
<tr>
<td width="10%" height="150px"></td>
<td width="80%" height="150px">{data:nachricht}</td>
<td width="10%" height="150px"></td>
</tr>
<tr>
<td width="100% height="100px"">
<br/><br/><br/><br/><br/><br/><br/><br/><br/>
<img src="/pdf/footer.jpg">
</td>
</tr>
</table>

On to the next step: I dont want to save the generated PDFs to the webserver but instead attach them to an email sent via chronoforms:




How can I setup the TCPDF-settings to avoid storage and what needs to be done to "Attachment settings" / "Attachment list" to send the file via email?

If it isn't possible to generate the email with attachment without storage: How do I delete the generated pdf from the webserver?

Best regards,

Marc
gatekeepa123 01 May, 2018
Is there any1, who can help me with this?

Update: Got to the point where the generated pdf i sent via email. My TCPDF action has the name tcpdf3 so I added {var:tcpdf3} to the Attachments list in the eMail-Action.

With the debugger I found the file path and file name stored in:
Array
(
    [validate_fields2] => Array
        (
            [log] => Automatic validation enabled.
            [var] => 1
        )

    [email4] => Array
        (
            [recipients] => Array
                (
                    [0] => _BLANKED_
                )

            [subject] => _BLANKED_
            [body] => _BLANKED_


            [files] => Array
                (
                    [0] => !!! FULL FILEPATH HERE /pdf/01-05-18-03-37-08.pdf !!!
                )

            [result] => the Mail sent successfully.
            [var] => 1
        )

)

--> How can I now delete the file after the eMail has been sent?

Best regards,

Marc
GreyHead 02 May, 2018
Hi Marc,

You can either add a PHP action after the Email action to delete it immediately; or, perhaps a little safer, run a cron job on your server every day to delete any saved tcpdf files more that say 48 hours old. That gives you a chance to re-send an email manually if something goes wrong.

Bob
gatekeepa123 02 May, 2018
Hey Bob,

I was thinking the same, but how do I get the filepath/filename from [files][0] and how can I then delete the file via php?

Thank you once again!
GreyHead 02 May, 2018
HI gatekeepa123,

To delete a file see the Joomla docs here, the path location you can see from your Debugger output.

Bob
gatekeepa123 02 May, 2018
Hey,

thank you for the docs link.

For the path/filename: Yes, I can see it; but how can I access the value in that array in CF6?

$form->data['email4']['files'][0]; comes up empty.

Marc
GreyHead 04 May, 2018
Hi Marc,

It seems that the TCPDF action doesn't show it's output in the CFv6 Debugger which is not helpful.

You can get the path to the saved file using {var:tcpdf999.path} - but replace tcpdf999 with the name of your TCPDF action.

Bob
gatekeepa123 04 May, 2018
Hey Bob,

thank you for taking a deeper look.

But how can I use the {var:tcpdf3.path} as a PHP value to use unlink?

Best regards,

Marc
GreyHead 04 May, 2018
Hi Marc,

You can use a PHP action in your form to run the Joomla! code I linked to earlier and use that variable to get the path to the file you need to delete.

Bob
gatekeepa123 08 May, 2018
Answer
1 Likes
Hey,

got it to work with this code:
$string = $this->get("tcpdf3.path");
$teile = explode("/", $string);
$filename = $teile[8];
$plorp = substr(strrchr($string,'/'), 1);
$path = substr($string, 0, - strlen($plorp));
JFile::delete($path.$filename);

Thank you everybody for the help in this thread.

Case closed!
This topic is locked and no more replies can be posted.