souravlahoti
12/16/2018 - 3:41 PM

E-Sign Method 2

Appending sign to PDF

//Appending sign to FDA doc

var writer = hummus.createWriterToModify('FDA.pdf', {
    modifiedFilePath: 'output.pdf'
});
var pdfReader = writer.getModifiedFileParser();
for (var i=0; i < pdfReader.getPagesCount(); ++i) {
    var pageBox = pdfReader.parsePage(i).getMediaBox();
    var pageWidth = pageBox[2] - pageBox[0];
    var imageDimensions = writer.getImageDimensions('certified.png'); 

    var pageModifier = new hummus.PDFPageModifier(writer, 2, true);
    pageModifier.startContext().getContext().drawImage(50, 180, 'certified.png',
        {transformation:{
              width:30,
            //   height:pageWidth*imageDimensions.height/imageDimensions.width,  
              height:30,  
              fit:'always'}});

    pageModifier.startContext().getContext().writeText('Andres Garcia',85, 200,
    { font: writer.getFontForFile('arial.ttf'),size:8,colorspace:'gray',color:0x00});
    pageModifier.startContext().getContext().writeText('Reason: I am an author',85, 192,
    { font: writer.getFontForFile('arial.ttf'),size:8,colorspace:'gray',color:0x00});
    pageModifier.startContext().getContext().writeText('Date:' + new Date(),85, 184,
    { font: writer.getFontForFile('arial.ttf'),size:8,colorspace:'gray',color:0x00});
    pageModifier.endContext().writePage();
}
writer.end();