Hi, we are currently using the PostPageTextStamps
method to add text stamps to PDFs. This API endpoint operates on a specific page number only. If, for example, we wanted to stamp each page of a 100 page document, this would result in 100 API calls.
Is there a way to stamp multiple pages (different text on each page) in a single API call?
@contactslaw
To add text stamps to multiple pages of a PDF in a single API call, you can utilize the PostDocumentTextStamps
method instead of the PostPageTextStamps
method, which operates on a specific page. The PostDocumentTextStamps
method allows you to apply the same or different text stamps across all pages of the document in one go.
Here’s a brief example of how you can implement this in C#:
using System.Collections.Generic;
using Aspose.Pdf.Cloud.Sdk.Model;
// Create a list of text stamps
List<TextStamp> stamps = new List<TextStamp>
{
new TextStamp
{
Background = true,
LeftMargin = 1,
RightMargin = 2,
TopMargin = 3,
BottomMargin = 4,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
Opacity = 1,
Rotate = Rotation.None,
Value = "Stamp for all pages",
TextState = new TextState(FontSize: 14D, Font: "Arial")
},
// You can add more stamps with different values here
};
// Call the API to add the stamps to the document
var response = PdfApi.PostDocumentTextStamps("YourDocument.pdf", stamps, folder: "YourFolder");
if (response.Code == 200)
{
Console.WriteLine("Stamps added successfully!");
}
In this example, you can customize the TextStamp
objects in the list to have different values or properties as needed. This way, you can effectively add multiple text stamps to different pages of your PDF document in a single API call, reducing the number of requests you need to make.
For more details, you can refer to the relevant examples in the Aspose documentation or the provided code samples in the Aspose GitHub repository.
When using the PostDocumentTextStamps
method, how do we specify which stamps are added to which pages?
@contactslaw
You can specify which text stamp to add to the page using the PostPageTextStamps
method, the PostDocumentTextStamps
method will apply the text stamp to each page inside the PDF document.
@kirill.novinskiy
So, just to clarify - one API call per page - so 100 pages = 100 API calls? That could get quite expensive for use cases like adding page numbers or, say, reference numbers on every odd-numbered page.
@contactslaw
For page number stamps you can use PostDocumentPageNumberStamps
method. Please provide more details about the use case.
@kirill.novinskiy
We have a requirement to generate a “bundle” of documents - which involves combining multiple PDFs into a single document, then adding global page numbers. The first page of each original document needs to be stamped with a reference number. In some cases, we want the odd and even-numbered pages to use different horizontal alignment for the page numbers.
For example:
Actual Page Num Page Num Stamp Reference Num Stamp
--------------------------------------------------------
1 1 (Left Align)
2 2 (Right Align)
3 3 (Left Align) ABC123
4 4 (Right Align)
5 5 (Left Align) DEF456
6 6 (Right Align) GHI789
Is there any way something like this could be done in a single API call?
@contactslaw
No, you can’t do it with one API call now.
Im report issue and logged the following ticket in our issue tracking system for further investigation and rectification. We will notify you as soon as these issues are resolved.
PDFCLOUD-4780 Add method for adding Stamp per page in batch.