Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions facades-stamps/AGENTS.md

Large diffs are not rendered by default.

67 changes: 0 additions & 67 deletions facades-stamps/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,54 +1,12 @@
using System;
using System.IO;
using Aspose.Pdf;
using Aspose.Pdf.Facades;

class Program
{
static void Main()
{
// Input PDF, output PDF and watermark image paths
const string inputPdf = "input.pdf";
const string outputPdf = "output.pdf";
const string watermarkImage = "watermark.png";

// Verify files exist
if (!File.Exists(inputPdf))
{
Console.Error.WriteLine($"Input file not found: {inputPdf}");
return;
}
if (!File.Exists(watermarkImage))
{
Console.Error.WriteLine($"Watermark image not found: {watermarkImage}");
return;
}

// Initialize PdfFileStamp facade and bind the source PDF
PdfFileStamp fileStamp = new PdfFileStamp();
fileStamp.BindPdf(inputPdf); // Load source PDF

// Create a stamp that will be used as a background watermark
Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();

// Bind an image to the stamp (you could also use BindLogo for text)
stamp.BindImage(watermarkImage);

// Make the stamp appear behind existing page content
stamp.IsBackground = true;

// Apply the stamp only to pages 2 through 5 (1‑based indexing)
stamp.Pages = new int[] { 2, 3, 4, 5 };

// Add the configured stamp to the PDF
fileStamp.AddStamp(stamp);

// Save the result to the output file
fileStamp.Save(outputPdf);

// Close the facade (releases resources)
fileStamp.Close();

Console.WriteLine($"Background watermark applied to pages 2‑5 and saved as '{outputPdf}'.");
}
}
// URL-STABILITY STUB
//
// add background image watermark to specific pdf pages
//
// This example has been consolidated or moved. Current location:
// https://github.com/aspose-pdf/agentic-net-examples/blob/main/facades-stamps/add-background-watermark-to-specific-pdf-pages.cs
//
// This stub keeps the original URL live for existing bookmarks,
// search-engine indexes, and blog-post links. See the canonical
// location above for the current, maintained implementation.

class Program { static void Main() { } }
58 changes: 58 additions & 0 deletions facades-stamps/add-background-watermark-to-specific-pdf-pages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.IO;
using System.Drawing; // For System.Drawing.Color
using Aspose.Pdf.Facades; // Facade classes: PdfFileStamp, Stamp, FormattedText, EncodingType

class Program
{
static void Main()
{
const string inputPath = "input.pdf";
const string outputPath = "output.pdf";

// Verify input file exists
if (!File.Exists(inputPath))
{
Console.Error.WriteLine($"Input file not found: {inputPath}");
return;
}

// Initialize the PdfFileStamp facade (no using – it does not implement IDisposable)
PdfFileStamp fileStamp = new PdfFileStamp();

// Load the source PDF
fileStamp.BindPdf(inputPath);

// Create a stamp object
Stamp stamp = new Stamp();

// Make the stamp a background watermark
stamp.IsBackground = true;

// Apply the stamp only to pages 2 through 5 (1‑based indexing)
stamp.Pages = new int[] { 2, 3, 4, 5 };

// Prepare formatted text for the watermark
FormattedText ft = new FormattedText(
"CONFIDENTIAL", // Text to display
Color.LightGray, // Text color (System.Drawing.Color)
"Helvetica", // Font name
EncodingType.Winansi, // Text encoding
false, // Do not embed the font
72); // Font size

// Bind the formatted text to the stamp
stamp.BindLogo(ft);

// Add the configured stamp to the PDF
fileStamp.AddStamp(stamp);

// Save the resulting PDF
fileStamp.Save(outputPath);

// Release resources
fileStamp.Close();

Console.WriteLine($"Background watermark applied to pages 2‑5 and saved as '{outputPath}'.");
}
}
55 changes: 12 additions & 43 deletions facades-stamps/add-barcode-header-to-pdf-pages.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,12 @@
using System;
using System.IO;
using Aspose.Pdf;
using Aspose.Pdf.Facades;

class Program
{
static void Main()
{
// Paths – adjust as needed
const string inputPdfPath = "input.pdf";
const string outputPdfPath = "output_with_barcode_header.pdf";
const string barcodeImgPath = "barcode.png"; // pre‑generated barcode image

// Verify files exist
if (!File.Exists(inputPdfPath))
{
Console.Error.WriteLine($"Input PDF not found: {inputPdfPath}");
return;
}
if (!File.Exists(barcodeImgPath))
{
Console.Error.WriteLine($"Barcode image not found: {barcodeImgPath}");
return;
}

// PdfFileStamp does NOT implement IDisposable – no using block required.
// Set input and output files via properties (the recommended way).
PdfFileStamp fileStamp = new PdfFileStamp();
fileStamp.InputFile = inputPdfPath;
fileStamp.OutputFile = outputPdfPath;

// Add the barcode image as a header.
// The second argument is the top margin (in points) from the top edge of each page.
// Adjust the margin as needed to position the header correctly.
fileStamp.AddHeader(barcodeImgPath, topMargin: 20f);

// Finalize and write the result.
fileStamp.Close();

Console.WriteLine($"Header with barcode added. Output saved to '{outputPdfPath}'.");
}
}
// URL-STABILITY STUB
//
// add barcode header to pdf pages
//
// This example has been consolidated or moved. Current location:
// https://github.com/aspose-pdf/agentic-net-examples/tree/main/facades-stamps
//
// This stub keeps the original URL live for existing bookmarks,
// search-engine indexes, and blog-post links. See the canonical
// location above for the current, maintained implementation.

class Program { static void Main() { } }
65 changes: 65 additions & 0 deletions facades-stamps/add-confidential-text-and-logo-stamp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.IO;
using Aspose.Pdf.Facades; // Stamp, FormattedText, EncodingType
using System.Drawing; // for Color

class Program
{
static void Main()
{
// Paths – adjust as needed
const string inputPdf = "input.pdf";
const string outputPdf = "output.pdf";
const string logoPath = "logo.png";

// Verify files exist
if (!File.Exists(inputPdf))
{
Console.Error.WriteLine($"Input PDF not found: {inputPdf}");
return;
}
if (!File.Exists(logoPath))
{
Console.Error.WriteLine($"Logo image not found: {logoPath}");
return;
}

// Initialize the PdfFileStamp facade and bind the source PDF
PdfFileStamp fileStamp = new PdfFileStamp();
fileStamp.BindPdf(inputPdf); // loads the document to be stamped

// Create formatted text for the word "Confidential" in bold
FormattedText confidentialText = new FormattedText(
"Confidential", // text
Color.Red, // text color (System.Drawing.Color)
"Helvetica-Bold", // bold font name
EncodingType.Winansi, // encoding
false, // embed font?
36); // font size

// Create a Stamp and bind both the text and the logo image
Stamp stamp = new Stamp();
stamp.BindLogo(confidentialText); // bind the formatted text
stamp.BindImage(logoPath); // bind the logo image

// Position the stamp (origin is the lower‑left corner of the stamp)
stamp.SetOrigin(100f, 500f); // X, Y in points

// Optionally set the size of the image part of the stamp
stamp.SetImageSize(80f, 80f); // width, height in points

// Make the stamp appear behind the page content (optional)
stamp.IsBackground = true;

// Add the stamp to the PDF
fileStamp.AddStamp(stamp);

// Save the stamped PDF
fileStamp.Save(outputPdf);

// Close the facade (releases resources)
fileStamp.Close();

Console.WriteLine($"Stamped PDF saved to '{outputPdf}'.");
}
}
67 changes: 12 additions & 55 deletions facades-stamps/add-creation-date-stamp-to-pdf.cs
Original file line number Diff line number Diff line change
@@ -1,55 +1,12 @@
using System;
using Aspose.Pdf;
using Aspose.Pdf.Text;
using Aspose.Pdf.Drawing; // needed for HorizontalAlignment & VerticalAlignment

class Program
{
static void Main()
{
// Paths to the source PDF and the resulting PDF
const string inputPath = "input.pdf";
const string outputPath = "output.pdf";

// ---------------------------------------------------------------------
// Ensure an input PDF exists for the sandbox. If it does not, create a
// minimal document, add a single blank page and save it to the expected
// location. This follows the "hardcoded-input-file-generate-inline-first"
// rule required for the execution environment.
// ---------------------------------------------------------------------
if (!System.IO.File.Exists(inputPath))
{
using (Document seed = new Document())
{
seed.Pages.Add(); // add a blank page
seed.Save(inputPath);
}
}

// Load the PDF document
Document pdfDocument = new Document(inputPath);

// Use the document's creation date if available; otherwise fall back to current date
DateTime creationDate = pdfDocument.Info?.CreationDate ?? DateTime.Now;
string dateText = creationDate.ToString("yyyy-MM-dd");

// Create a TextStamp for the date
TextStamp dateStamp = new TextStamp(dateText)
{
TextState = { Font = FontRepository.FindFont("Helvetica"), FontSize = 12, ForegroundColor = Color.Black },
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Top,
XIndent = 20f, // left margin
YIndent = 20f // top margin
};

// Add the stamp to every page (or just the first page if preferred)
foreach (Page page in pdfDocument.Pages)
{
page.AddStamp(dateStamp);
}

// Save the modified PDF
pdfDocument.Save(outputPath);
}
}
// URL-STABILITY STUB
//
// add creation date stamp to pdf
//
// This example has been consolidated or moved. Current location:
// https://github.com/aspose-pdf/agentic-net-examples/blob/main/facades-stamps/add-creation-date-stamp.cs
//
// This stub keeps the original URL live for existing bookmarks,
// search-engine indexes, and blog-post links. See the canonical
// location above for the current, maintained implementation.

class Program { static void Main() { } }
Loading
Loading