Stamp
Creates textual or image stamps on PDF documents. This client allows you to highly personalize your stamp. The font, color, rendering mode and position of your stamp 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.
Feature | Parameter | Response | Action | Description | Links |
stamp | Stamp | StampRes | StampAction | Creates textual or image stamps on PDF documents. | Swagger Sample |
textStamp | text, pages, alignX,alignY file | file stream | Creates textual or image stamps on PDF documents. | Swagger Sample |
Samples
Stamp
- curl
- C#
- Java
- JavaScript
- PHP
- Python
- Ruby
curl No Sample
// 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)
})
// 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);
# 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)
TextStamp
- curl
- 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
// stamping the pdf
byte[] stampedPdf = await Pdf4meClient.Pdf4me.Instance.StampClient.TextStampAsync(File.ReadAllBytes("myPdf.pdf"), "EXAMPLE TEXT", "all", AlignX.Center, AlignY.Middle);
// and writing the generated PDF to disk
File.WriteAllBytes("stampedPdf.pdf", stampedPdf);
// setup the stampClient
StampClient stampClient = new StampClient(pdf4meClient);
// stamp and writing the generated PDF to disk
byte[] stampedPdf = stampClient.textStamp("EXAMPLE TEXT", "all", AlignXEnum.CENTER,
AlignYEnum.MIDDLE, new File("myPdf.pdf"));
FileUtils.writeByteArrayToFile(new File("stampedPdf.pdf"), stampedPdf);
// setup the pdf4meClient
const pdf4meClient = pdf4me.createClient('YOUR API KEY')
// stamp document
pdf4meClient.textStamp('EXAMPLE TEXT', 'all', 'left', 'top', fs.createReadStream(path.join(__dirname, 'myPdf.pdf')))
.then(pdf => {
// and writing the resulting PDFs to disk
fs.writeFileSync(path.join(__dirname, 'stampedPdf.pdf'), pdf)
})
.catch(error => {
console.error(error)
})
pdf4me()->textStamp(
[
"text" => 'EXAMPLE TEXT'
"pages" => 'all',
"alignX" => 'center',
"alignY" => 'middle',
"file" => __DIR__.'/myPdf.pdf'
]
);
//writing it to file
file_put_contents('stampedPdf.pdf', $stampedPdf);
# setup the stamp_client
stamp_client = StampClient(pdf4me_client)
# applying the stamp to the PDF
stamped_pdf = stamp_client.text_stamp(
text='EXAMPLE TEXT',
pages='all',
align_x='center',
align_y='middle',
file=FileReader().get_file_handler(path='myPdf.pdf')
)
# writing the generated PDF to disk
with open('stampedPdf.pdf', 'wb') as f:
f.write(stamped_pdf)
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
Models
Stamp
Name | Type | Description | Notes |
---|---|---|---|
document |
Document |
||
stampAction |
StampAction |
StampAction
Name | Type | Description | Notes |
---|---|---|---|
pageSequence |
string |
Pages the action is applied to. | |
relativePosX |
integer |
Relative position of the stamp with regards to the page. Positive values define the distances from the stamp to the left page border, negative values to the right page boundary respectively. The units of the values are PDF units of 1/72 inch. | |
relativePosY |
integer |
Relative position of the stamp with regards to the page. Positive values define the distances from the stamp to the lower, negative values to the upper page boundary respectively. The units of the values are PDF units of 1/72 inch. | |
sizeX |
integer |
The width of the stamp. The stamp’s content will be clipped to this rectangle (width, height). If this is not specified or either the width or the height are zero, the respective size is calculated to fit content. | |
sizeY |
integer |
The height of the stamp. The stamp’s content will be clipped to this rectangle (width, height). If this is not specified or either the width or the height are zero, the respective size is calculated to fit content. | |
rotate |
double |
Clockwise rotation of the stamp [degree]. | |
autoorientation |
boolean |
Orientation of Stamp. - true: detects orientation (portrait and landscape) of page automatically and treats landscape page as a 90° rotated portrait. Useful to apply stamps to “long” or “short” edge of page. - false: always positions stamps as defined by stamp attributes. | |
alpha |
double |
The opacity of the entire stamp. 1.0 for fully opaque, 0.0 for fully transparent. The PDF/A-1 standard does not allow transparency. Therefore, for PDF/A-1 conforming input files you must not set alpha to a value other than 1.0. | |
scale |
string |
Scale of stamp. Scales the stamp relative to the page size. For example, make stamp half as large on a A5 and twice as large on a A3 page as specified. | |
alignX |
enum |
Values: left, center, right Align the stamp with the page. Overrules relativePosX. |
|
alignY |
enum |
Values: top, middle, bottom Align the stamp with the page. Overrules relativePosY. |
|
stampType |
enum |
Values: annotation, foreground, background The type of the stamp. |
|
text |
Text |
Text stamp. | |
image |
Image |
Image stamp. |
StampRes
Name | Type | Description | Notes |
---|---|---|---|
document |
Document |
Stamped document. |
Document
Name | Type | Description | Notes |
---|---|---|---|
jobId |
String |
JobId of Documents WorkingSet. | |
documentId |
String |
Document Id | |
name |
String |
Filename inlcuding filetype. | |
docStatus |
String |
Status of the Document, e.g. Stamped. | |
pages |
Page |
Description of pages. | |
docData |
[byte] |
Document bytes. | |
docMetadata |
DocMetadata |
Document metadata such as title, pageCount et al. | |
docLogs |
DocLog |
Logging information about the request, e.g. timestamp. |
Page
Name | Type | Description | Notes |
---|---|---|---|
documentId |
String |
Globally unique Id. | |
pageId |
String |
Globally unique Id. | |
pageNumber |
Integer |
PageNumber, starting with 1. | |
rotate |
double |
By how much the page was rotated from its original orientation. | |
thumbnail |
byte |
Thumbnail representing this particular page. | |
sourceDocumentId |
String |
Id of the document it was created from, e.g. in case of an extraction, the result's sourceDocumentId is the Id of the PDF the pages have been extracted from. | |
sourcePageNumber |
Integer |
Page number of the original page in the original document, e.g. let's assume document B consists of page number 4 of document A (extraction). Thus, document B's only page's sourcePageNumber is number 4. |
DocMetadata
Name | Type | Description | Notes |
---|---|---|---|
title |
String |
Title of document. | |
subject |
String |
Subject of document. | |
pageCount |
long |
Number of pages. | |
size |
long |
Number bytes of the document. | |
isEncrypted |
boolean |
If the document is Encrypted | |
pdfCompliance |
String |
Pdf Compliance, e.g. PDF/A. | |
isSigned |
boolean |
If the document is Encrypted | |
uploadedMimeType |
String |
Uploaded MimeType, e.g. application/bson. | |
uploadedFileSize |
long |
Uploaded file size. |
DocLog
Name | Type | Description | Notes |
---|---|---|---|
messageType |
String |
MessageType, e.g. PdfALog. | |
message |
String |
Message itself, e.g. a warning. | |
timestamp |
dateTime |
Timestamp. | |
docLogLevel |
String |
Type of message. | Supported Values : "verbose", "info", "warning", "error", "timing" |
durationMilliseconds |
long |
Timing for requested log information [ms]. |
Text
Name | Type | Notes | Description |
---|---|---|---|
format |
boolean |
[Optional] | Whether or not to enable formatting of variable text, such as the current date or the number of pages. |
size |
integer |
[Optional] | The font size in points, e.g. 12. If set to 0, the size is chosen such that text fits stamp size. |
font |
string |
[Optional] | The TrueType name of the font, e.g. "Arial" or "Times New Roman,Bold", or a complete path to the font, e.g. C:/Windows/Fonts/Arial.ttf. If the name is used, the respective font must be available in any of the font directories. |
color |
Color |
[Optional] | The color as RGB value, where all values must be in the range from 0 to 1. |
fontEncoding |
string |
"unicode": Only the glyphs used by the stamp are embedded. If the stamp is modified, a new font that includes the new glyph set has to be re-embedded. This setting is recommended for stamps that will not be modified later. "winAnsi": All glyphs required for WinAnsiEncoding are embedded. Hence the text’s characters are limited to this character set. If the content of the stamp is updated, fonts using WinAnsi will be reused. Default: "unicode" [Optional] |
This attribute is relevant only, if the stamp will be modified later. The PDF/A standard demands that all used fonts must be embedded in the PDF. Since fonts with many glyphs can be very large in size (>20MB), unused glyphs are removed prior to embedding. This process is called subsetting. The attribute fontencoding controls the subsetting. |
value |
string |
Text to be displayed. The text can have embedded HTML. | |
mode |
string |
"fill": the text is filled. "stroke": the text’s outlines are stroked. |
Rendering mode of the text. |
rotate |
Rotate |
[Optional] | Image rotation. |
translate |
Translate |
[Optional] | Image translate. |
transform |
Transform |
[Optional] | Image transform. |
Color
Name | Type | Notes | Description |
---|---|---|---|
red |
double |
[Optional] | RGB value for required Red. |
green |
double |
[Optional] | RGB value for required Green. |
blue |
double |
[Optional] | RGB value for required Blue. |
Rotate
Name | Type | Description | Notes |
---|---|---|---|
angle |
double |
Counter-clockwise rotation by n degrees, e.g 90. | |
originX |
integer |
Origin (x-coordinate) of rotation [point]. | |
originY |
integer |
Origin (y-coordinate) of rotation [point]. |
Translate
Name | Type | Description | Notes |
---|---|---|---|
offsetX |
integer |
Horizontal offset [point]. | |
offsetY |
integer |
Vertical offset [point]. |
Transform
Name | Type | Description | Notes |
---|---|---|---|
a |
integer |
Scaling of x-Axis. TODO: define all parameters proparly | |
b |
integer |
Rotation e.g. by x: cos(x) sin(x) -sin(x) cos(x) 0 0. | |
c |
integer |
Scaling of y-Axis. | |
d |
integer |
Rotation. | |
x |
integer |
Horizontal offset to the left [point]. | |
y |
integer |
Vertical offset from the bottom [point]. |
CustomCMSConfig
Name | Type | Description | Notes |
---|---|---|---|
white |
RGBSet |
0.996078, 0.996078, 0.996078 | |
c |
RGBSet |
0.000000, 0.686275, 0.937255 | |
m |
RGBSet |
0.925490, 0.149020, 0.560784 | |
y |
RGBSet |
1.000000, 0.949020, 0.066667 | |
k |
RGBSet |
0.215686, 0.203922, 0.207843 | |
cm |
RGBSet |
0.243137, 0.247059, 0.584314 | |
cy |
RGBSet |
0.000000, 0.658824, 0.349020 | |
ck |
RGBSet |
0.066667, 0.176471, 0.215686 | |
my |
RGBSet |
0.929412, 0.196078, 0.215686 | |
mk |
RGBSet |
0.215686, 0.101961, 0.141176 | |
yk |
RGBSet |
0.200000, 0.196078, 0.125490 | |
cmy |
RGBSet |
0.266667, 0.266667, 0.274510 | |
cmk |
RGBSet |
0.133333, 0.098039, 0.160784 | |
cyk |
RGBSet |
0.074510, 0.180392, 0.133333 | |
myk |
RGBSet |
0.215686, 0.121569, 0.113725 | |
cmyk |
RGBSet |
0.125490, 0.121569, 0.121569 |
Image
Name | Type | Description | Notes |
---|---|---|---|
rectangle |
Rectangle |
||
imageData |
byte | Image data as byte stream. | [Optional] |
imageType |
String | Type of Image | [Optional] |
fileName |
String | Name of the Image file. | [Optional] |
compression |
String | Value: cCITTFax, flate, dCT Compression compliance |
[Optional] |
rotate |
RotateConfig |
||
translate |
Translate |
||
transform |
Transform |