Skip to content

Commit cfa869d

Browse files
author
Stephen
committed
v1.7
new conf exclude title, fix if no logo, image to margin if full page
1 parent 48cf807 commit cfa869d

File tree

7 files changed

+34
-11
lines changed

7 files changed

+34
-11
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ Download the whole diretory and rename to "pdf_export". Then you can install it
1515

1616
- Resource Types to exclude (pick from list). This will hide PDF Export link from the view pages of those resources.
1717
- Fonts: can configure a filepath (relative to webroot, not a URL) to a custom font (ttf file) that sits on your server for heading (usually bold) and body/list text (usually regular).
18-
- URL to image to use as header (I would keep it to around 60px tall)
18+
- URL to image to use as header (I would keep it to around 60px tall)
19+
- Exclude title from top of PDF
1920
- Fields to include (2 fields, multiselect and comma separated list of metadata field IDs, ie: 67,73,78,etc)
2021
- Image size to use in PDF. Defaults to "hdr", but for some installs this is huge and unnecessary.
2122
- Set image height (inches)
2223
- Integration with [whereabouts plugin](https://github.com/ssuess/resourcespace-plugin-whereabouts) (if installed)
2324

2425

2526
## Changelog
27+
* `v 1.7` - New config exclude title, fix if no logo specified, allow full height image (to margin)
2628
* `v 1.6.1` - Fix broken collections output,fix SVG cutoff problem in header,fix header zero height problem, header space tweak
2729
* `v 1.6` - Set size and location of header. Better flow and positioning for all elements. Removed buggy newer TCPDF support, use more stable older version.
2830
* `v 1.5` - Set image height! Fixed horizontal image formatting on letter and legal.

config/config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
$pdf_export_admin_edit_access=array();
99
$pdf_export_logo_url ="";
1010
$pdf_export_logo_deets=".5,.3,0,.5";
11+
$pdf_export_exclude_title=false;
1112
$pdf_export_fields_include=array();
1213
$pdf_export_fields_include_hidden ="";
1314
$pdf_export_ttf_header_font_path="";

hooks/all.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ function HookPdf_exportAllAdditionalheaderjs(){
6262

6363
jQuery( "#jsonit" ).click(function( ) {
6464
var prejson = jQuery('#pdfconfigwrapper').find('input[name!="pdf_export_fields_include[]"][name!="pdf_export_rt_exclude[]"]').serializeArray();
65+
var titex = jQuery('#pdf_export_exclude_title').val();
66+
prejson.push({name:"pdf_export_exclude_title", value: titex});
6567
var confignamevalue = jQuery('#configname').val();
6668
var dataString = 'mydata=' + JSON.stringify(prejson) + '&configname='+ confignamevalue;
6769

include/general.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function create_pdf_export_pdf($ref,$is_collection=false,$size="letter",$cleanup
3636
# This leaves the pdfs and jpg previews in filestore/annotate so that they can be grabbed later.
3737
# $cleanup will result in a slightly different path that is not cleaned up afterwards.
3838

39-
global $pdf_export_logo_deets,$pdf_export_imgheight,$onetimenotes,$pdf_export_whereabouts_integration,$pdf_export_imagesizeid,$pdf_export_ttf_list_font_path,$pdf_export_ttf_header_font_path,$pdf_export_fields_include_hidden,$pdf_export_logo_url,$contact_sheet_preview_size,$pdf_output_only_annotated,$lang,$userfullname,$view_title_field,$baseurl,$imagemagick_path,$imagemagick_colorspace,$ghostscript_path,$previewpage,$storagedir,$storageurl,$pdf_export_font,$access,$k;
39+
global $pdf_export_exclude_title,$pdf_export_logo_deets,$pdf_export_imgheight,$onetimenotes,$pdf_export_whereabouts_integration,$pdf_export_imagesizeid,$pdf_export_ttf_list_font_path,$pdf_export_ttf_header_font_path,$pdf_export_fields_include_hidden,$pdf_export_logo_url,$contact_sheet_preview_size,$pdf_output_only_annotated,$lang,$userfullname,$view_title_field,$baseurl,$imagemagick_path,$imagemagick_colorspace,$ghostscript_path,$previewpage,$storagedir,$storageurl,$pdf_export_font,$access,$k;
4040
$date= date("m-d-Y h:i a");
4141

4242
include_once($storagedir.'/../include/search_functions.php');
@@ -124,16 +124,18 @@ public function MultiRow($left, $right) {
124124
$logourlvar = $configarray[2]['value'];
125125
$logodeetsvar=$configarray[3]['value'];
126126
$imagesizeidvar = $configarray[4]['value'];
127-
$pdf_export_imgheight = $configarray[5]['value'];
127+
$imageheightvar = $configarray[5]['value'];
128128
$exportfieldslistvar = $configarray[6]['value'];
129+
$excludetitlevar = $configarray[9]['value'];
129130
} else {
130131
$ttfheaderfontvar = $pdf_export_ttf_header_font_path;
131132
$ttflistfontvar = $pdf_export_ttf_list_font_path;
132133
$logourlvar = $pdf_export_logo_url;
133134
$logodeetsvar=$pdf_export_logo_deets;
134-
$pdf_export_imgheight=$pdf_export_imgheight;
135+
$imageheightvar=$pdf_export_imgheight;
135136
$imagesizeidvar = $pdf_export_imagesizeid;
136137
$exportfieldslistvar = $pdf_export_fields_include_hidden;
138+
$excludetitlevar = $pdf_export_exclude_title;
137139
}
138140

139141
// set document information
@@ -145,6 +147,7 @@ public function MultiRow($left, $right) {
145147
$pdf->setPrintHeader(false);
146148
$pdf->setPrintFooter(false);
147149
$pdf->setMargins(.5,.5,.5);
150+
$pdf->SetAutoPageBreak(TRUE, .5);
148151
if($logodeetsvar){
149152
$logodeetsarr=explode(",",$logodeetsvar);
150153
if ($logodeetsarr[0]) {
@@ -208,7 +211,7 @@ public function MultiRow($left, $right) {
208211
$hwratio=$imagesize[1]/$imagesize[0];
209212

210213
if ($whratio<1){
211-
$imageheight=$pdf_export_imgheight; // height variable
214+
$imageheight=$imageheightvar; // height variable
212215
$whratio=$imagesize[0]/$imagesize[1];
213216
$imagewidth=$imageheight*$whratio;}
214217
if ($whratio>=1 || $imagewidth>$width+1){
@@ -229,15 +232,19 @@ public function MultiRow($left, $right) {
229232
$pdf->ImageSVG($logourl,$mylogoleft,$mylogotop,$mylogowidth,$mylogoheight,'','','',0,true);
230233
} else {
231234
$pdf->Image($logourl,$mylogoleft,$mylogotop,$mylogowidth,$mylogoheight,$logoext);
232-
}}
235+
}
233236
$logofinalY = $pdf->getImageRBY()-.23;
237+
} else {
238+
$logofinalY = 0;
239+
}
234240
if ($ttfheaderfontvar) {
235241
$ttf_header_font = $pdf->addTTFfont('../../../'.$ttfheaderfontvar, 'TrueTypeUnicode', '', 32);
236242
$pdf->SetFont($ttf_header_font, '', 15);
237243
} else {
238244
$pdf->SetFont('helvetica', 'B', 15,'',false);
239245
}
240-
$ypos=$pdf->GetY();
246+
$ypos=$pdf->GetY();
247+
if ($excludetitlevar==0) {
241248
$righttitle=str_replace("\\r\\n","\n",strtoupper(i18n_get_translated($resourcedata['field'.$view_title_field])));
242249
$pdf->MultiCell(0,0, $righttitle, 0, 'L', 0, 1,.45,$ypos+$logofinalY, true, 0,false,false);
243250
// store current object
@@ -246,13 +253,22 @@ public function MultiRow($left, $right) {
246253
$lines = $pdf->MultiCell(0,0, $righttitle, 0, 'L', 0, 1,.45,$ypos+$logofinalY, true, 0,false,false);
247254
// restore previous object
248255
$pdf = $pdf->rollbackTransaction();
256+
} else {
257+
$lines = 0;
258+
}
249259
if ($ttflistfontvar) {
250260
$ttf_list_font = $pdf->addTTFfont('../../../'.$ttflistfontvar,'','','','',3,1,false,false);
251261
$pdf->SetFont($ttf_list_font, '', 10);
252262
} else {
253263
$pdf->SetFont('helvetica', '', 10,'',false);
254264
}
265+
if ($lines>0) {
255266
$titleheight = (($lines*0.20833333333334));
267+
$titlelineratio = ($titleheight/$lines);
268+
} else {
269+
$titleheight = -.27;
270+
$titlelineratio = .2;
271+
}
256272
$ypos=$logofinalY+.5+$titleheight+.5;$pdf->SetY($ypos);
257273
$pdf->Image($imgpath,.5,$ypos,$imagewidth,$imageheight,"jpg",$baseurl. '/?r=' . $ref);
258274
// set color for background
@@ -277,13 +293,13 @@ public function MultiRow($left, $right) {
277293
if ($onetimenotes) {
278294
$pdf->SetLineStyle($style1);
279295
$ypos=$pdf->GetY();
280-
$pdf->SetY($ypos+($titleheight/$lines)+.6);
296+
$pdf->SetY($ypos+($titlelineratio)+.6);
281297
$pdf->MultiRow($lang["onetimenotes"],str_replace("\\r\\n","\n",$onetimenotes));
282298
$ypos=$pdf->GetY();
283299
$pdf->SetY($ypos);
284300
$pdf->Line(.5,$ypos,$pdf->getPageWidth()-.5,$ypos);
285301
} else {
286-
$pdf->SetY($ypos+($titleheight/$lines)+.6);
302+
$pdf->SetY($ypos+($titlelineratio)+.6);
287303
}
288304
foreach ($includearr as $include) {
289305
$fieldsf = get_field($include);

languages/en.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
$lang["pdf_export_chooseconfig"]="Select a config to use: ";
1212
$lang["pdf_export_logo_url"]="PDF header image (URL)<br />Supports jpg, png, and svg<br /><br />";
1313
$lang["pdf_export_logo_deets"]="Header image: Left, Top, Width and Height in inches (numeric and comma separated, use 0 for auto calc of width/height)<br /><br />";
14+
$lang["pdf_export_exclude_title"]="Exclude file title from top of page.<br /><br />";
1415
$lang["pdf_export_fields_include"]="Fields to include in the export, in order<br /><br />";
1516
$lang["pdf_export_fields_include_hidden"]="This field just shows the IDs (see <a href='/pages/admin/admin_resource_type_fields.php'>here</a>) from fields you chose above. You can type or rearrange them by hand here to change the order above.<br /><br />";
1617
$lang["pdf_export_ttf_header_font_path"]="Header font conversion from ttf (filepath)<br />(relative to webroot)<br /><br />";

pages/savejsonconfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
error_log(getcwd() . "\n");
2+
//error_log(getcwd() . "\n");
33
// Do the include and authorization checking ritual -- don't change this section.
44
include '../../../include/db.php';
55
include_once '../../../include/general.php';
@@ -13,6 +13,6 @@
1313
$filename =$_POST['configname'];
1414

1515

16-
if (!file_exists("../../../filestore/pdf_export/jsonconfigs")){ mkdir("../../../filestore/pdf_export/jsonconfigs",0777);}
16+
if (!file_exists("../../../filestore/pdf_export/jsonconfigs")){ mkdir("../../../filestore/pdf_export/jsonconfigs",0755);}
1717

1818
file_put_contents("../../../filestore/pdf_export/jsonconfigs/".$filename .".json",$myconfig);

pages/setup.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
//$page_def[] = config_add_boolean_select('pdf_export_debug', $lang['pdf_exportdebug']);
2323
$page_def[] = config_add_text_input('pdf_export_logo_url', $lang["pdf_export_logo_url"]);
2424
$page_def[] = config_add_text_input('pdf_export_logo_deets', $lang["pdf_export_logo_deets"]);
25+
$page_def[] = config_add_boolean_select('pdf_export_exclude_title', $lang['pdf_export_exclude_title']);
2526
$page_def[] = config_add_text_input('pdf_export_imagesizeid', $lang["pdf_export_imagesizeid"]);
2627
$page_def[] = config_add_text_input('pdf_export_imgheight', $lang["pdf_export_imgheight"]);
2728

0 commit comments

Comments
 (0)