anywhere
Posts: 40
Joined: Tue Sep 08, 2020 3:04 am

Create PDF from Data

Hi

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Re: Create PDF from Data

Hello,

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

anywhere
Posts: 40
Joined: Tue Sep 08, 2020 3:04 am

Re: Create PDF from Data

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

anywhere
Posts: 40
Joined: Tue Sep 08, 2020 3:04 am

Re: Create PDF from Data

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

Galyna Abramovych
Site Admin
Posts: 84
Joined: Tue Mar 22, 2016 6:03 pm

Re: Create PDF from Data

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

anywhere
Posts: 40
Joined: Tue Sep 08, 2020 3:04 am

Re: Create PDF from Data

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.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Re: Create PDF from Data

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).

anywhere
Posts: 40
Joined: Tue Sep 08, 2020 3:04 am

Re: Create PDF from Data

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

Return to “Issues”