Page 1 of 1

Help with jspdf

Posted: Sat Oct 16, 2021 12:16 pm
by loulou2522
HI all
I try to implement directly JSPDF but it dosen't work; can someone Help me ?

Code: Select all

! require(["https://unpkg.com/jspdf@latest/dist/jspdf.umd.min.js"], function(jsPDF) {
!   window.jsPDF = jsPDF.jsPDF;
! });
!var doc = new jsPDF( 'p', 'mm','a4'); 
!doc.setFont("arial narrow");
!doc.setFontSize(15);
!alert(" Ligne 20");

! margins = { top : 80, bottom : 60, left : 60,width : 522 }; 


!// Optional - set properties on the document
!doc.setProperties({
!title: 'Title',
!subject: 'Anomalies',
!author: 'SEPA',
!keywords: 'erreur, javascript, web 2.0, ajax',
!creator: 'SPIDERBASIC'
!});
!doc.setFillColor(137, 252, 226);
!doc.setDrawColor(0);
; !doc.setLineWidth(1);
!doc.roundedRect(70, 10, 110, 10,2,2, 'DF'); // filled red square
!doc.text("Bordereau d'envoi Virements",120, 16, {align: 'center'});  //write text
! var generateData = function(amount) {
! var result = [];
! var data = {
!  coin: "1000",
!  game_group: "GameGroup",
!  game_name: "XPTO2",
!  game_version: "25",
!  machine_un: "204858611",
!  vlt: "0"
! };
! for (var i = 0; i < amount; i += 1) {
!  data.id = (i + 1).toString();
!  result.push(Object.assign({}, data));
!}
! return result;
!};

!function createHeaders(keys) {
! var result = [];
! for (var i = 0; i < keys.length; i += 1) {
! result.push({
!  id: keys[i],
! name: keys[i],
! prompt: keys[i],
! width: 65,
! align: "center",
! padding: 15
! });
!}
!return result;
!}
!var headers = createHeaders([
! "id",
! "coin",
! "game_group",
! "game_name",
! "game_version",
! "machine_un",
! "vlt"
!]);
;!var doc = new jsPDF({ putOnlyUsedFonts: true, orientation: "landscape");
!  doc.table(20, 30, generateData(100), headers, {
!    margins: {
!     top: 30,
!    bottom: 30
! },
! width: 60,
! autoSize: true,
! printHeaders: true,
! rowMargin: 0,
! rowHeight: 12,
! headerRowHeight: 10,
! fontSize: 11} );
!  pages = doc.internal.getNumberOfPages();
! pageWidth = doc.internal.pageSize.width;  //Optional
! pageHeight = doc.internal.pageSize.height;  //Optional
!for (let j = 1; j < pages + 1 ; j++) {
!     let horizontalPos = pageWidth / 2;  //Can be fixed number
!    let verticalPos = pageHeight - 10;  //Can be fixed number
!   doc.setPage(j);
!  if (j>1) {
!doc.setDrawColor(0);
!doc.setFillColor(137, 252, 226);
!doc.roundedRect(70, 10, 110, 10,2,2, 'DF'); // filled red square
!doc.setFontSize(15);
!doc.text("Bordereau d'envoi Virements",120, 16, {align: 'center'});  //write text
!doc.setFontSize(12);
! }
!  doc.text("Pages "+j+ '/' + pages, horizontalPos, verticalPos, {align: 'right'});
!}
!// Then save

! doc.save("test.pdf");
Browser return the following error
Uncaught ReferenceError: jsPDF is not defined
at SpiderLaunch (spiderbasic.js:275)
at SpiderMain (main.js:24)
at main.js:41
at fa (dojo.js:19)
at dojo.js:20
at ga (dojo.js:20)
at da (dojo.js:20)
at s (dojo.js:22)
at HTMLScriptElement.<anonymous> (dojo.js:27)
Thanks in advance to help me solving these problem

Re: Help with jspdf

Posted: Sat Oct 16, 2021 2:24 pm
by Peter

Code: Select all

Procedure Main()
  
  !var doc = new jsPDF( 'p', 'mm','a4'); 
  !doc.setFont("arial narrow");
  !doc.setFontSize(15);
  !alert(" Ligne 20");
  
  ! margins = { top : 80, bottom : 60, left : 60,width : 522 }; 
  
  
  !// Optional - set properties on the document
  !doc.setProperties({
  !title: 'Title',
  !subject: 'Anomalies',
  !author: 'SEPA',
  !keywords: 'erreur, javascript, web 2.0, ajax',
  !creator: 'SPIDERBASIC'
  !});
  !doc.setFillColor(137, 252, 226);
  !doc.setDrawColor(0);
  ; !doc.setLineWidth(1);
  !doc.roundedRect(70, 10, 110, 10,2,2, 'DF'); // filled red square
  !doc.text("Bordereau d'envoi Virements",120, 16, {align: 'center'});  //write text
  ! var generateData = function(amount) {
  ! var result = [];
  ! var data = {
  !  coin: "1000",
  !  game_group: "GameGroup",
  !  game_name: "XPTO2",
  !  game_version: "25",
  !  machine_un: "204858611",
  !  vlt: "0"
  ! };
  ! for (var i = 0; i < amount; i += 1) {
  !  data.id = (i + 1).toString();
  !  result.push(Object.assign({}, data));
  !}
  ! return result;
  !};
  
  !function createHeaders(keys) {
  ! var result = [];
  ! for (var i = 0; i < keys.length; i += 1) {
  ! result.push({
  !  id: keys[i],
  ! name: keys[i],
  ! prompt: keys[i],
  ! width: 65,
  ! align: "center",
  ! padding: 15
  ! });
  !}
  !return result;
  !}
  !var headers = createHeaders([
  ! "id",
  ! "coin",
  ! "game_group",
  ! "game_name",
  ! "game_version",
  ! "machine_un",
  ! "vlt"
  !]);
  ;!var doc = new jsPDF({ putOnlyUsedFonts: true, orientation: "landscape");
  !  doc.table(20, 30, generateData(100), headers, {
  !    margins: {
  !     top: 30,
  !    bottom: 30
  ! },
  ! width: 60,
  ! autoSize: true,
  ! printHeaders: true,
  ! rowMargin: 0,
  ! rowHeight: 12,
  ! headerRowHeight: 10,
  ! fontSize: 11} );
  !  pages = doc.internal.getNumberOfPages();
  ! pageWidth = doc.internal.pageSize.width;  //Optional
  ! pageHeight = doc.internal.pageSize.height;  //Optional
  !for (let j = 1; j < pages + 1 ; j++) {
  !     let horizontalPos = pageWidth / 2;  //Can be fixed number
  !    let verticalPos = pageHeight - 10;  //Can be fixed number
  !   doc.setPage(j);
  !  if (j>1) {
  !doc.setDrawColor(0);
  !doc.setFillColor(137, 252, 226);
  !doc.roundedRect(70, 10, 110, 10,2,2, 'DF'); // filled red square
  !doc.setFontSize(15);
  !doc.text("Bordereau d'envoi Virements",120, 16, {align: 'center'});  //write text
  !doc.setFontSize(12);
  ! }
  !  doc.text("Pages "+j+ '/' + pages, horizontalPos, verticalPos, {align: 'right'});
  !}
  !// Then save
  
  ! doc.save("test.pdf");
  
EndProcedure

! require(["https://unpkg.com/jspdf@latest/dist/jspdf.umd.min.js"], function(jsPDF) {
!   window.jsPDF = jsPDF.jsPDF;
Main()
! });
P.S.: Don't open new threads for the same problem all the time.

Re: Help with jspdf

Posted: Sat Oct 16, 2021 2:36 pm
by loulou2522
Right Peter,
I have deleted the duplicate Post.Thnaks that's work now
Have a good wek end