Skip to content

Commit 013195e

Browse files
author
Stephen
committed
v1.3
1 parent 39981fe commit 013195e

File tree

7 files changed

+71
-11
lines changed

7 files changed

+71
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Download the whole diretory and rename to "pdf_export". Then you can install it
2121

2222

2323
## Changelog
24+
* `v 1.3` - Support for svg header (requires newer TCPDF),Collection export, Title alignment, multiline formatting (respects line breaks)
2425
* `v 1.2` - Added notes on output, Font Awesome icon, cleanup of PDF layout, various code fixes, French language file.
2526
* `v 1.1` - Fields list config is now by include, not exclude. And order of fields determines order output to PDF.
2627
* `v 1.0` - Initial Release

hooks/all.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php function HookPdf_exportAllRender_actions_add_collection_option($top_actions,$options){
2+
global $lang,$pagename,$pdf_output,$pdf_output_only_annotated,$baseurl_short,$collection,$count_result;
3+
4+
$c=count($options);
5+
6+
if ($pdf_output || $count_result!=0){
7+
$data_attribute['url'] = sprintf('%splugins/pdf_export/pages/pdf_export_config.php?col=%s',
8+
$baseurl_short,
9+
$collection
10+
);
11+
$options[$c]['value']='pdf_export';
12+
$options[$c]['label']=$lang['pdfexportwithnotes'];
13+
$options[$c]['data_attr']=$data_attribute;
14+
15+
return $options;
16+
}
17+
}
18+
19+
?>

include/general.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,15 @@ public function MultiRow($left, $right) {
110110
$pageheight=$pagesize[1]=$height;
111111

112112
$pdf = new MYPDF("portrait", "in", $size, true, 'UTF-8', false);
113-
113+
$versionstrfile = file_get_contents($_SERVER["DOCUMENT_ROOT"].'/lib/tcpdf/composer.json');
114+
$jsonarray = json_decode($versionstrfile, true);
115+
$versionstring = $jsonarray['version'];
114116
if ($pdf_export_ttf_header_font_path) {
117+
if (version_compare($versionstring, '6.2.0', '>=')) {
118+
$ttf_header_font = TCPDF_FONTS::addTTFfont($_SERVER["DOCUMENT_ROOT"].'/'.$pdf_export_ttf_header_font_path);
119+
} else {
115120
$ttf_header_font = $pdf->addTTFfont($_SERVER["DOCUMENT_ROOT"].'/'.$pdf_export_ttf_header_font_path, 'TrueTypeUnicode', '', 32);
121+
}
116122
$pdf->SetFont($ttf_header_font, '', 15);
117123
} else {
118124
$pdf->SetFont('helvetica', 'B', 15,'',false);
@@ -169,15 +175,27 @@ public function MultiRow($left, $right) {
169175
$logourl = $pdf_export_logo_url;
170176
$filename_from_url = parse_url($logourl);
171177
$logoext = pathinfo($filename_from_url['path'], PATHINFO_EXTENSION);
178+
if (($logoext != 'svg') && ($logourl !='')) {
172179
$logosizes = getimagesize($logourl);
173180
$logoextension = image_type_to_extension($logosizes[2]);
174181
$logowidth = ($logosizes[0]/139.5);
175182
$logoheight = ($logosizes[1]/139.5);
183+
}
184+
if ($logourl !='') {
185+
if ($logoext == 'svg') {
186+
$pdf->ImageSVG($logourl,0,.3,$width-1,0,'','','C',0,true);
187+
} else {
176188
$pdf->Image($logourl,.5,.3,$logowidth,$logoheight,$logoext);
177-
$righttitle=str_replace("<br />","\n",strtoupper(i18n_get_translated($resourcedata['field'.$view_title_field])));
178-
$pdf->MultiCell(0,0, $righttitle, 0, 'L', 0, 1,.44,.8, true, 0);
189+
}}
190+
$righttitle=str_replace("\\r\\n","\n",strtoupper(i18n_get_translated($resourcedata['field'.$view_title_field])));
191+
$pdf->MultiCell(0,0, $righttitle, 0, 'L', 0, 1,.45,.8, true, 0,false,false);
179192
if ($pdf_export_ttf_list_font_path) {
180-
$ttf_list_font = $pdf->addTTFfont($_SERVER["DOCUMENT_ROOT"].'/'.$pdf_export_ttf_list_font_path, 'TrueTypeUnicode', '', 32);
193+
if (version_compare($versionstring, '6.2.0', '>=')) {
194+
$ttf_list_font = TCPDF_FONTS::addTTFfont($_SERVER["DOCUMENT_ROOT"].'/'.$pdf_export_ttf_list_font_path);
195+
} else {
196+
// old style for prior version of TCPDF
197+
$ttf_list_font = $pdf->addTTFfont($_SERVER["DOCUMENT_ROOT"].'/'.$pdf_export_ttf_list_font_path,'','','','',3,1,false,false);
198+
}
181199
$pdf->SetFont($ttf_list_font, '', 10);
182200
} else {
183201
$pdf->SetFont('helvetica', '', 10,'',false);
@@ -205,22 +223,22 @@ public function MultiRow($left, $right) {
205223
$notepages=1; // Normally notes will all fit on one page, but may not
206224
if ($onetimenotes) {
207225
$pdf->SetLineStyle($style1);
208-
$pdf->MultiRow($lang["onetimenotes"],$onetimenotes);
226+
$pdf->MultiRow($lang["onetimenotes"],str_replace("\\r\\n","\n",$onetimenotes));
209227
$ypos=$pdf->GetY();
210228
$pdf->SetY($ypos);
211229
$pdf->Line(.5,$ypos,$pdf->getPageWidth()-.5,$ypos);
212230
}
213231
foreach ($includearr as $include) {
214232
$fieldsf = get_field($include);
215233
// If the notes took us to a new page, return to the image page before marking annotation
216-
if($notepages>1){$pdf->setPage($currentpdfpage);}
234+
//if($notepages>1){$pdf->setPage($currentpdfpage);}
217235

218236
$ypos=$pdf->GetY();
219237

220238
$pdf->SetY($ypos);
221239
$pdf->SetLineStyle($style);
222240
// If the notes went over the page, we went back to image for annotation, so we need to return to the page with the last row of the table before adding next row
223-
if($notepages>1){$pdf->setPage($currentpdfpage+($notepages-1));}
241+
//if($notepages>1){$pdf->setPage($currentpdfpage+($notepages-1));}
224242
if (($whereabouts)&&($include =='w')) {
225243
$pdf->MultiRow($whereabouts[0]['title'],ltrim(trim($whereabouts[0]['value']),','));
226244
} else {

languages/en.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@
88
$lang['pdfexportwithnotes']="PDF Export";
99
$lang["pdf_exportpdfconfig"]="PDF Export Configuration";
1010
$lang["pdf_exportpdfintrotext"]="Select the page size for your PDF.<br /><br />Configure other options <a href='/plugins/pdf_export/pages/setup.php'>here</a>.";
11-
$lang["pdf_export_logo_url"]="PDF header image (URL)";
11+
if (file_exists($_SERVER["DOCUMENT_ROOT"].'/lib/tcpdf/composer.json')) {
12+
$versionstrfile = file_get_contents($_SERVER["DOCUMENT_ROOT"].'/lib/tcpdf/composer.json');
13+
$jsonarray = json_decode($versionstrfile, true);
14+
$versionstring = $jsonarray['version'];
15+
} else {
16+
$versionstring = 99999999;
17+
}
18+
if (version_compare($versionstring, '6.1.0', '>=')) {
19+
$lang["pdf_export_logo_url"]="PDF header image (URL)<br />Supports jpg, png, and svg<br /><br />";
20+
} else {
21+
$lang["pdf_export_logo_url"]="PDF header image (URL)<br />Supports jpg and png<br /><br />";
22+
}
1223
$lang["pdf_export_fields_include"]="Fields to include from the export<br />(use ref IDs of <a href='/pages/admin/admin_resource_type_fields.php'>metadata fields</a>, comma separated and in order you want them to appear)<br /><br />";
1324
$lang["pdf_export_ttf_header_font_path"]="Header font conversion from ttf (filepath)<br />(relative to webroot)<br /><br />";
1425
$lang["pdf_export_ttf_list_font_path"]="List font conversion from ttf (filepath)<br />(relative to webroot)<br /><br />";

languages/fr.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@
88
$lang['pdfexportwithnotes']="PDF Export";
99
$lang["pdf_exportpdfconfig"]="PDF Export Configuration";
1010
$lang["pdf_exportpdfintrotext"]="Choisissez la taille de page pour votre PDF.<br /><br />Vous pouvez configurer d'autres options <a href='/plugins/pdf_export/pages/setup.php'>ici</a>.";
11-
$lang["pdf_export_logo_url"]="Logo/Image d'en-tête pour le PDF (URL)";
11+
if (file_exists($_SERVER["DOCUMENT_ROOT"].'/lib/tcpdf/composer.json')) {
12+
$versionstrfile = file_get_contents($_SERVER["DOCUMENT_ROOT"].'/lib/tcpdf/composer.json');
13+
$jsonarray = json_decode($versionstrfile, true);
14+
$versionstring = $jsonarray['version'];
15+
} else {
16+
$versionstring = 99999999;
17+
}
18+
if (version_compare($versionstring, '6.1.0', '>=')) {
19+
$lang["pdf_export_logo_url"]="Logo/Image d'en-tête pour le PDF (URL)<br />Soutien de jpg, png, et svg<br /><br />";
20+
} else {
21+
$lang["pdf_export_logo_url"]="Logo/Image d'en-tête pour le PDF (URL)<br />Soutien de jpg et png<br /><br />";
22+
}
1223
$lang["pdf_export_fields_include"]="Champs de la base de données à inclure<br />(utilisez ref IDs de <a href='/pages/admin/admin_resource_type_fields.php'>métadonnées</a>, séparées par des virgules et dans l'ordre que vous voulez qu'ils apparaissent)<br /><br />";
1324
$lang["pdf_export_ttf_header_font_path"]="Police en-tete - convertir un fichier ttf<br />(chemin relatif à webroot)<br /><br />";
1425
$lang["pdf_export_ttf_list_font_path"]="Police de liste - convertir un fichier ttf<br />(chemin relatif à webroot)<br /><br />";

pages/pdf_export_config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// prune unnannotated resources if necessary
2929
$pdf_export=true;
3030

31-
if (count($resources)==0){$pdf_export=false;}
31+
//if (count($resources)==0){$pdf_export=false;}
3232

3333

3434
# Fetch search details (for next/back browsing and forwarding of search params)

pages/setup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
//$page_def[] = config_add_boolean_select('pdf_export_debug', $lang['pdf_exportdebug']);
2222
$page_def[] = config_add_text_input('pdf_export_logo_url', $lang["pdf_export_logo_url"]);
2323
$page_def[] = config_add_text_input('pdf_export_fields_include', $lang["pdf_export_fields_include"]);
24-
$page_def[] = config_add_text_input('pdf_export_imagesizeid', $lang["pdf_export_imagesizeid"]);
2524
// Integrate the whereabouts plugin
2625
if (isset($whereabouts_rt_exclude)) {
2726
$page_def[] = config_add_boolean_select('pdf_export_whereabouts_integration', $lang['pdf_export_whereabouts_integration']);
2827
}
28+
$page_def[] = config_add_text_input('pdf_export_imagesizeid', $lang["pdf_export_imagesizeid"]);
2929

3030
// Do the page generation ritual -- don't change this section.
3131
$upload_status = config_gen_setup_post($page_def, $plugin_name);

0 commit comments

Comments
 (0)