jspdf - Forum

Forum Navigation
You need to log in to create posts and topics.

jspdf

Good morning
I'm using the JsPdf library, I can create the pdf
but when I pass variables with numeric values to javascript the $App label is reported. plus the name of the variable declared in Visualneo.
I tried every way but the value contained in the variable does not appear.
This is the code

BeginJS

// Create a new jsPDF instance

var doc = new jsPDF();

// LINEA ORRIZZONTALE
doc.setLineWidth(1);
doc.line(5 , 5, 205, 5);
doc.line(5 , 292, 205, 292);
// LINEA VERTICALE
doc.line(5 , 5, 5, 292 );
doc.line(205 , 5, 205, 292 );

doc.setTextColor('#5f9ea0');
// Intesrtazione pagina

doc.text('Calcolo Materiale Fondazione', 70, 20);

// Intesrtazione campi tabella
doc.setTextColor('#a9a9a9');
doc.text('F1', 20, 50);
doc.text('L.F', 40, 50);
doc.text('B.F', 60, 50);
doc.text('H.F', 80, 50);
doc.text('CLS', 100, 50);

// prima riga fondazione1

doc.text('$App.TOT', 20, 60, );

// Save the PDF
doc.save('table.pdf');
EndJS

I used the library

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.4.1/jspdf.debug.js" integrity="sha512-6HmJ9Y5PZWQVCd4KUwIaSgtDskfsykB+Fvm8Nq98GVCMHstaVoX9jqDdwSyGCbmJy5eLs/DXgDE3SXRS+2B2yA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

 

this is the only library that works for me that allows me to download the pdf, both from Chrom and Visualneo.
I haven't compiled it yet to try it on Android.

I also tried using the jsPdf-Autotalet library
but it doesn't work, it's not compatible with the jspdf library I'm using, I can't find a compatible one.
If there are any suggestions.
I didn't solve it with neopdf.

@llazzari don't use quotation marks if you want to access the variable value:

doc.text($App.TOT, 20, 60, );

Regards.

Hey
I tried your method too.
if I declare the TOT variable as a string
( SetVar [TOT] "23")
doc.text( $App.TOT , 20, 60);
everything is fine, the PDF opens and the value is loaded.

in my case the value of TOT comes from input boxes, the variable is numeric, in this case it doesn't work, it doesn't download the PDF.
If I put it in quotes
doc.text( '$App.TOT', 20, 60); ,
the pdf opens but it gives me the string $App.TOT as a value.

SetVar [TOT] [LONG]*[WIDE]*[ALT]
LUNG-WIDE-ALT are input variables.

 

Thanks for the reply.
I tried the app on Android hoping it would work
but it doesn't work, I'll try to get some clarification
by the VoltBuilder platform staff.
Greetings

@llazzari

doc.text( $App.TOT , 20, 60);
everything is fine, the PDF opens and the value is loaded.

in my case the value of TOT comes from input boxes, the variable is numeric, in this case it doesn't work, it doesn't download the PDF.
If I put it in quotes
doc.text( '$App.TOT', 20, 60); ,
the pdf opens but it gives me the string $App.TOT as a value.

You need to convert the numeric value (specified in the numeric input box) to a string before passing it to the pdf library.

Here are two examples of how to do it (there may be more) ...

1)

... num to string
SetVar [numVar] 13456
BeginJS
   $App.strVar = $App.numVar.toString();
EndJS

... verify
TypeOf [numVar] [numVarType]
TypeOf [strVar] [strVarType]

AlertBox "result" "[numVar] = [numVarType]<br/>[strVar] = [strVarType]" ""

2)

... num to string
SetVar [numVar] 13456

SetVar [strVar] "xxx[numVar]"
StrReplace "[strVar]" "xxx" "" [strVar] ""

TypeOf [numVar] [numVarType]
TypeOf [strVar] [strVarType]

AlertBox "result" "[numVar] = [numVarType]<br/>[strVar] = [strVarType]" ""

 

luishp and llazzari have reacted to this post.
luishpllazzari