0

fillable PDFs

Is there a easy way to complete fillable PDF forms and import them into Ninox?

 

Can you use importFile() with an http API request that returns a PDF file?

I am trying to use PDF Otter API to fill out a PDF form.

https://pdfotter.github.io/slate/?shell#introduction

 

I want to use data that is stored in Ninox to fill out the PDF forms.

I can't make importFile() work with the response. It seems to want a path to a file, not an api request that has a response that is a file.

Do I need to set up a system in the middle of Ninox and the PDF Otter API to make the request and store the file, then have Ninox import the file from that system?

 

The response header from PDF Otter looks like this

server:Cowboy

date:Tue, 30 Oct 2018 14:43:42 GMT

connection:keep-alive

x-frame-options:SAMEORIGIN

x-xss-protection:1;

mode=block

x-content-type-options:nosniff

content-type:application/pdf

content-disposition:attachment;

filename="abf9ba31-7fb4-4144-a1b9-05e87be35020.pdf"

content-transfer-encoding:binary

cache-control:private

x-request-id:4ede0fff-fb52-45ce-9043-242eb66b988d

x-runtime:0.622091

strict-transport-security:max-age=15552000;

includeSubDomainstransfer-encoding:chunked

via:1.1 vegur

6 replies

null
    • Mconneen
    • 5 yrs ago
    • Reported - view

    Interesting use case.   Where do plan to write the returned pdf file from 

    POST https://www.pdfotter.com/api/v1/pdf_templates/<ID>/fill

    In Ninox.. I do not see a raw write / export function.  I see printandSaveRecord .. Hmm.. 

    • blackie
    • 5 yrs ago
    • Reported - view

    got it to work by using a Raspberry Pi as the middle system. It was already running as a Node.js/Express print server to print labels from Ninox, so I added another endpoint for filling out PDF files. Ninox makes a request to the raspberry pi, the pi make the request to pdfOtter, PDFOtter responds with the PDF file which the raspberry pi places in it's webserver directory. The raspberry pi responds to Ninox with the url to the PDF.

    I needed to add a delay between the response from the raspberry pi because the PDF takes a few seconds to build and download. I wasn't sure what to do, so I used a dialog() as a delay.

    This is what the ninox button code looks like, minus the stuff to create the URL:

    let response := http("GET", url, {}, null);
    if response.error then
    alert(text(response.error))
    else
    dialog("Need a Delay!", "Are you Ready?", ["yes"]);
    Text := text(response.result);
    importFile(myID, text(response.result))
    end

     

    This is what the Express endpoint looks like on the raspberry pi side:

     

    // Express route for incoming requests for a list of all inputs
    app.get('/fill', function (req, res) {

    exec('curl -X POST https://www.pdfotter.com/api/v1/pdf_templates/tem_c214E5Y8Ycc3pM/fill \
    -u test_YOUR-API-KEY: \
    -d "data[nax]"='+ req.query.nax +' \
    -d "data[apx]"='+ req.query.apx +' \
    -d "data[rx]"='+ req.query.rx +' \
    -d "data[name]"='+ req.query.name +' \
    -d "data[phone]"='+ req.query.phone +' \
    -d "data[dob]"='+ req.query.dob +'\
    -d "data[homeAddress]"='+ req.query.homeAddress +' \
    -d "data[homeState]"='+ req.query.homeState +' \
    -d "data[homeCity]"='+ req.query.homeCity +' \
    -d "data[homeZip]"='+ req.query.homeZip +' \
    -d "data[mailAddress]"='+ req.query.mailAddress +' \
    -d "data[mailState]"='+ req.query.mailState +' \
    -d "data[mailCity]"='+ req.query.City +' \
    -d "data[mailZip]"='+ req.query.mailZip +'\
    -d "data[emailAddress]"='+ req.query.emailAddress +' \
    -d "data[ssn]"='+ req.query.ssn +' \
    -d "data[nfName]"='+ req.query.nfName +'\
    -d "data[nfx]"='+ req.query.nfx +' \
    -d "data[hName]"='+ req.query.hName +' \
    -d "data[hx]"='+ req.query.hx +' \
    -d "data[cFee]"='+ req.query.cFee +' \
    -d "data[pgx]"='+ req.query.pgx +' \
    -d "data[nop]"='+ req.query.nop +' \
    -d "data[cbcFee]"='+ req.query.cbcFee +' \
    -d "data[family1]"='+ req.query.family1 +' \
    -d "data[family2]"='+ req.query.family2 +' \
    -d "data[totalFee]"='+ req.query.totalFee +'\
    -d "data[clStreet]"='+ req.query.clStreet +'\
    -d "data[clState]"='+ req.query.clState +' \
    -d "data[clCity]"='+ req.query.clCity +' \
    -d "data[clCounty]"='+ req.query.clCounty +' \
    -d "data[clZip]"='+ req.query.clZip +' \
    -d "data[indoorx]"='+ req.query.indoorx +' \
    -d "data[indoorDescription]"='+ req.query.indoorDescription +' \
    -d "data[outdoorx]"='+ req.query.outdoorx +' \
    -d "data[outdoorDescription]"='+ req.query.outdoorDescription +'\
    -d "data[clpoName]"='+ req.query.clpoName +'\
    -d "data[clpoAddress]"='+ req.query.clpoAddress +' \
    -d "data[clpoZip]"='+ req.query.clpoZip +' \
    -d "data[clpoState]"='+ req.query.clpoCity +' \
    -d "data[clpoCounty]"='+ req.query.clpoCounty+'\
    -d "data[clpoCity]"='+ req.query.clpoCity +' \
    -d "data[cgName]"='+ req.query.cgName +' \
    -d "data[date]"='+ req.query.date +'\
    > /var/www/pdf/result.pdf', function (err,stdout,stderr){});

    console.log('printed http://192.168.1.31/pdf/result.pdf');
    res.status(200).send('http://192.168.1.31/pdf/result.pdf' );
    });

    • blackie
    • 5 yrs ago
    • Reported - view

    oh, this only with the ninox apps when they are on the LAN with the raspi pi.

    • Mconneen
    • 5 yrs ago
    • Reported - view

    You would probably have better success putting the dealy in the Node.js side.. then let it responsd that it was complete. 

    • blackie
    • 5 yrs ago
    • Reported - view

    Thanks. I changed some things around on the Node side so the response doesn't come until the curl command is funished. It seems to be working pretty well now.

     

    I changed 

     

    var child =require('child_process').exec(‘MY_LONG_CURL_COMMAND')
    child.stdout.pipe(process.stdout)
    child.on('exit',function(){

    console.log('Finished curl');
    res.status(200).send('http://192.168.1.31/pdf/result.pdf' );

    })

     

    This is the initial tutorial I based my raspberry pi Node.js stuff off of:

    http://www.robert-drummond.com/2013/05/08/how-to-build-a-restful-web-api-on-a-raspberry-pi-in-javascript-2/

    • blackie
    • 5 yrs ago
    • Reported - view

    I found a less complicated way to do what I wanted to do. I realized Ninox can treat a PDF as an image file.

     

    I split the PDF into single pages with PDFSAM, then create a print layout in Ninox that uses the PDF as a static image for the background.

     

    If I need to I merge the single PDF pages back together I use PDFSAM again.

Content aside

  • 5 yrs agoLast active
  • 6Replies
  • 3841Views