How To Add Image in Header of the PDF Document in Node.Js Using Aspose.PDF REST API

How to insert image to top position of PDF. and insert the image all PDF pages

@bilbi_John

You can use PostDocumentImageHeader API method to add image in Header of the PDF document.

How to Insert Image to PDF Header in Node.js

const { PdfApi } = require("asposepdfcloud");


// Get Client ID and Secret from https://dashboard.aspose.cloud/
pdfApi = new PdfApi("xxxxx-xxxxx-xxxxx-xxxx-xxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
var fs = require('fs');

const name = "02_pages.pdf";
const remoteTempFolder = "Temp";
const localTestDataFolder = "C:\\Temp";
const startPage = 2;
const endPage = 3;
const image = "Koala.jpg";
const path = remoteTempFolder + "\\" + imageName;
var data = fs.readFileSync(localTestDataFolder + "\\" + image);

// Upload Image to Cloud Storage
pdfApi.uploadFile(path, data).then((result) => {  
                     console.log("Uploaded File");    
                    }).catch(function(err) {
    // Deal with an error
    console.log(err);
});

//Add image to PDF document header

const header = new ImageHeader();
header.background = true;
header.leftMargin = 1;
header.rightMargin = 2
header.topMargin = 20;
header.horizontalAlignment = HorizontalAlignment.Center;
header.opacity = 1;
header.rotate = Rotation.None;
header.rotateAngle = 10;
header.xIndent = 0;
header.yIndent = 0;
header.zoom = 1;
header.fileName = remoteTempFolder + '/' + image;
            

return pdfApi.postDocumentImageHeader(name, header, startPage, endPage, null, remoteTempFolder)
     .then((result) => {
			console.log(result.body.code);  
}).catch(function(err) {
    // Deal with an error
    console.log(err);
});