index.js
/**
     * Creates fdf file from JSON input.
     * Converts input values to binary buffer, which seems to allow PdfTk to render utf-8 characters.
     * @static
     * @public
     * @param {Object} data - JSON data to transform to fdf.
     * @returns {Buffer} Fdf data as a buffer.
     */
Creates fdf file from JSON input.
Converts input values to binary buffer, which seems to allow PdfTk to render utf-8 characters.
@static
@public
@param {Object} data - JSON data to transform to fdf.
@returns {Buffer} Fdf data as a buffer.
Creates fdf file from JSON input . Converts input values to binary buffer which seems to allow PdfTk to render utf - 8 characters . @static @public @param { Object } data - JSON data to transform to fdf . @returns { Buffer } Fdf data as a buffer .
static generateFdfFromJSON(data) {
        const header = PdfTk.stringToBuffer(`
            %FDF-1.2\n
            ${String.fromCharCode(226) + String.fromCharCode(227) + String.fromCharCode(207) + String.fromCharCode(211)}\n
            1 0 obj\n
            <<\n
            /FDF\n
            <<\n
            /Fields [\n
        `);
        let body = PdfTk.stringToBuffer('');
        for (const prop in data) {
            if (data.hasOwnProperty(prop)) {
                body = Buffer.concat([
                    body,
                    PdfTk.stringToBuffer('<<\n/T ('),
                ]);
                body = Buffer.concat([
                    body,
                    PdfTk.stringToBuffer(prop, 'binary'),
                ]);
                body = Buffer.concat([
                    body,
                    PdfTk.stringToBuffer(')\n/V('),
                ]);
                body = Buffer.concat([
                    body,
                    PdfTk.stringToBuffer(data[prop], 'binary'),
                ]);
                body = Buffer.concat([
                    body,
                    PdfTk.stringToBuffer(')\n>>\n'),
                ]);
            }
        }
        const footer = PdfTk.stringToBuffer(`
            ]\n
            >>\n
            >>\n
            endobj \n
            trailer\n
            \n
            <<\n
            /Root 1 0 R\n
            >>\n
            %%EOF\n
        `);
        return Buffer.concat([
            header,
            body,
            footer,
        ]);
    }
static generateFdfFromJSON ( data ) { const header = PdfTk . stringToBuffer ( ` \n ${ String . fromCharCode ( 226 ) + String . fromCharCode ( 227 ) + String . fromCharCode ( 207 ) + String . fromCharCode ( 211 ) } \n \n \n \n \n \n ` ) ; let body = PdfTk . stringToBuffer ( '' ) ; for ( const prop in data ) { if ( data . hasOwnProperty ( prop ) ) { body = Buffer . concat ( [ body , PdfTk . stringToBuffer ( '<<\n/T (' ) , ] ) ; body = Buffer . concat ( [ body , PdfTk . stringToBuffer ( prop , 'binary' ) , ] ) ; body = Buffer . concat ( [ body , PdfTk . stringToBuffer ( ')\n/V(' ) , ] ) ; body = Buffer . concat ( [ body , PdfTk . stringToBuffer ( data [ prop ] , 'binary' ) , ] ) ; body = Buffer . concat ( [ body , PdfTk . stringToBuffer ( ')\n>>\n' ) , ] ) ; } } const footer = PdfTk . stringToBuffer ( ` \n \n \n \n \n \n \n \n \n \n ` ) ; return Buffer . concat ( [ header , body , footer , ] ) ; }
Creates fdf file from JSON input.
Creates fdf file from JSON input .
/* istanbul ignore else  */