corymickelson / NoPoDoFo

node pdf native bindings
GNU Affero General Public License v3.0
26 stars 6 forks source link

Am I installing it correct? #77

Closed sourav-prescriber-360 closed 5 years ago

sourav-prescriber-360 commented 5 years ago

I ran npm i nopodofo --save to my project My code below:-

const doc = new npdf.Document()
console.log(doc);
doc.load('./FDA.pdf', e => {

    console.log(e);
    const rect = new npdf.Rect(0, 0, 10, 10),
        page = doc.getPage(0),
        annot = page.createAnnotation(NPDFAnnotation.Widget, rect)

    // This signature is going to be hidden, for a visible signature add an appearance stream
    annot.flags = NPDFAnnotationFlag.Hidden | NPDFAnnotationFlag.Invisible

    const field = new npdf.SignatureField(annot, doc)

    // Set field properties
    field.setReason('test')
    field.setLocation('here')
    field.setCreator('me')
    field.setFieldName('signer.sign')

    // This will set the date as now
    field.setDate()
    // or create a new date and pass to the setDate function
    let d = new npdf.Date(pdfDate(new Date('2012-12-12')))
    field.setDate(d)
    const signer = new npdf.Signer(doc, './output/')
    signer.signatureField = field
    signer.loadCertificateAndKey('certificate.p12', '123456', (error, signatureLength) => {
        if (error) { /* handle error */ }
        signer.write(signatureLength, (e, d) => {
            if (e) { /* handle error*/ }
            // signed document has been written to /output/path provided in Signer constructor 
        })
    })
})

I get the following error:

/Users/beingsrv/Documents/OneDrive - Optiks Solutions, Inc/Freelance/upwork_ 21158544/node_modules/bindings/bindings.js:91
        throw e
        ^

Error: dlopen(/Users/beingsrv/Documents/OneDrive - Optiks Solutions, Inc/Freelance/upwork_ 21158544/node_modules/nopodofo/build/Release/nopodofo.node, 1): no suitable image found.  Did find:
        /Users/beingsrv/Documents/OneDrive - Optiks Solutions, Inc/Freelance/upwork_ 21158544/node_modules/nopodofo/build/Release/nopodofo.node: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00
        /Users/beingsrv/Documents/OneDrive - Optiks Solutions, Inc/Freelance/upwork_ 21158544/node_modules/nopodofo/build/Release/nopodofo.node: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00
    at Object.Module._extensions..node (module.js:681:18)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at bindings (/Users/beingsrv/Documents/OneDrive - Optiks Solutions, Inc/Freelance/upwork_ 21158544/node_modules/bindings/bindings.js:84:48)
    at Object.<anonymous> (/Users/beingsrv/Documents/OneDrive - Optiks Solutions, Inc/Freelance/upwork_ 21158544/node_modules/nopodofo/index.js:1:101)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
corymickelson commented 5 years ago

you need to have podofo compiled on your system, if the path to podofo is not a common installation path (eg. /usr, /usr/local) you will need to provide the path to podofo as an -rpath argument. What OS are you using? Installation instructions are also provided in the book

sourav-prescriber-360 commented 5 years ago

@corymickelson I am using MACOs for dev purpose later will deploy to LINUX server

corymickelson commented 5 years ago

@sourav-prescriber-360 I've not tested on Mac, I do have one available though, I can take a look and get back to you.

sourav-prescriber-360 commented 5 years ago

@corymickelson I tried installing on MacOS with the code given in the GitBook:

git clone https://github.com/svn2github/podofo $HOME/podofo && \ cd $HOME/podofo && \ mkdir $HOME/podofo/build && \ cd $HOME/podofo/build && \ cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local && \ make && make install

Error

[ 55%] Linking CXX executable ContentParser Undefined symbols for architecture x86_64: "_FcConfigDestroy", referenced from: PoDoFo::PdfFontConfigWrapper::DerefBuffer() in libpodofo.a(PdfFontConfigWrapper.cpp.o) "_FcConfigSubstitute", referenced from: PoDoFo::PdfFontCache::GetFontConfigFontPath(_FcConfig*, char const*, bool, bool) in libpodofo.a(PdfFontCache.cpp.o) "_FcDefaultSubstitute", referenced from: PoDoFo::PdfFontCache::GetFontConfigFontPath(_FcConfig*, char const*, bool, bool) in libpodofo.a(PdfFontCache.cpp.o) "_FcFontMatch", referenced from: PoDoFo::PdfFontCache::GetFontConfigFontPath(_FcConfig*, char const*, bool, bool) in libpodofo.a(PdfFontCache.cpp.o) "_FcInitLoadConfigAndFonts", referenced from: PoDoFo::PdfFontConfigWrapper::InitializeFontConfig() in libpodofo.a(PdfFontConfigWrapper.cpp.o) "_FcPatternBuild", referenced from: PoDoFo::PdfFontCache::GetFontConfigFontPath(_FcConfig*, char const*, bool, bool) in libpodofo.a(PdfFontCache.cpp.o) "_FcPatternDestroy", referenced from: PoDoFo::PdfFontCache::GetFontConfigFontPath(_FcConfig*, char const*, bool, bool) in libpodofo.a(PdfFontCache.cpp.o) "_FcPatternGet", referenced from: PoDoFo::PdfFontCache::GetFontConfigFontPath(_FcConfig*, char const*, bool, bool) in libpodofo.a(PdfFontCache.cpp.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [test/ContentParser/ContentParser] Error 1 make[1]: *** [test/ContentParser/CMakeFiles/ContentParser.dir/all] Error 2 make: *** [all] Error 2

corymickelson commented 5 years ago

You can install using vcpkg, if you have a package manager that you would rather use the only requirement at the moment is that podofo is 0.9.6 or greater and is built with openssl, libpng, libjpeg, libtiff, and if you need aes 256 encryption you will also need libidnv1. I know the vcpkg installation includes all but libidn. Im sorry I can't be of more assistance at the moment, but I will take a look into installation on mac soon, and will update the installation page with a mac section.

corymickelson commented 5 years ago

@sourav-prescriber-360 If you want to try the library in the mean time, you can pull the docker image nopodofo/alpine, this has podofo and nopodofo installed at /usr/local. If you were testing just in a node repl you would require nopodofo with require('nopodofo')

corymickelson commented 5 years ago

@sourav-prescriber-360 The macports podofo port is probably your easiest option for building podofo locally. This does however install to /opt/local which is not in the search path for nopodofo. I will update the cmake file today to include this directory when building nopodofo.

sourav-prescriber-360 commented 5 years ago

@corymickelson I have installed podofo using macports. Once you have updated the documentation I will proceed further for my project. Thanks for quick response

corymickelson commented 5 years ago

closing thread, the cmakelists file has been updated to include /opt in it's search path. Additional documentation has also been added to the mac os installation section.