Add Image Stamp to PDF via JavaScript via C++

Create Image Stamp programmaticaly using Aspose.PDF for JavaScript via C++ Tool

How to add Image Stamps to PDF Using JavaScript via C++

Image stamps can be used to add copyrights or watermarks to PDF files. This helps to protect content from unauthorized copying or distribution. Image stamps may also be used to designate confidential or restricted documents, to confirm the authenticity of the document, or for validation. Image stamps improve the visual appearance of your PDF document. In order to add image stamps into PDF file, we’ll use Aspose.PDF for JavaScript via C++ is a easy and secure toolkit used to work with PDF directly in the web browser. To install and use Aspose.PDF for JavaScript via C++ extract files from the ZIP archive.

Add Image Stamp to PDF Document JavaScript via C++


You need Aspose.PDF library to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Open a PDF document using Document object.
  3. Create a Image Stamp and define its properties.
  4. Add the Stamp to Page using AddStamp method

Add Image Stamp to PDF - JavaScript via C++


    var ffileStamp = function (e) {
        const file_reader = new FileReader();
        /*set the stamp filename*/
        fileStamp = e.target.files[0].name;
        file_reader.onload = (event) => {
        /*prepare(save) the stamp file from BLOB*/
        AsposePdfPrepare(event.target.result, fileStamp);
        };
        file_reader.readAsArrayBuffer(e.target.files[0]);
    };

    var ffileAddStamp = function (e) {
        const file_reader = new FileReader();
        file_reader.onload = (event) => {
        /*insert the stamp file to a PDF-file and save the "ResultStamp.pdf"*/
        const json = AsposePdfAddStamp(event.target.result, e.target.files[0].name, fileStamp, 0, 5, 5, 40, 40, Module.Rotation.on270, 0.5, "ResultStamp.pdf");
        if (json.errorCode == 0) document.getElementById('output').textContent = json.fileNameResult;
        else document.getElementById('output').textContent = json.errorText;
        /*make a link to download the result file*/
        DownloadFile(json.fileNameResult, "application/pdf");
        };
        file_reader.readAsArrayBuffer(e.target.files[0]);
    };