Page 1 of 1

Create PDF from Data

Posted: Tue Sep 15, 2020 3:32 pm
by anywhere

Hi

Is there a way I can create a pdf from a grid element containing data from a collection?
Thank you.


Re: Create PDF from Data

Posted: Thu Sep 17, 2020 10:01 am
by Serhii Kulibaba

Hello,

Yes, it is possible to do with some 3rd-party libraries like https://parall.ax/products/jspdf


Re: Create PDF from Data

Posted: Thu Sep 17, 2020 11:16 am
by anywhere

Thanks
I found Mr Rio jsPDF on github. It allows for creating of data within tables.


Re: Create PDF from Data

Posted: Sat Sep 19, 2020 12:28 pm
by anywhere

jsPDF does what I need but only in a web browser. It does not work on mobile.


Re: Create PDF from Data

Posted: Sun Sep 20, 2020 7:27 am
by Galyna Abramovych

Could you please describe the faulty behavior in more details? Do you get any error?


Re: Create PDF from Data

Posted: Tue Oct 13, 2020 9:31 am
by anywhere

Ok, if anyone needs to create a PDF from your data, this may help.
PROJECT TYPE JQM:
You will need jsPDF (https://github.com/MrRio/jsPDF) and autotable (
https://github.com/simonbengtsson/jsPDF-AutoTable) libraries
This is an example to get your data into PDF
function getData(sdate, eDate) {

db.transaction(function (rx) {

Code: Select all

var rows =[];
var query = "SELECT event, date, time, dVol, uVol, uUrge, lUrge, kind, activity FROM trackU WHERE date >= ? AND date <= ?";

    rx.executeSql(query, [sdate, eDate], function (rx, rs) {

        for(var x = 0; x < rs.rows.length; x++) {
            rows.push([rs.rows.item(x).event, rs.rows.item(x).date, rs.rows.item(x).time, rs.rows.item(x).dVol, rs.rows.item(x).uVol, rs.rows.item(x).uUrge, rs.rows.item(x).lUrge, rs.rows.item(x).kind, rs.rows.item(x).activity]);
         }
     var doc = new jsPDF('p', 'pt');
   doc.autoTable({
        head: [['Event', 'Date', 'Time', 'dVol', 'uVol', 'uUrge', 'lUrge', 'kind', 'activity']],
         body: rows,
         didDrawPage: function (data) {
            // Header
            doc.setFontSize(20);
            doc.setTextColor(40);
            doc.setFontStyle('normal');
            doc.text("You're In Control - My Bladder Diary", data.settings.margin.left + 10, 22);
        }
    });
    localStorage.setItem('pdf', doc.output());
    });
   
});

}

var startD = Apperyio.storage.dates.get("$['startDate']");
var endD = Apperyio.storage.dates.get("$['endDate']");
getData(startD, endD);
function myFunction() {


log.execute({});
}
setTimeout(myFunction, 1000);

Once you have the data in your LSV you can decide what to do with it. I push it into a file on the server and then I email it out to clients via sendinblue or simply open the file with window.open. to open it in your native pdf reader.

Hope that will help someone if they are stuck like I was.

At this stage you cant social share the pdf (or anything for that matter) as Appery does not support the Cordova Social Share plugin on JQM.


Re: Create PDF from Data

Posted: Wed Oct 14, 2020 1:31 pm
by Serhii Kulibaba

You are right, it might not work in the mobile application. Unfortunately, any help (and/or debugging) with your custom app code or logic as well as 3rd party Apache Cordova/PhoneGap plugins are not covered by our Support policy (https://docs.appery.io/docs/general-support-policy).
To get such help, you will need to consider purchasing Advisory Pack: (https://appery.io/services/#Advisory_Pack).


Re: Create PDF from Data

Posted: Wed Oct 14, 2020 1:52 pm
by anywhere

As an independent freelance developer, I certainly cant afford your Advisory Pack Especially not with the Rand/Dollar Exchange rate as it is.