Add Text and Image Stamp
Add Text Stamp on All Pages in a PDF File
PdfFileStamp class allows you to add text stamp on all the pages of a PDF file. In order to add text stamp, you first need to create objects of PdfFileStamp and Stamp classes. You also need to create the text stamp using BindLogo method of Stamp class. You can set other attributes like origin, rotation, background etc. using Stamp object as well. Then you can add the stamp in the PDF file using AddStamp method of PdfFileStamp class. Finally, save the output PDF file using Close method of PdfFileStamp class. The following code snippet shows you how to add text stamp on all pages in a PDF file.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddTextStampOnAllPagesInPdfFile()
{
var dataDir = RunExamples.GetDataDir_AsposePdf_Images(); // Using dynamic path
// Create PdfFileStamp object
using (var fileStamp = new Aspose.Pdf.Facades.PdfFileStamp())
{
// Open Document
fileStamp.BindPdf(dataDir + "sample.pdf");
// Create stamp
var stamp = new Aspose.Pdf.Facades.Stamp();
stamp.BindLogo(new Aspose.Pdf.Facades.FormattedText("Hello World!",
System.Drawing.Color.Blue,
System.Drawing.Color.Gray,
Aspose.Pdf.Facades.FontStyle.Helvetica,
Aspose.Pdf.Facades.EncodingType.Winansi,
true,
14));
stamp.SetOrigin(10, 400);
stamp.Rotation = 90.0F;
stamp.IsBackground = true;
// Add stamp to PDF file
fileStamp.AddStamp(stamp);
// Save the document
fileStamp.Save(dataDir + "AddTextStamp-All_out.pdf");
}
}
Add Text Stamp on Particular Pages in a PDF File
PdfFileStamp class allows you to add text stamp on particular pages of a PDF file. In order to add text stamp, you first need to create objects of PdfFileStamp and Stamp classes. You also need to create the text stamp using BindLogo method of Stamp class. You can set other attributes like origin, rotation, background etc. using Stamp object as well. As you want to add text stamp on particular pages of the PDF file, you also need to set the Pages property of the Stamp class. This property requires an integer array containing numbers of the pages on which you want to add the stamp. Then you can add the stamp in the PDF file using AddStamp method of PdfFileStamp class. Finally, save the output PDF file using Close method of PdfFileStamp class. The following code snippet shows you how to add text stamp on particular pages in a PDF file.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddTextStampOnParticularPagesInPdfFile()
{
var dataDir = RunExamples.GetDataDir_AsposePdf_Images(); // Using dynamic path
// Create PdfFileStamp object
using (var fileStamp = new Aspose.Pdf.Facades.PdfFileStamp())
{
// Open Document
fileStamp.BindPdf(dataDir + "sample.pdf");
// Create stamp
var stamp = new Aspose.Pdf.Facades.Stamp();
stamp.BindLogo(new Aspose.Pdf.Facades.FormattedText("Hello World!",
System.Drawing.Color.Blue,
System.Drawing.Color.Gray,
Aspose.Pdf.Facades.FontStyle.Helvetica,
Aspose.Pdf.Facades.EncodingType.Winansi,
true,
14));
stamp.SetOrigin(10, 400);
stamp.Rotation = 90.0F;
stamp.IsBackground = true;
// Set particular pages (page 2)
stamp.Pages = new[] { 2 };
// Add stamp to PDF file
fileStamp.AddStamp(stamp);
// Save the document
fileStamp.Save(dataDir + "AddTextStamp-Page_out.pdf");
}
}
Add Image Stamp on All Pages in a PDF File
PdfFileStamp class allows you to add image stamp on all the pages of a PDF file. In order to add image stamp, you first need to create objects of PdfFileStamp and Stamp classes. You also need to create the image stamp using BindImage method of Stamp class. You can set other attributes like origin, rotation, background etc. using Stamp object as well. Then you can add the stamp in the PDF file using AddStamp method of PdfFileStamp class. Finally, save the output PDF file using Close method of PdfFileStamp class. The following code snippet shows you how to add image stamp on all pages in a PDF file.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddImageStampOnAllPagesInPdfFile()
{
var dataDir = RunExamples.GetDataDir_AsposePdf_Images(); // Using dynamic path
// Create PdfFileStamp object
using (var fileStamp = new Aspose.Pdf.Facades.PdfFileStamp())
{
// Open Document
fileStamp.BindPdf(dataDir + "sample.pdf");
// Create stamp
var stamp = new Aspose.Pdf.Facades.Stamp();
stamp.BindImage(dataDir + "StampImage.png");
stamp.SetOrigin(10, 200);
stamp.Rotation = 90.0F;
stamp.IsBackground = true;
// Set particular pages (page 2)
stamp.Pages = new[] { 2 };
// Add stamp to PDF file
fileStamp.AddStamp(stamp);
// Save the document
fileStamp.Save(dataDir + "AddImageStamp-Page_out.pdf");
}
}
Control image quality when adding as stamp
When adding Image as stamp object, you can also control the quality of image. In order to accomplish this requirement, Quality property is added for Stamp class. It indicates the quality of image in percents (valid values are 0..100).
Add Image Stamp on Particular Pages in a PDF File
PdfFileStamp class allows you to add image stamp on particular pages of a PDF file. In order to add image stamp, you first need to create objects of PdfFileStamp and Stamp classes. You also need to create the image stamp using BindImage method of Stamp class. You can set other attributes like origin, rotation, background etc. using Stamp object as well. As you want to add image stamp on particular pages of the PDF file, you also need to set the Pages property of the Stamp class. This property requires an integer array containing numbers of the pages on which you want to add the stamp. Then you can add the stamp in the PDF file using AddStamp method of PdfFileStamp class. Finally, save the output PDF file using Close method of PdfFileStamp class. The following code snippet shows you how to add image stamp on particular pages in a PDF file.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddImageStampOnParticularPagesInPdfFile()
{
var dataDir = RunExamples.GetDataDir_AsposePdf_Images(); // Using dynamic path
// Create PdfFileStamp object using 'using' block to ensure proper disposal
using (var fileStamp = new Aspose.Pdf.Facades.PdfFileStamp())
{
// Open Document
fileStamp.BindPdf(dataDir + "sample.pdf");
// Create stamp
var stamp = new Aspose.Pdf.Facades.Stamp();
stamp.BindImage(dataDir + "StampImage.png");
stamp.SetOrigin(10, 200);
stamp.Rotation = 90.0F;
stamp.IsBackground = true;
// Add stamp to PDF file
fileStamp.AddStamp(stamp);
// Save the document
fileStamp.Save(dataDir + "AddImageStamp-All_out.pdf");
}
}