Skip to main content

Posts

Showing posts from August, 2020

fill in checkbox with pdf-lib

  https://github.com/Hopding/pdf-lib/issues/109 const fooCheckBox = findAcroFieldByName ( pdfDoc , 'FooCheckBox' ) ; const barCheckBox = findAcroFieldByName ( pdfDoc , 'BarCheckBox' ) ; const quxCheckBox = findAcroFieldByName ( pdfDoc , 'QuxCheckBox' ) ; const bazCheckBox = findAcroFieldByName ( pdfDoc , 'BazCheckBox' ) ; console . log ( 'Selecting "Foo" and "Qux" boxes...' ) ; fooCheckBox . set ( 'V' , PDFName . from ( 'Yes' ) ) ;

turn GraphQL mutation into promise - with parameters

export interface SigningProps { forms : Document [] todos ?: Document [] listingId : string listingAddress : Address addDocument ?: ( data : DocumentInput ) => void printPdf ?: ( data : PrintPdfInput ) => void fillInPdfForm : ( data : FillInPdfInput ) => Promise < string > deleteTodo ?: ( id : string ) => void }   function fillInPdfForm ( fillInPdfInput : FillInPdfInput ): Promise < string > { return new Promise (( resolve , reject ) => { fillInPdf ({ variables : { fillInPdfInput : fillInPdfInput , }, }) . then (( data : any ) => { const doc = { ... data . data . fillInPdf , created : new Date (). toString (), } setDocuments ([... documents , doc ]) const todoDocs = todoDocuments . filter ( todo => todo . name !== doc . name ) setTodoDocuments ( todoDocs ) resolve ( '' ) ...

pdf-lib node package for manipulate pdf template

  use pdf-lib to fill in pdf template: export const fillForm = async (pdfDoc: any, fieldNames: string[], fieldValues: string[]) =&gt; {   const form = pdfDoc.context.lookup(pdfDoc.catalog.get(PDFName.of('AcroForm')))   if (!form) {     throw new Error('PDF does not contain a form')   }   form.set(PDFName.of('NeedAppearances'), PDFBool.True)   const fieldRefs = form.context.lookup(form.get(PDFName.of('Fields')))   if (!fieldRefs) {     throw new Error('PDF form does not contain any fields')   }   const fields = fieldRefs.array.map((ref: any) =&gt; form.context.lookup(ref))   fields.forEach((field: any) =&gt; {     const name = field.get(PDFName.of('T'))     console.log('pdf form fieldName:', name, name.value)     if (name) {       const idx = fieldNames.indexOf(name.value)       const newValue = idx &gt;= 0 ? fieldValues[idx] : ''    ...

C# app on GCP

Simple app to fill data into the pdf template   https://www.codeguru.com/csharp/.net/net_general/generating-a-pdf-document-using-c-.net-and-itext-7.html add signature/image to existing pdf: PdfReader reader = new PdfReader ( pdfIn ) FileStream fs = new FileStream ( pdfOut , FileMode . Create ); var stamper = new PdfStamper ( reader , fs ); var pdfContentByte = stamper . GetOverContent ( 1 ); iTextSharp . text . Image sigimage = iTextSharp . text . Image . GetInstance ( bytes ); sigimage . SetAbsolutePosition ( 100 , 100 ); pdfContentByte . AddImage ( sigimage ); Create Google cloud functions https://codelabs.developers.google.com/codelabs/cloud-functions-csharp/index.html?index=..%2F..index#0

convert callback to async/await with promise

1) Node version 8 and above now support turning callback functions into promises using the built-in  util  module. const request = require('request'); const util = require('util'); const fetchData = util.promisify(request); fetchData(url).then(data => { let content = JSON.parse(data.body); console.log('Joke: ', content.value); }).catch(err => console.log('error: ', err)) 2) Turn callback into a promise export const mergePdfs = async (pdf1: string, pdf2: string, pdf: string) => { return new Promise((resolve, reject) => { merge([pdf1, pdf2], pdf, (error: any) => { if (error) { return reject(error) } resolve('') }) }) } 3) sample for printPDF

check variable undefined with quokka

// listingId = '', 0, null, undefined, false //let listingId if ( typeof listingId === 'undefined' ) console . log ( 'listingId is undefined' ) else console . log ( listingId ) if (!! listingId ) console . log ( listingId ) else console . log ( 'listingId does not found' ) if ( listingId ) console . log ( listingId ) else console . log ( 'listingId does not found' ) if ( listingId === undefined ) console . log ( 'listingId does not found' ) else console . log ( listingId )

add Digital Signature to pdf with pdfKit and react-signature-canvas for NodeJS / GraphQL

to create hand-craft signature with signaturePad, add date and save to a pdf. then add signature PDF as an additional page attach to the main pdf. https://www.npmjs.com/package/react-signature-canvas ** need remove alpha from image in order for pdfKit to create pdf by:  1. set background color to whte < SignaturePad ref = { sigPad } backgroundColor = "rgba(255,255,255,1)" canvasProps = { { className : classes . sigPad } } /> 2. to image/jpeg const imageData = sigPad . current . getTrimmedCanvas () . toDataURL ( 'image/jpeg' ) 3. merge pdfs using  https://www.npmjs.com/package/easy-pdf-merge export const mergePdfs = async ( pdf1 : string , pdf2 : string , pdf : string ) => { return new Promise (( resolve , reject ) => { merge ([ pdf1 , pdf2 ], pdf , ( error : any ) => { if ( error ) { return reject ( error ) } resolve ...