Add Watermark

Creates textual or image stamps on PDF documents. This client allows you to personalize your Watermark highly. The font, color, rendering mode, and stamp position are only the start. For detailed information have a look at the StampAction. Furthermore, you may select the pages your stamp will be applied to.

Code Samples

Try the API in the language you prefer

  • C#
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
curl https://api.pdf4me.com/Stamp/TextStamp ^
    -H "Authorization: Basic DEV-KEY" ^
    -F text=EXAMPLE TEXT ^
    -F pages=3,4,5 ^
    -F alignX=center ^
    -F alignY=middle
    -F "file=@./myPdf.pdf" ^
    -o ./stampedPdf.pdf   
// create stamp object
var stamp = new Stamp()
{
    // document
    Document = new Document()
    {
        DocData = File.ReadAllBytes("myPdf.pdf"),
        Name = "myPdf.pdf",
    },
    // action
    StampAction = new StampAction()
    {
        Text = new Text()
        {
            Value = "EXAMPLE TEXT",
            Size = 30
        },
        PageSequence = "all",
        Alpha = 0.25,// opacity of the stamp: 1.0 for fully opaque, 0.0 for fully transparent.
        AlignX = StampActionAlignX.Center,
        AlignY = StampActionAlignY.Middle
    },
};

// applying the stamp to the PDF
var res = await Pdf4meClient.Pdf4me.Instance.StampClient.StampAsync(stamp);

// extract the stamped PDF and writing it to disk
byte[] stampedPdf = res.Document.DocData;
File.WriteAllBytes("stampedPdf.pdf", stampedPdf);
// setup the stampClient
StampClient stampClient = new StampClient(pdf4meClient);

// create stamp object
Stamp stamp = new Stamp();
// document
Document document = new Document();
document.setDocData(Files.readAllBytes(Paths.get("myPdf.pdf")));
stamp.setDocument(document);
// action
StampAction stampAction = new StampAction();
Text textObj = new Text();
textObj.setValue("EXAMPLE TEXT");
textObj.setSize(30);
stampAction.setText(textObj);
stampAction.setAlpha(0.25); // opacity of the stamp: 1.0 for fully opaque, 0.0 for fully transparent.
stampAction.setPageSequence("all");
stampAction.setAlignX(AlignXEnum.CENTER);
stampAction.setAlignY(AlignYEnum.MIDDLE);
stamp.setStampAction(stampAction);

// applying the stamp to the PDF
StampRes res = stampClient.stamp(stamp);

// extracting the generated PDF and writing it to disk
byte[] stampedPdf = res.getDocument().getDocData();
FileUtils.writeByteArrayToFile(new File("stampedPdf.pdf"), stampedPdf);
// setup the pdf4meClient
const pdf4meClient = pdf4me.createClient('YOUR API KEY')

// create stamp object
const stampReq = {
  // document
  document: {
    docData: fs.readFileSync(path.join(__dirname, 'myPdf.pdf')).toString('base64'),
  },
  // action
  stampAction: {
    text: {
      value: 'EXAMPLE TEXT',
      size: 30,
      color: { red: 0.5, green: 0.5, blue: 0 },
    },
    alpha: 0.25,
    rotate: -52,
    pageSequence: 'all',
    stampType: 'foreground',
    alignX: 'center',
    alignY: 'middle',
  },
}

// applying the stamp to the PDF
pdf4meClient.stamp(stampReq)
  .then(function(stampRes) {
    // extracting the generated PDF and writing it to disk
    const pdfDocument = Buffer.from(stampRes.document.docData, 'base64')
    fs.writeFileSync(path.join(__dirname, 'stampedPdf.pdf'), pdfDocument)
  })
  .catch(error => {
    console.log(error)
  })
# setup the stamp_client
stamp_client = StampClient(pdf4me_client)

# create the stamp object
stamp = Stamp(
    # document
    document=Document(
        doc_data=FileReader().get_file_data('myPdf.pdf')
    ),
    # action
    stamp_action=StampAction(
        text=Text(
            value='EXAMPLE TEXT'
        ),
        alpha=0.25,
        page_sequence='all',
        align_x='center',
        align_y='middle'
    )
)

# applying the stamp to the PDF
res = stamp_client.stamp(stamp=stamp)

# extracting the generated PDF
stamped_pdf = base64.b64decode(res['document']['doc_data'])
# writing it to disk
with open('stampedPdf.pdf', 'wb') as f:
    f.write(stamped_pdf)
// create stamp object
$create_stamp = [
    // document
    'document' => [
        'docData' => $client->getFileData('myPdf.pdf')
    ],
    // action
    'stampAction' => [
        "pageSequence" => 'all',
        "alpha" => 0.25,
        "alignX" => 'center',
        "alignY" => 'middle',
        "text" => [
            "value" => 'EXAMPLE TEXT',
            "size" => 30
        ]
    ]
];

// applying the stamp to the PDF
$res = $client->pdf4me()->stampPdf($create_stamp);

// extracting the generated PDFs
$stampedPdf = base64_decode($res->document->docData);
// and writing them to file
file_put_contents('stampedPdf.pdf', $stampedPdf);
a = Pdf4me::TextStamp.new(
      file: '/mypdf.pdf',
      pages: [1, 3],
      position_x: 'center',
      position_y: 'middle',
      text: 'EXAMPLE TEXT',
      save_path: 'stampedPdf.pdf'
)
a.run

Important Links

Swagger - Add Watermark