This topic is locked
[SOLVED]

 Custom PDF with PDFmake.js not based on any page in Designer

2/24/2020 10:18:20 AM
PHPRunner General questions
mbintex author

Hi at all,
I would like to have button creating PDFs not based on any page in Designer.
As far as I can see, the PDF API doesn´t give me this option.
I tried calling the PDFMake-version from PHPrunner with no success.
Downloading the standard PDFMake version and integrating it via the footer file worked:
In the footer file I have:

<?php

echo "

<script type='text/javascript' charset='utf-8' src='include/pdfmake/pdfmake.min.js'></script>

<script type='text/javascript' charset='utf-8' src='include/pdfmake/vfs_fonts.js'></script>

...


And then a custom Button generating a nice PDF with headers and footers.



var dd = {

// a string or { width: number, height: number }

pageSize: 'A4',
// by default we use portrait, you can change it to landscape if you wish

pageOrientation: 'portrait',
// [left, top, right, bottom] or [horizontal, vertical] or just a number for equal margins

pageMargins: [ 57, 156, 57, 100 ],



defaultStyle: {

fontSize: 12,

alignment: 'left',

lineHeight: 1.2

},



header:

{ text: 'Company', alignment: 'center', margin: [57,14,0,0] },
footer: {

columns: [

{ stack: ['Company','teststr. 9', '99999 dudelhaus',' ','Deutschland'], width: 'auto', alignment: 'left', margin: [57,0,0,0] },

{ stack: ['Web: www.dudelhaus.de','Mail: info@dudelhaus.de', 'Tel.: 0342347324234'], width: 'auto', alignment: 'left', margin: [0,0,0,0] },

{ stack: ['Bankverbindung','Bank', 'IBAN', 'BIC'], width: 'auto', alignment: 'left', margin: [0,0,0,0] },

{ stack: ['Handelsregister','Stadt', 'Registernr', 'Geschäftsführer'], width: 'auto', alignment: 'left', margin: [0,0,57,0] },

],

margin: [0, 26, 57, 20],

columnGap: 10,

fontSize: 9

},
content: [

{ text: ' Absenderzeile', fontSize: 8},

{ stack: ['Anschrift1','Vorname Nachname', 'Strasse', ' ', 'PLZ Ort',' ',' ']},

{ text: 'Betreff', bold: 'true' },

{ text: 'Dudelhaus, den 28.2.2020', alignment: 'right' },

{ text: ' '},

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

'Der eigentliche Brieftext',

{ stack: [' ','Mit freundlichen Grüßen', 'Company', ' ',' ',' ', 'Martin Dudel',]},

]



}
pdfMake.createPdf(dd).open();


Since I don´t really like to have two PDFmake-versions in my output, questions are:

  • how could I use the built-in PDFmake version for custom PDFs not based on pages?

    or
  • why doesn´t it work with the built-in version?
    If there is no way currently, then this would be a feature wish: Ability to handle custom-coded document descriptions for PDF generation via the PDF API.

W
WilliamBDevClub member 2/24/2020

Include the PDFMake files the are supplied with PHPRunner via a code snippit on the page or like you have via header or footer to use on all pages.



echo "<script src='include/pdfmake/pdfmake.min.js'></script>";

echo "<script src='include/pdfmake/vfs_fonts.js'></script>";


Then via a button use PDF Make.



var dd={

content: [

'First paragraph',

'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'

]

};
pdfMake.createPdf( dd ).download("test.pdf");
mbintex author 2/24/2020

Great thanks.
Don´t know what I had done wrong trying with the built in version. Got a bunch of "roboto not found in virtual file system" and stuff like pdfmake not defined. Hell knows what I did :-)

mbintex author 2/24/2020

Have to correct myself.
The pdfmake.min.js of the project PDFmake was uploade and vfs_fonts.js. With that it worked.
As soon as I updload the PHPrunner version of pdfmake.min.js again, I get
"Uncaught Error: File 'Roboto-Regular.ttf' not found in virtual file system"