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);
import pdf4me from 'pdf4me'

async function callpdf4me() {
  const pdf4meClient = pdf4me.createClient( 'TOKEN' )

  const convertReq = {
    //document
    document: {
        docData: fs.readFileSync('Example.pdf').toString('base64'),
        name: "Result.pdf"
      },
      // action
      stampAction: {
        text: {
          value: 'EXAMPLE TEXT',
          size: 30,
          color: { red: 0.5, green: 0.5, blue: 0 },
        },
        alpha: 1,
        rotate: -52,
        pageSequence: 'all',
        stampType: 'foreground',
        alignX: 'center',
        alignY: 'middle',
      },
  }

  //applying the stamp to the pdf
  const convertFromPdfRes = await pdf4meClient.stamp(convertReq)

  //writing the generated pdf to disk
  fs.writeFileSync(
    convertFromPdfRes.document.name,
    Buffer.from(convertFromPdfRes.document.docData, 'base64')
  )
}

callpdf4me()
from pdf4me.client.stamp_client import StampClient
from pdf4me.model import Document, Stamp, StampAction, Text
from pdf4me.client.pdf4me_client import Pdf4meClient
from pdf4me.helper.file_reader import FileReader
import base64

# setup the stamp_client
pdf4me_client = Pdf4meClient(token='TOKEN',apiurl='API URL')
stamp_client = StampClient(pdf4me_client)

# create the stamp object
stamp = Stamp(
    # document
    document=Document(
        doc_data=FileReader().get_file_data('example.pdf')
    ),
    # action
    stamp_action=StampAction(
        text=Text(
            value='EXAMPLE TEXT',
            size = 20
        ),
        alpha=1,
        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