Export firebase node data to pdf report

What is your mobile app emergency messaging system that uses Firebase as a backend. When the end of the emergency event ends, I would like to record the message log in the pdf document. I could not find any report editors that work with Firebase. This means that I may have to export this to php mysql. Firebase php SDK looks too much for this task. I got googling php get from firebase, and most of the answers are related to using Firebase php SDK. Is this the only way this can be done?

+5
source share
1 answer

You can use the PDF Kit ( ... ) on Cloud Functions (this is all nodeJS, there is no PHP there).

There are several packages on npmjs.com for @ firebase-ops , googleapis and @ google-cloud .

To read from Firebase and write to the Storage Bucket or Data Warehouse ; this example script will still require a link to the database and storage location in order to display the contents of the PDF (eventually from the template) and put it where it belongs. also see firebase / functions-samples (especially package.json , which defines dependencies). npm install -g firebase-tools installs the tools necessary for deployment; it also needs to be set to be locally famous (a pretty similar composer, while remotely they become known during the deployment process).

You will need a) Firebase Event onUpdate () as a trigger, b) check the endTime returned DeltaSnapshot for the value, and c) then draw and save the PDF. the code may be different, just to provide a rough idea of ​​how it works within a given environment:

 'use strict'; const admin = require('firebase-admin'); const functions = require('firebase-functions'); const PDFDocument = require('pdfkit'); const gcs = require('@google-cloud/storage')(); const bucket = gcs.bucket( 'some-bucket' ); const fs = require('fs'); // TODO: obtain a handle to the delta snapshot // TODO: render the report var pdf = new PDFDocument({ size: 'A4', info: {Title: 'Tile of File', Author: 'Author'} }); pdf.text('Emergency Incident Report'); pdf.pipe( // TODO: figure out how / where to store the file fs.createWriteStream( './path/to/file.pdf' ) ).on('finish', function () { console.log('PDF closed'); }); pdf.end(); 

external PHP code in this case, however, is not executed on the server side. the problem is that the external server will not provide any real-time trigger, so the file will not be displayed instantly when updating in time (as you would expect from a real-time database). you can also add external web hooks (or link them to PHP), for example. to receive these PDF files via HTTPS (or even generated by HTTPS request, for generation with an external call). for local testing, you can use the firebase serve command, it saves a lot of time and firebase deploy .

The fact is that you can teach Cloud Function how PDF files will look the same when they are created and where to put them, as a microservice that does nothing but to render these files. script one script should remain in the acceptable range, given all the hints provided.

+3
source

Source: https://habr.com/ru/post/1273476/


All Articles