Html2pdf PDF template requires php only variables

I need some help.

I have successfully created a PDF report which works well. It is produced using Html2pdf. Here is an example 8_AD_Report.zip (237.3 KB)

Where I am having a problem is where I need to do a repeat or loop with images, typically about 6 images.

At the moment I use ServerConnect with a Single Query to query the DB, and then set a Session variable with the result as follows

The Session variable is used as follows to populate the report template

<?php echo $_SESSION['for_PDF']['job_your_ref']; ?>

The template can only use HTML, basic in-line CSS and PHP (so no DMX stuff)

This works well.

Where I am having a problem is where I need to do a repeat or loop of images, typically about 6 images.

I have a second query, which is a standard (Multi) DB Query which queries a separate table and returns the file names, directory, notes, sort order etc for the images, but this does not work the same as above, probably because these need to be set as a multi level array, or something :slight_smile:

This is where I am stuck. What do I need to do to get this to work?

image

I have now done a

print_r($_SESSION)

with the result (shown at the bottom), which is quite confusing, but I did notice the required elements such as

Array ( 
[sort_order] => 2 
[directory] => /web_upload/web_upload_4 
[image] => 20180412_160612.jpg 
[image_note] => This shows a bit more )

are showing towards the end.

I am not sure how to use it or get at it.

Array ( [s_current_user] => Array ( [0] => Array ( [user_login] => neil@neilrigby.com [user_password] => 123456 [data_security] => 160 [data_active] => 158 [data_editor] => 1 [data_created] => 2019-01-01 00:00:00 [data_modified] => 2019-08-13 17:25:47 [data_from] => 2019-10-16 00:00:00 [data_to] => [people_id] => 283 [people_type] => 227 [title] => Mr [forename] => Neil [midname] => [surname] => Rigby [nickname] => Neil [qualifications] => [dob] => 1963-07-19 [gender] => 250 [rainbow] => 244 [avatar] => [notes] => Great guy! ) ) [for_PDF] => Array ( [job_id] => 8 [business_id] => 394 [job_principal] => Penn Faraday Solicitors [job_principal_contact] => 193 [job_type] => 1 [job_our_ref] => Penn Faraday TNG 228F [job_your_ref] => PENNref [addr_writverb] => 40 [job_date_instr] => 2019-11-06 00:00:00 [job_date_instr_ampm] => 33 [job_date_acc] => 2019-11-04 00:00:00 [job_date_insp] => 2020-01-09 00:00:00 [job_date_rep] => 2020-03-09 00:00:00 [job_eng] => 198 [job_image_avail] => [job_in_hire] => 295 [job_in_storage] => 297 [cost_storage] => TBA [cost_recovery] => TBA [cost_transport] => TBA [job_expected_labour_rate] => [job_date_eng] => 2020-01-08 00:00:00 [addr_prefix] => [addr_name] => Jayne Price [addr_addr] => Heron House, The Village, Town DD5 7GT [owner_name] => Jayne Price 2 [vehicle_addr] => Heron House, The Village, Town DD5 7GT [addr_contact] => [index] => TNG 228F [job_loc] => [driv_rep_details] => The Village Garage, Town, WW4 7FR [driv_vat] => 299 [driv_cover] => 299 [driv_excess] => 299 [job_notes] =>
cbh jmfghj fghj fhg

[reported_damage] => Nearside scratches to door and wing and a bit more elsewhere [veh_make] => Ford Mondeo [veh_col] => White [veh_odom] => 36999 [veh_odom_note] => [veh_cc] => 1270 [veh_dofr] => 1988-05-06 00:00:00 [veh_vin] => UIYGFOIJH54H456 [val_retail_val] => 4587.00 [val_retail_odom] => 36999 [val_guide_price] => [val_trade_val] => 3356.00 [val_trade_odom] => 36999 [val_mp_high] => 3700.00 [val_mp_low] => 3200.00 [val_eng_val] => 3600.00 [val_eng_odom] => 36999 [val_salv_perc] => [val_salv_val] => 0.00 [charg_store] => [charg_rec] => [charg_trans] => [impact_temp_comm] =>
Temporary repairs could be completed if there is an unnecessary delay in commencing repairs.

[status_comments] => The cost to repair this vehicle would exceed 25% of its pre-accident value, because of this we would advise that the vehicle be dealt with on a Constructive Total Loss Basis. The vehicle was found to have a fair pre-accident condition consistent with age and mileage showing no obvious signs of pre-existing damage or corrosion? We have looked in the marketplace and feel that our valuation is a fair and accurate reserve. Temporary repairs could be completed if there is an unnecessary delay in settling the claim. [costs_lab_hrs] => 12 [costs_lab_rate] => 39.00 [costs_lab_costs] => 468.00 [costs_paint] => 252.00 [costs_parts] => 365.00 [costs_glass_num] => [costs_glass] => [costs_geo_type] => [costs_geo_val] => [costs_corrosion] => [costs_epa] => [costs_resets] => [specialist_grand_total] => 717.00 [costs_cont_rep] => 1802.00 [costs_agreed_vat] => 138 [costs_vat] => 360.40 [costs_anticipated] => 141 [costs_grand_total] => 2162.40 [costs_ceil_res_txt] => [costs_ceil_res_val] => 2280.00 [diag_diag_json] => [diag_diag_png] => [meth_replace] => Fog Lamp Surround, Indicator, Headlamp, Inner Wing, Wing Moulding, Arch Spat, N/S Road Wheel, O/S Road Wheel, N/S Tyre, O/S Tyre, [meth_repair] => N/S/R Door Foil, N/S/F Door Hinges, N/S/R Door Hinges, 1/4 Panel Moulding, Lamp Panel, Roof Section, [meth_paint] => O/S/F Door Hinges, O/S/R Door Hinges, [meth_blend] =>


[meth_specialist] => Anti Corrosion Protection (additional),Bumper P.D.C Sensors - basic,Bumper P.D.C Sensors - medium,Decal - Chassis number,Bumper P.D.C Sensors - premium,Decal Wrap - per panel [meth_specialist_ref] => 3_1,4_4,5_2,7_1,6_1,8_2 [meth_check] =>


[dec_comments] => [data_order] => 0 [data_security] => 160 [data_version] => 142 [data_active] => 158 [data_editor] => 1 [data_created] => 0000-00-00 00:00:00 [data_modified] => 2020-04-02 09:58:06 [data_from] => 1900-01-01 00:00:00 [data_to] => 0000-00-00 00:00:00 [driv_rep_status] => Contract Repair [veh_paint] => Pearl [veh_body] => MPV [veh_odom_unit] => miles [veh_cond] => Fair [veh_fuel] => BioDiesel [veh_trans] => Semi-Automatic [veh_taxi] => Hackney Carriage [stat_steer] => No Keys Available [stat_hand] => No Keys Available [stat_foot] => No Keys Available [val_glass] => Glass's Guide [impact_mag] => Light to Moderate [impact_area] => Near-Side Rear [impact_road] => No [impact_temp] => Yes [meth_jig] => Yes [meth_work_days] => 5 [stat_osf] => 3 [stat_osr] => 1.6 [stat_nsf] => 3 [stat_nsr] => 1.6 [job_eng_title] => [job_eng_forename] => Phil [job_eng_surname] => Goldring [job_eng_quals] => [val_eng_odom_unit] => kms [old_code] => #P01 [new_code] => PENN [our_ref] => Penn Faraday ) [login_secId] => 1 [forename] => Neil [surname] => Rigby [nickname] => Neil [for_PDF_imgs] => Array ( [0] => Array ( [sort_order] => [directory] => /web_upload/web_upload_4 [image] => 20180412_170245.jpg [image_note] => ) [1] => Array ( [sort_order] => [directory] => /web_upload/web_upload_4 [image] => 20180412_170252.jpg [image_note] => ) [2] => Array ( [sort_order] => 1 [directory] => /web_upload/web_upload_4 [image] => 20180412_160607.jpg [image_note] => This should be the first item listed ) [3] => Array ( [sort_order] => 2 [directory] => /web_upload/web_upload_4 [image] => 20180412_160612.jpg [image_note] => This shows a bit more ) [4] => Array ( [sort_order] => 3 [directory] => /web_upload/web_upload_4 [image] => 20180412_170211.jpg [image_note] => ) ) )

I am getting closer. I have now discovered that

<?php echo $_SESSION['for_PDF_imgs'][0]['image']; ?>

returns the expected result of ‘20180412_170245.jpg’.

Now I just need to work out how to loop over the array. Any suggestions? :slight_smile:

Yes, it would be really useful if there was a $index type variable attached to Server Actrion repeats in the same way as found in app connect.

I would simply define a variable and increment it with each iteration fo the loop

i.e.
set var count = 0
repeat
echo $_SESSION[‘for_PDF_imgs’][count][‘image’]
count=count+1

1 Like

Thanks Brian, that’s what I was alluding to but really wasn’t sure exactly how to do it.

Anyway, I have now got the result I wanted :slight_smile:

It took a few hours but am happy with the result. It still needs some layout issues sorting but that’s OK.

Here is the final bit of code, using a foreach loop, for those interested

	<table>
		<tr>
		<?php foreach ($_SESSION['for_PDF_imgs'] as $id => $value) { ?>
			<td style="padding: 0mm; margin: 0mm; width: 105mm;">
				<div style="padding: 0mm; margin: 0mm; width: 105mm;">
					<img src="..<?php echo $value['directory']; ?>/<?php echo $value['image']; ?>" style="width: 103mm; padding: 0; margin: 1mm;"></div>
				<div style="padding: 2mm 3mm 6mm 3mm; margin: 0mm; width: 99mm;"><?php echo 'Image '.($id+1); ?> <?php echo $value['image_note']; ?></div>
			</td>
		<?php if (($id+1) % 2 === 0 ) { ?>
		</tr>
	</table>
	<table>
		<tr>
		<?php } ?>
		<?php } ?>
		</tr>
	</table>

and the final PDF report is here showing a set of images imported 8_AD_Report_final.zip (6.4 MB)

3 Likes

We’ve integrated a client-side App Connect PDF Creator component in Wappler 6.3.0
Please check it and let us know what do you think: Using App Connect PDF Creator

Note that more options will be coming to it in the next updates!

This topic was automatically closed after 3 days. New replies are no longer allowed.