This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 3

[closed] PDF output - I really would like to find a solution


  1. timothykrulan
    Member

    Has anyone tried to redirect the output of the Review Enry Page to a file to create a pdf of the data? If so how has it worked for you?

    Thanks

    Posted 11 years ago #
  2. AMurray
    Pro Member

    There are many PDF creator scripts (written in PHP out there) but I don't know how easy to implement into Machform - specifically the review page.

    Someone with PHP skills on this forum might be able to give some pointers.

    First page of Google results searched for "web page to pdf PHP script":

    https://www.google.com.au/search?q=web+page+to+pdf+PHP+script&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

    Posted 11 years ago #
  3. shannonrobertson
    Member

    Well it’s not that simple, but luckily once again I had to do this so here is the code.
    I think that’s it for general modifications :).
    Here is the jist of what to do,
    Like everything this has a few downsides, a unsecured view form file,
    Uses a lot of resources when it runs,
    And you will still need to do a fair bit of work with css to get the output pdf looking a bit better.

    You will need
    http://code.google.com/p/dompdf/
    and https://github.com/thomasjbradley/signature-to-image/

    Step 1 placing the PDF link
    Go to entry-functions.php
    And replace these 2 lines

    $table_header_markup .= '<th class="me_action" scope="col"><input type="checkbox" value="1" name="col_select" id="col_select" /></th>'."\n";
    
    $table_body_markup .= '<td class="me_action"><input type="checkbox" id="entry_'.$column_data.'" name="entry_'.$column_data.'" value="1" /></td>'."\n";

    With

    $table_header_markup .= '<th class="me_action" scope="col"></th><th class="me_action" scope="col"><input type="checkbox" value="1" name="col_select" id="col_select" /></th>'."\n";
    
    $table_body_markup .= "<td ><a href='pdfbridge.php?form_id=".$form_id."&entry_id=".$column_data."'>".'PDF'."</a></td>".'<td class="me_action"><input type="checkbox" id="entry_'.$column_data.'" name="entry_'.$column_data.'" value="1" /></td>'."\n";

    Now you have a pdf link on your output rows.

    Step 2 the PDF bridge file
    Create a file called pdfbridge.php in the machforms root.

    And place this in there

    <?php
    
    include_once($_SERVER['DOCUMENT_ROOT'].'/dompdf/dompdf_config.inc.php');
    $form_id = $_GET['form_id'];
    $pdfentryid = $_GET['entry_id'];
    $html = file_get_contents("http://".$_SERVER["SERVER_NAME"]."/machform/view_pdf.php?form_id=".$form_id."&entry_id=".$pdfentryid);        
    
    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();
    $dompdf->stream('file.pdf');      
    
    header("http://".$_SERVER["SERVER_NAME"]."machform/manage_entries.php?id=".$form_id);
    ?>

    Step 3 the page we want the output PDF of,
    Now this is where the majority of the work will be.

    Copy view_entry.php and rename the new file to view_pdf.php

    Place this line in the includes section of view_pdf.php

    require_once './signature-to-image.php';

    and remove this line

    require('includes/check-session.php');

    replace this

    $signature_markup = <<<EOT
    									        <div id="mf_sigpad_{$element_id}" class="mf_sig_wrapper {$data['element_size']}">
    									          <canvas class="mf_canvas_pad" width="{$canvas_width}" height="{$canvas_height}"></canvas>
    									        </div>
    									        <script type="text/javascript">
    												$(function(){
    													var sigpad_options_{$element_id} = {
    										               drawOnly : true,
    										               displayOnly: true,
    										               bgColour: '#fff',
    										               penColour: '#000',
    										               output: '#element_{$element_id}',
    										               lineTop: {$line_margin_top},
    										               lineMargin: 10,
    										               validateFields: false
    										        	};
    										        	var sigpad_data_{$element_id} = {$data['value']};
    										      		$('#mf_sigpad_{$element_id}').signaturePad(sigpad_options_{$element_id}).regenerate(sigpad_data_{$element_id});
    												});
    											</script>
    EOT;

    with this

    $defaultOptions = array(
        'imageSize' => array($canvas_width, $canvas_height)
    
    );
    
    $img = sigJsonToImage($data['value'], $defaultOptions);
    
    imagepng($img, 'signature'.$element_id.'.png');
    
    			$signature_markup = <<<EOT
    									        <div id="mf_sigpad_{$element_id}" class="mf_sig_wrapper {$data['element_size']}">
    									        <img src="signature{$element_id}.png">
    									        </div>
    
    EOT;

    Take note 'imageSize' => array($canvas_width, $canvas_height) implies that you have a $canvas_width variable which isn't standard.

    This make the image become a png and saves it to the server so that the pdf can pick it up and attach.

    Finally add this to the top of signature-to-image.php

    ini_set('memory_limit', '-1');

    this gives signature-to-image php a lot more resources so it can render giant signature which I us in the sketch pad modification.

    This is a good start I probably forgot something but you should be able to work out what that might be. Also with the url’s they are matched to my system, so most likely they will need to be changed.

    Posted 11 years ago #
  4. DaveVoss
    Member

    Are you trying to capture the grid of all the entries or all of the informaion from one entry on the page where you view an entire entry?

    Posted 11 years ago #
  5. chinuba
    Member

    Is it possible to take the output of a form eg Name and address and input it to specific fields in the PDF?

    I am asking this because I have a contract that users should have but instead of mailing it to them, They can just input their name and address into the form and then it generates a PDF with the name and address in specific fields that the customer can download and print.

    Any help is appreciated.

    Posted 11 years ago #
  6. shannonrobertson
    Member

    It would probably be easier to make a form.
    have you contract text in a section break.
    have the section break hidden.
    then have the form emailed to them when it's complete.
    That way they can just print the email.

    Posted 11 years ago #
  7. timothykrulan
    Member

    What I want is to just take the page displayed on the confirmation and convert it to a pdf. Even better if I could get it without the SUBMIT and PREVIOUS buttons at the bottem.

    I found that all of the html for the confirm page is stored in $markup. I am currently writing this out to a unique file and start to play from there with converting it to a pdf..

    Posted 11 years ago #
  8. timothykrulan
    Member

    Ok - so here's where I stand on producing a pdf of the completed form ...

    The contents of $markup at then end of confirm.php will work for me as the pdf file. I would like it not to have the Submit and Previous footer included in it - but can live with that for now.

    I've installed wkhtmltopdf on the server (version 10 - not the current version becuase the current version did not convert the signature field properly without X being installed and running)

    I can write out $markup to a file and the use shell_exec to run the wkhtmltopdf command to convert the file to a pdf.

    I just want it to only run when the user clicks Submit for the last time after their review and the program is just about to write the data into the database.

    I just dont know where to fire off my code so it only happen once and at this time?

    Thanks

    Posted 11 years ago #
  9. yuniar

    You can edit the "confirm.php" and "confirm_embed.php" files (they are pretty much identical). Search around line 30 for this code:

    if(!empty($_POST['review_submit']) || !empty($_POST['review_submit_x'])){ //if form submitted

    You can put your code exactly below that line. It should be executed once, when the review page being submitted.


    MachForm Founder

    Posted 11 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.