diff --git a/facades-stamps/add-background-text-stamp-30-opacity.cs b/facades-stamps/add-background-text-stamp-30-opacity.cs new file mode 100644 index 00000000..42485b53 --- /dev/null +++ b/facades-stamps/add-background-text-stamp-30-opacity.cs @@ -0,0 +1,44 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Text; + +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; + } + + // Load the PDF document + var document = new Document(inputPath); + + // Create a text stamp that will act as a background watermark + var stamp = new TextStamp("CONFIDENTIAL"); + stamp.TextState.Font = FontRepository.FindFont("Helvetica"); + stamp.TextState.FontSize = 48; + stamp.TextState.ForegroundColor = Aspose.Pdf.Color.Gray; + stamp.Opacity = 0.3f; // 30% opacity + stamp.Background = true; // place behind page content + stamp.HorizontalAlignment = HorizontalAlignment.Center; + stamp.VerticalAlignment = VerticalAlignment.Center; + + // Apply the stamp to every page + foreach (Page page in document.Pages) + { + page.AddStamp(stamp); + } + + // Save the modified PDF + document.Save(outputPath); + + Console.WriteLine($"Background stamp applied with 30% opacity: {outputPath}"); + } +} diff --git a/facades-stamps/add-background-watermark-stamp-to-pdf-pages.cs b/facades-stamps/add-background-watermark-stamp-to-pdf-pages.cs new file mode 100644 index 00000000..c3c6789d --- /dev/null +++ b/facades-stamps/add-background-watermark-stamp-to-pdf-pages.cs @@ -0,0 +1,52 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; +using System.Drawing; // for System.Drawing.Color + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Initialize the PdfFileStamp facade using the modern API. + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(inputPath); // replaces the obsolete InputFile property + + // Create a stamp that will be used as a background watermark. + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + + // Build the formatted text for the watermark. + // NOTE: Use System.Drawing.Color for the color argument and a float for the font size. + Aspose.Pdf.Facades.FormattedText ft = new Aspose.Pdf.Facades.FormattedText( + "CONFIDENTIAL", // text + System.Drawing.Color.Gray, // text color (System.Drawing.Color) + "Helvetica", // font name + EncodingType.Winansi, // encoding + false, // embed font? + 48f); // font size (float) + + stamp.BindLogo(ft); // bind the formatted text to the stamp + stamp.IsBackground = true; // place the stamp behind existing page content + + // Apply the stamp only to pages 2 through 5 (1‑based indexing). + stamp.Pages = new int[] { 2, 3, 4, 5 }; + + // Add the stamp to the document. + fileStamp.AddStamp(stamp); + + // Save the modified PDF using the modern API. + fileStamp.Save(outputPath); // replaces the obsolete OutputFile property + fileStamp.Close(); + + Console.WriteLine($"Background watermark applied to pages 2‑5 and saved as '{outputPath}'."); + } +} diff --git a/facades-stamps/add-creation-date-stamp-to-pdf.cs b/facades-stamps/add-creation-date-stamp-to-pdf.cs new file mode 100644 index 00000000..d2bc07c9 --- /dev/null +++ b/facades-stamps/add-creation-date-stamp-to-pdf.cs @@ -0,0 +1,46 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Text; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Load the source PDF + Document doc = new Document(inputPath); + + // Retrieve the document creation date and format it as yyyy-MM-dd + DateTime creationDate = doc.Info.CreationDate; + string dateText = creationDate.ToString("yyyy-MM-dd"); + + // Create a text stamp that will be placed at the top‑left corner + TextStamp stamp = new TextStamp(dateText); + stamp.TextState.Font = FontRepository.FindFont("Helvetica"); + stamp.TextState.FontSize = 12; + stamp.TextState.ForegroundColor = Aspose.Pdf.Color.Black; // fully‑qualified Aspose color + stamp.HorizontalAlignment = HorizontalAlignment.Left; + stamp.VerticalAlignment = VerticalAlignment.Top; + stamp.XIndent = 10f; // margin from the left edge + stamp.YIndent = 10f; // margin from the top edge + + // Apply the stamp to every page (or change to a specific page if needed) + foreach (Page page in doc.Pages) + { + page.AddStamp(stamp); + } + + // Save the stamped PDF + doc.Save(outputPath); + Console.WriteLine($"Stamped PDF saved to '{outputPath}'."); + } +} diff --git a/facades-stamps/add-custom-border-stamp-to-pdf-page.cs b/facades-stamps/add-custom-border-stamp-to-pdf-page.cs new file mode 100644 index 00000000..1373e771 --- /dev/null +++ b/facades-stamps/add-custom-border-stamp-to-pdf-page.cs @@ -0,0 +1,48 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "highlighted.pdf"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"File not found: {inputPath}"); + return; + } + + // Use PdfContentEditor (facade) to add a square annotation with custom border thickness and color. + using (PdfContentEditor editor = new PdfContentEditor()) + { + // Bind the existing PDF document. + editor.BindPdf(inputPath); + + // Define the area to highlight on the page (x, y, width, height). + // Fully qualify System.Drawing.Rectangle to avoid ambiguity with Aspose.Pdf.Rectangle. + var highlightRect = new System.Drawing.Rectangle(100, 500, 200, 100); + + // Create a square annotation: + // - contents: description shown when the annotation is selected. + // - color: border color (red in this example). + // - square: true (square shape; false would create a circle). + // - page: 1 (Aspose.Pdf uses 1‑based page indexing). + // - borderWidth: custom thickness of the border (5 points here). + editor.CreateSquareCircle( + highlightRect, + "Important Section", + System.Drawing.Color.Red, + true, + 1, + 5); + + // Save the modified PDF. + editor.Save(outputPath); + } + + Console.WriteLine($"Stamped PDF saved to '{outputPath}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/add-disclaimer-stamp-to-first-page.cs b/facades-stamps/add-disclaimer-stamp-to-first-page.cs new file mode 100644 index 00000000..7aa0f728 --- /dev/null +++ b/facades-stamps/add-disclaimer-stamp-to-first-page.cs @@ -0,0 +1,53 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + // Paths – adjust as needed + const string inputPdf = "target.pdf"; // PDF to be stamped + const string disclaimerPdf = "disclaimer.pdf"; // PDF containing the legal disclaimer (first page will be used) + const string outputPdf = "target_with_disclaimer.pdf"; + + // Verify files exist + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); + return; + } + if (!File.Exists(disclaimerPdf)) + { + Console.Error.WriteLine($"Disclaimer PDF not found: {disclaimerPdf}"); + return; + } + + // Initialize the facade, bind the source document and configure the stamp + PdfFileStamp fileStamp = new PdfFileStamp(); + try + { + // Bind the target PDF that will receive the stamp + fileStamp.BindPdf(inputPdf); + + // Create a stamp that uses the first page of the disclaimer PDF + Stamp stamp = new Stamp(); + stamp.BindPdf(disclaimerPdf, 1); // use page 1 of disclaimer.pdf as stamp content + stamp.IsBackground = false; // place stamp on top of existing content + stamp.Pages = new int[] { 1 }; // apply only to the first page of the target PDF + + // Add the stamp to the document + fileStamp.AddStamp(stamp); + + // Save the result + fileStamp.Save(outputPdf); + } + finally + { + // Close releases resources; PdfFileStamp does not implement IDisposable + fileStamp.Close(); + } + + Console.WriteLine($"Stamped PDF saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/add-dynamic-text-stamp-to-pdf.cs b/facades-stamps/add-dynamic-text-stamp-to-pdf.cs new file mode 100644 index 00000000..f37dfcc2 --- /dev/null +++ b/facades-stamps/add-dynamic-text-stamp-to-pdf.cs @@ -0,0 +1,43 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Text; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + const string author = "John Doe"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"File not found: {inputPath}"); + return; + } + + // Load the PDF document inside a using block for deterministic disposal + using (Aspose.Pdf.Document doc = new Aspose.Pdf.Document(inputPath)) + { + // Create a text stamp with interpolated content (date and author) + string stampText = $"Created on {DateTime.Now:yyyy-MM-dd} by {author}"; + Aspose.Pdf.TextStamp textStamp = new Aspose.Pdf.TextStamp(stampText); + + // Configure stamp appearance (optional) + textStamp.Background = false; // draw on top of page content + textStamp.Opacity = 0.7; // semi‑transparent + textStamp.HorizontalAlignment = HorizontalAlignment.Center; + textStamp.VerticalAlignment = VerticalAlignment.Bottom; + textStamp.YIndent = 20; // distance from bottom edge + + // Add the stamp to the first page (pages are 1‑based) + doc.Pages[1].AddStamp(textStamp); + + // Save the modified PDF + doc.Save(outputPath); + } + + Console.WriteLine($"Stamp added and saved to '{outputPath}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/add-file-name-header-stamp.cs b/facades-stamps/add-file-name-header-stamp.cs new file mode 100644 index 00000000..6cc55df1 --- /dev/null +++ b/facades-stamps/add-file-name-header-stamp.cs @@ -0,0 +1,43 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Text; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"File not found: {inputPath}"); + return; + } + + // Load the PDF document + Document pdfDocument = new Document(inputPath); + + // Create a TextStamp that uses the {FileName} placeholder. + // Aspose.Pdf replaces {FileName} with the actual file name when the stamp is applied. + TextStamp headerStamp = new TextStamp("{FileName}"); + headerStamp.TextState.Font = FontRepository.FindFont("Helvetica"); + headerStamp.TextState.FontSize = 12; + headerStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Black; + headerStamp.HorizontalAlignment = HorizontalAlignment.Center; + headerStamp.VerticalAlignment = VerticalAlignment.Top; + headerStamp.YIndent = 20f; // top margin in points + + // Apply the stamp to every page + foreach (Page page in pdfDocument.Pages) + { + page.AddStamp(headerStamp); + } + + // Save the modified PDF + pdfDocument.Save(outputPath); + + Console.WriteLine($"Stamped PDF saved to '{outputPath}'."); + } +} diff --git a/facades-stamps/add-footer-date-stamp-to-last-page.cs b/facades-stamps/add-footer-date-stamp-to-last-page.cs new file mode 100644 index 00000000..855e1e5f --- /dev/null +++ b/facades-stamps/add-footer-date-stamp-to-last-page.cs @@ -0,0 +1,43 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Text; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output_lastpage_footer.pdf"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Load the PDF document + Document doc = new Document(inputPath); + // Get the last page (pages are 1‑based) + Page lastPage = doc.Pages[doc.Pages.Count]; + + // Prepare footer text (current date in MM-dd-yyyy format) + string footerText = DateTime.Now.ToString("MM-dd-yyyy"); + + // Create a text stamp for the footer + TextStamp stamp = new TextStamp(footerText); + stamp.TextState.Font = FontRepository.FindFont("Helvetica"); + stamp.TextState.FontSize = 12; + stamp.TextState.ForegroundColor = Aspose.Pdf.Color.Black; + stamp.HorizontalAlignment = HorizontalAlignment.Center; + stamp.VerticalAlignment = VerticalAlignment.Bottom; + stamp.YIndent = 10; // distance from the bottom edge + + // Add the stamp only to the last page + lastPage.AddStamp(stamp); + + // Save the modified PDF + doc.Save(outputPath); + Console.WriteLine($"Footer stamp added to last page. Output saved to '{outputPath}'."); + } +} diff --git a/facades-stamps/add-footer-stamp-10pt-above-bottom.cs b/facades-stamps/add-footer-stamp-10pt-above-bottom.cs new file mode 100644 index 00000000..d2a06414 --- /dev/null +++ b/facades-stamps/add-footer-stamp-10pt-above-bottom.cs @@ -0,0 +1,34 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; // PdfFileStamp and FormattedText are defined here + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + + // Verify that the source PDF exists + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Create a PdfFileStamp facade with input and output files + PdfFileStamp fileStamp = new PdfFileStamp(inputPath, outputPath); + + // Prepare the footer text (default font/color are used) + FormattedText footerText = new FormattedText("Footer placed 10 pt above bottom edge"); + + // Add the footer with a bottom margin of 10 points. + // Left and right margins are set to 0 (centered horizontally). + fileStamp.AddFooter(footerText, 10f, 0f, 0f); + + // Close the facade to write the result to the output file + fileStamp.Close(); + + Console.WriteLine($"Footer stamp added. Output saved to '{outputPath}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/add-footer-with-page-count.cs b/facades-stamps/add-footer-with-page-count.cs new file mode 100644 index 00000000..cb5c3daf --- /dev/null +++ b/facades-stamps/add-footer-with-page-count.cs @@ -0,0 +1,43 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; +using Aspose.Pdf.Text; + +class Program +{ + static void Main() + { + // Paths to the source PDF and the resulting PDF with footer. + const string inputPdf = "input.pdf"; + const string outputPdf = "output.pdf"; + + // Verify that the input file exists. + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input file not found: {inputPdf}"); + return; + } + + // Create a PdfFileStamp facade and bind it to the source PDF. + // PdfFileStamp implements IDisposable via SaveableFacade, so we use a using block. + using (PdfFileStamp stampFacade = new PdfFileStamp()) + { + // Bind the source PDF file. + stampFacade.BindPdf(inputPdf); + + // Create a FormattedText object that contains the placeholder for total page count. + // The placeholder {page_count} is recognized by Aspose.Pdf and will be replaced + // with the actual number of pages when the document is saved. + FormattedText footerText = new FormattedText("Page {page_count}"); + + // Add the footer to all pages. The second argument is the bottom margin (in points). + stampFacade.AddFooter(footerText, 10f); + + // Save the modified PDF to the output path. + stampFacade.Save(outputPdf); + } + + Console.WriteLine($"Footer with page count added successfully: {outputPdf}"); + } +} \ No newline at end of file diff --git a/facades-stamps/add-header-stamp-to-pdf-pages.cs b/facades-stamps/add-header-stamp-to-pdf-pages.cs new file mode 100644 index 00000000..9aa6e6dc --- /dev/null +++ b/facades-stamps/add-header-stamp-to-pdf-pages.cs @@ -0,0 +1,45 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Text; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + const string companyName = "Acme Corporation"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Load the document. + using (Document doc = new Document(inputPath)) + { + // Iterate through each page and add a header stamp. + foreach (Page page in doc.Pages) + { + // Create a TextStamp for the header. + TextStamp headerStamp = new TextStamp(companyName); + headerStamp.TextState.Font = FontRepository.FindFont("Helvetica"); + headerStamp.TextState.FontSize = 12; + headerStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Black; + headerStamp.HorizontalAlignment = HorizontalAlignment.Center; + headerStamp.VerticalAlignment = VerticalAlignment.Top; + headerStamp.YIndent = 20f; // offset from the top edge + + // Add the stamp to the current page. + page.AddStamp(headerStamp); + } + + // Save the modified document. + doc.Save(outputPath); + } + + Console.WriteLine($"Header stamp added to all pages. Output saved to '{outputPath}'."); + } +} diff --git a/facades-stamps/add-logo-confidential-stamp-to-pdf.cs b/facades-stamps/add-logo-confidential-stamp-to-pdf.cs new file mode 100644 index 00000000..f9d1957b --- /dev/null +++ b/facades-stamps/add-logo-confidential-stamp-to-pdf.cs @@ -0,0 +1,71 @@ +using System; +using System.IO; +using System.Drawing; // Required for System.Drawing.Color +using Aspose.Pdf.Facades; // PdfFileStamp, Stamp, FormattedText, EncodingType + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; // Source PDF + const string outputPdf = "stamped_output.pdf"; // Destination PDF + const string logoPath = "logo.png"; // Company logo image + + // Verify that required 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; + } + + // Use PdfFileStamp facade to load, stamp, and save the document + using (PdfFileStamp fileStamp = new PdfFileStamp()) + { + // Load the source PDF + fileStamp.BindPdf(inputPdf); + + // Create a new stamp instance + Stamp stamp = new Stamp(); + + // Position the stamp (lower‑left corner coordinates, in points) + stamp.SetOrigin(100, 500); // Adjust X/Y as needed + + // Make the stamp appear behind page content + stamp.IsBackground = true; + + // Set semi‑transparent opacity + stamp.Opacity = 0.5f; + + // Bind the company logo image to the stamp + stamp.BindImage(logoPath); + // Optionally define the image size (width, height) + stamp.SetImageSize(100, 100); // Adjust size as needed + + // Create formatted text for the word "Confidential" in bold + FormattedText ft = new FormattedText( + "Confidential", // Text content + Color.Red, // Text color + "Helvetica-Bold", // Bold font (use a bold variant) + EncodingType.Winansi, // Text encoding + false, // Do not embed the font + 36); // Font size + + // Bind the formatted text to the same stamp + stamp.BindLogo(ft); + + // Apply the stamp to all pages of the document + fileStamp.AddStamp(stamp); + + // Save the stamped PDF + fileStamp.Save(outputPdf); + fileStamp.Close(); + } + + Console.WriteLine($"Stamped PDF saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/add-lower-roman-page-numbers-odd-pages.cs b/facades-stamps/add-lower-roman-page-numbers-odd-pages.cs new file mode 100644 index 00000000..ebb33f45 --- /dev/null +++ b/facades-stamps/add-lower-roman-page-numbers-odd-pages.cs @@ -0,0 +1,56 @@ +using System; +using System.IO; +using System.Linq; +using Aspose.Pdf; +using Aspose.Pdf.Text; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Load the PDF document + Document doc = new Document(inputPath); + int pageCount = doc.Pages.Count; + + // Determine odd pages (1‑based indexing) + int[] oddPages = Enumerable.Range(1, pageCount) + .Where(p => p % 2 == 1) + .ToArray(); + + // Create a PageNumberStamp that will render the page number in lower‑roman style. + // "#" is the placeholder that Aspose.Pdf replaces with the actual page number. + PageNumberStamp pageNumberStamp = new PageNumberStamp() + { + Value = "#", + NumberingStyle = NumberingStyle.NumeralsRomanLowercase, + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Bottom, + YIndent = 20, // distance from the bottom edge + TextState = + { + Font = FontRepository.FindFont("Helvetica"), + FontSize = 12, + ForegroundColor = Color.Black + } + }; + + // Apply the stamp only to odd pages. + foreach (int pageNum in oddPages) + { + doc.Pages[pageNum].AddStamp(pageNumberStamp); + } + + // Save the modified PDF. + doc.Save(outputPath); + Console.WriteLine($"Page numbers added to odd pages (lower‑roman) and saved as '{outputPath}'."); + } +} diff --git a/facades-stamps/add-multi-line-text-watermark.cs b/facades-stamps/add-multi-line-text-watermark.cs new file mode 100644 index 00000000..bf7624d6 --- /dev/null +++ b/facades-stamps/add-multi-line-text-watermark.cs @@ -0,0 +1,46 @@ +using System; +using System.IO; +using System.Drawing; +using Aspose.Pdf; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "watermarked.pdf"; + + // Ensure the source PDF exists; create a placeholder if it does not. + if (!File.Exists(inputPath)) + { + using (Document placeholder = new Document()) + { + placeholder.Pages.Add(); + placeholder.Save(inputPath); + } + } + + // Create a multi‑line formatted text watermark. + var ft = new Aspose.Pdf.Facades.FormattedText( + "Confidential", // first line + System.Drawing.Color.Red, // text color (System.Drawing) + "Helvetica", // font name + Aspose.Pdf.Facades.EncodingType.Winansi, + false, // embed font flag + 48f); // font size (float) + + ft.AddNewLineText("Do Not Distribute"); + ft.AddNewLineText("Company XYZ"); + + // Apply the watermark to every page using PdfFileStamp. + using (PdfFileStamp stamp = new PdfFileStamp()) + { + stamp.BindPdf(inputPath); + stamp.AddHeader(ft, 0); // 0 = default vertical offset + stamp.Save(outputPath); + } + + Console.WriteLine($"Watermarked PDF saved to '{outputPath}'."); + } +} diff --git a/facades-stamps/add-multi-line-watermark-pdffilemend.cs b/facades-stamps/add-multi-line-watermark-pdffilemend.cs new file mode 100644 index 00000000..edaaef9d --- /dev/null +++ b/facades-stamps/add-multi-line-watermark-pdffilemend.cs @@ -0,0 +1,82 @@ +using System; +using System.IO; +using System.Drawing; // System.Drawing.Color for Facades.FormattedText +using Aspose.Pdf; +using Aspose.Pdf.Facades; +using Aspose.Pdf.Facades; // for EncodingType, FormattedText, PdfFileMend + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; + const string outputPdf = "watermarked.pdf"; + + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input file not found: {inputPdf}"); + return; + } + + // Load the PDF document + using (Document doc = new Document(inputPdf)) + { + // Prepare an array with all page numbers (1‑based) + int pageCount = doc.Pages.Count; + int[] allPages = new int[pageCount]; + for (int i = 0; i < pageCount; i++) + allPages[i] = i + 1; + + // Use PdfFileMend (Facades) – it works with Facades.FormattedText + PdfFileMend mend = new PdfFileMend(); + mend.BindPdf(doc); + + // ----------------------------------------------------------------- + // First line – bold red Helvetica, size 36 + // ----------------------------------------------------------------- + FormattedText line1 = new FormattedText( + "Confidential", + System.Drawing.Color.Red, // System.Drawing.Color required by Facades.FormattedText + "Helvetica", + EncodingType.Winansi, + false, + 36f); // font size as float + // Add the text to every page. Rectangle coordinates are (llx, lly, urx, ury). + mend.AddText(line1, allPages, 100f, 700f, 500f, 720f); + + // ----------------------------------------------------------------- + // Second line – green Times New Roman, size 28 (with an extra blank line) + // ----------------------------------------------------------------- + FormattedText line2 = new FormattedText( + "Do Not Distribute", + System.Drawing.Color.Green, + "TimesNewRoman", + EncodingType.Winansi, + false, + 28f); + // Add a blank line with extra spacing using AddNewLineText + line2.AddNewLineText(string.Empty, 10f); + mend.AddText(line2, allPages, 100f, 660f, 500f, 680f); + + // ----------------------------------------------------------------- + // Third line – blue Courier, size 24 with a subtitle underneath + // ----------------------------------------------------------------- + FormattedText line3 = new FormattedText( + "Internal Use Only", + System.Drawing.Color.Blue, + "Courier", + EncodingType.Winansi, + false, + 24f); + // Add a second line (subtitle) inside the same FormattedText instance + line3.AddNewLineText("Version 1.0", 5f); + mend.AddText(line3, allPages, 100f, 620f, 500f, 640f); + + // Save the watermarked PDF + mend.Save(outputPdf); + mend.Close(); + } + + Console.WriteLine($"Watermarked PDF saved to '{outputPdf}'."); + } +} diff --git a/facades-stamps/add-page-number-stamp-arabic-numerals.cs b/facades-stamps/add-page-number-stamp-arabic-numerals.cs new file mode 100644 index 00000000..016ccf52 --- /dev/null +++ b/facades-stamps/add-page-number-stamp-arabic-numerals.cs @@ -0,0 +1,41 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"File not found: {inputPath}"); + return; + } + + // Initialize the PdfFileStamp facade + PdfFileStamp fileStamp = new PdfFileStamp(); + + // Load the source PDF + fileStamp.BindPdf(inputPath); + + // Use Arabic numerals (default) and start numbering at 1 + fileStamp.NumberingStyle = NumberingStyle.NumeralsArabic; + fileStamp.StartingNumber = 1; + + // Add page numbers. The placeholder '#' is replaced with the page number. + // Leading zeros are not directly supported by PdfFileStamp; this adds plain numbers. + fileStamp.AddPageNumber("Page #"); + + // Save the stamped PDF + fileStamp.Save(outputPath); + + // Release resources + fileStamp.Close(); + + Console.WriteLine($"Page numbers added to '{outputPath}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/add-page-number-stamp-to-pdf.cs b/facades-stamps/add-page-number-stamp-to-pdf.cs new file mode 100644 index 00000000..dab3b84f --- /dev/null +++ b/facades-stamps/add-page-number-stamp-to-pdf.cs @@ -0,0 +1,40 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // PdfFileStamp is a facade that handles loading and saving internally. + // It does not implement IDisposable, so we do not wrap it in a using block. + // Use BindPdf to load the source PDF, AddPageNumber to add the stamp, + // then Save the result and finally close the facade. + PdfFileStamp fileStamp = new PdfFileStamp(); + + // Load the source PDF. + fileStamp.BindPdf(inputPath); + + // Add a page number stamp. + // Aspose.Pdf uses the '#' character as a placeholder for the current page number. + // The requested {page_number} placeholder is therefore expressed as "#". + fileStamp.AddPageNumber("Page #"); + + // Write the stamped PDF to the output file. + fileStamp.Save(outputPath); + + // Release resources. + fileStamp.Close(); + + Console.WriteLine($"Stamped PDF saved to '{outputPath}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/add-qr-code-text-stamp-to-pdf.cs b/facades-stamps/add-qr-code-text-stamp-to-pdf.cs new file mode 100644 index 00000000..2fcb28dc --- /dev/null +++ b/facades-stamps/add-qr-code-text-stamp-to-pdf.cs @@ -0,0 +1,67 @@ +using System; +using System.IO; +using System.Drawing; // for Color +using Aspose.Pdf; +using Aspose.Pdf.Facades; + +class ProductVerificationStamp +{ + static void Main() + { + // Paths – adjust as needed + const string inputPdfPath = "product_catalog.pdf"; // PDF to stamp + const string outputPdfPath = "product_catalog_stamped.pdf"; + const string qrCodeImagePath = "qr_code.png"; // QR code image file + const string verificationText = "Verify product at https://example.com/verify"; + + // Ensure files exist + if (!File.Exists(inputPdfPath)) + { + Console.Error.WriteLine($"Input PDF not found: {inputPdfPath}"); + return; + } + if (!File.Exists(qrCodeImagePath)) + { + Console.Error.WriteLine($"QR code image not found: {qrCodeImagePath}"); + return; + } + + // Initialize PdfFileStamp facade using the non‑obsolete API + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(inputPdfPath); + + // Create a stamp (Aspose.Pdf.Facades.Stamp) + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + + // Position the stamp (origin is lower‑left corner of the page) + stamp.SetOrigin(100, 500); // X = 100, Y = 500 (adjust as needed) + stamp.SetImageSize(120, 120); // Width = 120, Height = 120 + stamp.Opacity = 0.85f; + stamp.IsBackground = false; + + // Bind the QR code image to the stamp + stamp.BindImage(qrCodeImagePath); + + // Prepare formatted text for the descriptive message + // Use System.Drawing.Color, fully‑qualified Facades types, and a float font size + Aspose.Pdf.Facades.FormattedText formattedText = new Aspose.Pdf.Facades.FormattedText( + verificationText, + System.Drawing.Color.Black, // Text color + "Helvetica", // Font name + Aspose.Pdf.Facades.EncodingType.Winansi, // Encoding + false, // Do not embed the font + 12f); // Font size (float) + + // Bind the formatted text (logo) to the same stamp – it will appear beside the image + stamp.BindLogo(formattedText); + + // Add the composed stamp to all pages of the PDF + fileStamp.AddStamp(stamp); + + // Save the stamped PDF and release resources + fileStamp.Save(outputPdfPath); + fileStamp.Close(); + + Console.WriteLine($"Stamped PDF saved to '{outputPdfPath}'."); + } +} diff --git a/facades-stamps/add-repeating-background-image-watermark.cs b/facades-stamps/add-repeating-background-image-watermark.cs new file mode 100644 index 00000000..0016486f --- /dev/null +++ b/facades-stamps/add-repeating-background-image-watermark.cs @@ -0,0 +1,71 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; // source PDF + const string outputPdf = "watermarked.pdf"; // result PDF + const string watermarkImage = "watermark.png"; // image to use as watermark + + 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; + } + + try + { + // Load the source PDF inside a using block for deterministic disposal. + using (Document doc = new Document(inputPdf)) + { + // Initialize the PdfFileStamp facade. + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.InputFile = inputPdf; // source file + fileStamp.OutputFile = outputPdf; // destination file + + // Create a single Aspose.Pdf.Facades.Stamp instance that will be applied to all pages. + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + + // Bind the image that will be used as the watermark. + stamp.BindImage(watermarkImage); + + // Position the watermark (origin is measured from the lower‑left corner). + stamp.SetOrigin(100, 200); // X = 100, Y = 200 + + // Define the size of the image stamp (width, height). + stamp.SetImageSize(150, 100); + + // Make the stamp a background element so it appears behind page content. + stamp.IsBackground = true; + + // Set a semi‑transparent opacity (0.0 = fully transparent, 1.0 = opaque). + stamp.Opacity = 0.5f; + + // Apply the stamp to all pages (null means every page). + stamp.Pages = null; + + // Add the stamp to the document via the facade. + fileStamp.AddStamp(stamp); + + // Persist changes and release resources. + fileStamp.Close(); + } + + Console.WriteLine($"Watermarked PDF saved to '{outputPdf}'."); + } + catch (Exception ex) + { + Console.Error.WriteLine($"Error: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/facades-stamps/add-right-aligned-logo-stamp-to-pdf-pages.cs b/facades-stamps/add-right-aligned-logo-stamp-to-pdf-pages.cs new file mode 100644 index 00000000..1eea8e3a --- /dev/null +++ b/facades-stamps/add-right-aligned-logo-stamp-to-pdf-pages.cs @@ -0,0 +1,53 @@ +using System; +using System.IO; +using Aspose.Pdf; + +class Program +{ + static void Main() + { + // Input PDF, output PDF and logo image paths + const string inputPdf = "input.pdf"; + const string outputPdf = "output.pdf"; + const string logoPath = "logo.png"; + + // Validate input files + 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; + } + + // Load the PDF document + Document pdfDocument = new Document(inputPdf); + + // Iterate over each page and apply the logo stamp aligned to the right margin + foreach (Page page in pdfDocument.Pages) + { + // Create an ImageStamp from the image file + ImageStamp stamp = new ImageStamp(logoPath) + { + // Align the stamp to the right edge of the page and center it vertically + HorizontalAlignment = HorizontalAlignment.Right, + VerticalAlignment = VerticalAlignment.Center, + // Optional: make the stamp appear in front of page content (false = foreground) + Background = false, + // Optional: set opacity (0‑1 range) + Opacity = 1.0f + }; + + // Apply the stamp to the current page + page.AddStamp(stamp); + } + + // Save the modified PDF + pdfDocument.Save(outputPdf); + + Console.WriteLine($"Logo stamp added and saved to '{outputPdf}'."); + } +} diff --git a/facades-stamps/add-rotated-image-stamp-to-first-page.cs b/facades-stamps/add-rotated-image-stamp-to-first-page.cs new file mode 100644 index 00000000..8ca217e6 --- /dev/null +++ b/facades-stamps/add-rotated-image-stamp-to-first-page.cs @@ -0,0 +1,59 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + // Directory containing the PDF files to process + const string inputDirectory = @"C:\PdfFolder"; + // Path to the image that will be used as a stamp + const string stampImagePath = @"C:\stamp.png"; + + if (!Directory.Exists(inputDirectory)) + { + Console.Error.WriteLine($"Input directory not found: {inputDirectory}"); + return; + } + + if (!File.Exists(stampImagePath)) + { + Console.Error.WriteLine($"Stamp image not found: {stampImagePath}"); + return; + } + + // Process each PDF file in the directory + foreach (string pdfPath in Directory.GetFiles(inputDirectory, "*.pdf")) + { + // Build output file name (original name + "_stamped.pdf") + string outputPath = Path.Combine( + inputDirectory, + Path.GetFileNameWithoutExtension(pdfPath) + "_stamped.pdf"); + + // Initialize the PdfFileStamp facade and bind the source PDF + using (PdfFileStamp fileStamp = new PdfFileStamp()) + { + fileStamp.BindPdf(pdfPath); + + // Configure the stamp + Stamp stamp = new Stamp(); + stamp.BindImage(stampImagePath); // use the image as stamp content + stamp.Opacity = 0.7f; // make the stamp semi‑transparent + stamp.Pages = new int[] { 1 }; // apply only to the first page + + // Position the stamp (example: 100 points from left, 500 points from bottom) + stamp.SetOrigin(100, 500); + + // Rotate the stamp by 45 degrees – use the Rotation property (degrees) + stamp.Rotation = 45f; + + // Add the stamp to the document and save the result + fileStamp.AddStamp(stamp); + fileStamp.Save(outputPath); + } + + Console.WriteLine($"Stamped PDF saved to: {outputPath}"); + } + } +} diff --git a/facades-stamps/add-semi-transparent-png-background-stamp.cs b/facades-stamps/add-semi-transparent-png-background-stamp.cs new file mode 100644 index 00000000..53a3fe67 --- /dev/null +++ b/facades-stamps/add-semi-transparent-png-background-stamp.cs @@ -0,0 +1,49 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; // Facade APIs for stamping + +class Program +{ + static void Main() + { + // Paths – adjust as needed + const string inputPdf = "input.pdf"; + const string outputPdf = "output.pdf"; + const string stampImage = "stamp.png"; // semi‑transparent PNG + + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); + return; + } + if (!File.Exists(stampImage)) + { + Console.Error.WriteLine($"Stamp image not found: {stampImage}"); + return; + } + + // Initialize the facade and bind the source PDF + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(inputPdf); // Load source PDF + + // Create a stamp that uses the PNG image + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + stamp.BindImage(stampImage); // Set image source + stamp.IsBackground = true; // Place behind page content + stamp.Opacity = 0.5f; // Semi‑transparent (0.0 – 1.0) + + // Size the stamp to cover the whole page + // PageWidth / PageHeight are available after BindPdf() + stamp.SetOrigin(0, 0); // Lower‑left corner + stamp.SetImageSize(fileStamp.PageWidth, fileStamp.PageHeight); + + // Add the stamp to all pages + fileStamp.AddStamp(stamp); + + // Save the result and release resources + fileStamp.Save(outputPdf); + fileStamp.Close(); + + Console.WriteLine($"Background stamp applied and saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/add-translucent-text-watermark-to-pdf-pages.cs b/facades-stamps/add-translucent-text-watermark-to-pdf-pages.cs new file mode 100644 index 00000000..6cef61c6 --- /dev/null +++ b/facades-stamps/add-translucent-text-watermark-to-pdf-pages.cs @@ -0,0 +1,49 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Text; + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; + const string outputPdf = "output.pdf"; + const string watermarkText = "CONFIDENTIAL"; + + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input file not found: {inputPdf}"); + return; + } + + // Load the PDF document + Document pdfDocument = new Document(inputPdf); + + // Create a text stamp that will act as a watermark + TextStamp stamp = new TextStamp(watermarkText) + { + // Center the watermark on each page + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + // Place the stamp behind the page content if the property exists (some versions expose IsBackground) + // IsBackground = true, + // 50% opacity for a translucent effect + Opacity = 0.5f + }; + + // Configure the TextState – the TextState property itself is read‑only, so set its members individually + stamp.TextState.Font = FontRepository.FindFont("Helvetica"); + stamp.TextState.FontSize = 72; + stamp.TextState.ForegroundColor = Aspose.Pdf.Color.Red; + + // Apply the stamp to every page in the document + foreach (Page page in pdfDocument.Pages) + { + page.AddStamp(stamp); + } + + // Save the modified PDF + pdfDocument.Save(outputPdf); + } +} diff --git a/facades-stamps/add-transparent-confidential-text-stamp.cs b/facades-stamps/add-transparent-confidential-text-stamp.cs new file mode 100644 index 00000000..b21bc703 --- /dev/null +++ b/facades-stamps/add-transparent-confidential-text-stamp.cs @@ -0,0 +1,54 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; +using System.Drawing; // Required for System.Drawing.Color + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "confidential_output.pdf"; + + // Pages on which the stamp should appear (1‑based indexing) + int[] selectedPages = new int[] { 1, 3, 5 }; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"File not found: {inputPath}"); + return; + } + + // Create formatted text for the stamp using the Facades overload that expects + // System.Drawing.Color and a float font size. + Aspose.Pdf.Facades.FormattedText ft = new Aspose.Pdf.Facades.FormattedText( + "CONFIDENTIAL", + System.Drawing.Color.Red, // System.Drawing.Color required + "Helvetica", + Aspose.Pdf.Facades.EncodingType.Winansi, + false, + 48f); // float font size + + // Fully qualify Stamp to avoid ambiguity with other Stamp classes + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + stamp.BindLogo(ft); // Bind the text to the stamp + stamp.Opacity = 0.7f; // 70% opacity (0 = fully transparent, 1 = opaque) + stamp.IsBackground = true; // Place stamp behind page content + stamp.Pages = selectedPages; // Apply only to selected pages + + // Optional positioning and size (adjust as needed) + stamp.SetOrigin(100, 400); // X, Y coordinates (from bottom‑left) + stamp.SetImageSize(300, 100); // Width, Height of the text bounding box + + // Use PdfFileStamp facade to apply the stamp + using (PdfFileStamp fileStamp = new PdfFileStamp()) + { + fileStamp.BindPdf(inputPath); // Load source PDF + fileStamp.AddStamp(stamp); // Add the configured stamp + fileStamp.Save(outputPath); // Save the stamped PDF + } + + Console.WriteLine($"Stamped PDF saved to '{outputPath}'."); + } +} diff --git a/facades-stamps/agents.md b/facades-stamps/agents.md new file mode 100644 index 00000000..871c323b --- /dev/null +++ b/facades-stamps/agents.md @@ -0,0 +1,126 @@ +--- +name: facades-stamps +description: C# examples for facades-stamps using Aspose.PDF for .NET +language: csharp +framework: net10.0 +parent: ../agents.md +--- + +# AGENTS - facades-stamps + +## Persona + +You are a C# developer specializing in PDF processing using Aspose.PDF for .NET, +working within the **facades-stamps** category. +This folder contains standalone C# examples for facades-stamps operations. +See the root [agents.md](../agents.md) for repository-wide conventions and boundaries. + +## Scope +- This folder contains examples for **facades-stamps**. +- Files are standalone `.cs` examples stored directly in this folder. + +## Required Namespaces + +- `using Aspose.Pdf.Facades;` (34/45 files) ← category-specific +- `using Aspose.Pdf;` (28/45 files) ← category-specific +- `using Aspose.Pdf.Text;` (15/45 files) +- `using System;` (45/45 files) +- `using System.IO;` (45/45 files) +- `using System.Drawing;` (13/45 files) +- `using System.Collections.Generic;` (2/45 files) +- `using System.Linq;` (2/45 files) +- `using System.Runtime.InteropServices;` (2/45 files) +- `using System.Drawing.Imaging;` (1/45 files) + +## Common Code Pattern + +Most files in this category use `PdfFileStamp` from `Aspose.Pdf.Facades`: + +```csharp +PdfFileStamp tool = new PdfFileStamp(); +tool.BindPdf("input.pdf"); +// ... PdfFileStamp operations ... +tool.Save("output.pdf"); +``` + +## Files in this folder + +| File | Title | Key APIs | Description | +|------|-------|----------|-------------| +| [add-background-text-stamp-30-opacity](./add-background-text-stamp-30-opacity.cs) | Add Background Text Stamp with 30% Opacity | `Document`, `TextStamp`, `FontRepository` | Demonstrates how to place a semi‑transparent text stamp behind the content of each page in a PDF ... | +| [add-background-watermark-stamp-to-pdf-pages](./add-background-watermark-stamp-to-pdf-pages.cs) | Add Background Watermark Stamp to Specific PDF Pages | `PdfFileStamp`, `BindPdf`, `AddStamp` | Demonstrates how to create a background watermark stamp using Aspose.Pdf.Facades and apply it to ... | +| [add-creation-date-stamp-to-pdf](./add-creation-date-stamp-to-pdf.cs) | Add Creation Date Stamp to PDF | `Document`, `TextStamp`, `FontRepository` | Shows how to read a PDF's creation date and place it as a text stamp in the top‑left corner of ea... | +| [add-custom-border-stamp-to-pdf-page](./add-custom-border-stamp-to-pdf-page.cs) | Add Custom Border Stamp to PDF Page | `PdfContentEditor`, `BindPdf`, `CreateSquareCircle` | Shows how to use PdfContentEditor to create a square annotation with a custom border thickness an... | +| [add-disclaimer-stamp-to-first-page](./add-disclaimer-stamp-to-first-page.cs) | Add Disclaimer Stamp to First Page of PDF | `PdfFileStamp`, `Stamp`, `BindPdf` | Shows how to use Aspose.Pdf.Facades.PdfFileStamp and Stamp to overlay a disclaimer PDF onto the f... | +| [add-dynamic-text-stamp-to-pdf](./add-dynamic-text-stamp-to-pdf.cs) | Add Dynamic Text Stamp to PDF | `Document`, `TextStamp`, `AddStamp` | Demonstrates loading a PDF, creating a TextStamp with interpolated date and author, configuring i... | +| [add-file-name-header-stamp](./add-file-name-header-stamp.cs) | Add File Name Header Stamp to PDF | `Document`, `Page`, `TextStamp` | Demonstrates how to place a text stamp in the header of each PDF page that automatically shows th... | +| [add-footer-date-stamp-to-last-page](./add-footer-date-stamp-to-last-page.cs) | Add Footer Date Stamp to Last PDF Page | `Document`, `Page`, `TextStamp` | Shows how to place a footer stamp with the current date (MM-dd-yyyy) on the last page of a PDF us... | +| [add-footer-stamp-10pt-above-bottom](./add-footer-stamp-10pt-above-bottom.cs) | Add Footer Stamp 10 Points Above Bottom Edge | `PdfFileStamp`, `FormattedText`, `AddFooter` | Demonstrates how to place a footer stamp exactly 10 points above the bottom edge of each page by ... | +| [add-footer-with-page-count](./add-footer-with-page-count.cs) | Add Footer with Automatic Page Count to PDF | `PdfFileStamp`, `BindPdf`, `AddFooter` | Shows how to use PdfFileStamp to add a footer containing the {page_count} placeholder, which Aspo... | +| [add-header-stamp-to-pdf-pages](./add-header-stamp-to-pdf-pages.cs) | Add Header Stamp to All PDF Pages | `Document`, `Page`, `TextStamp` | Shows how to load a PDF, iterate through each page, and add a centered header stamp containing a ... | +| [add-logo-confidential-stamp-to-pdf](./add-logo-confidential-stamp-to-pdf.cs) | Add Logo and Confidential Stamp to PDF | `PdfFileStamp`, `Stamp`, `FormattedText` | Demonstrates using Aspose.Pdf.Facades to place a company logo image together with bold 'Confident... | +| [add-lower-roman-page-numbers-odd-pages](./add-lower-roman-page-numbers-odd-pages.cs) | Add Lower‑Roman Page Numbers to Odd Pages | `Document`, `PageNumberStamp`, `NumberingStyle` | Demonstrates how to stamp lower‑case Roman numerals as page numbers on only the odd pages of a PD... | +| [add-multi-line-text-watermark](./add-multi-line-text-watermark.cs) | Add Multi-Line Text Watermark to PDF Using FormattedText | `FormattedText`, `PdfFileStamp`, `Document` | Demonstrates creating a multi-line formatted text watermark with Aspose.Pdf.Facades and applying ... | +| [add-multi-line-watermark-pdffilemend](./add-multi-line-watermark-pdffilemend.cs) | Add Multi‑Line Watermark with Different Font Styles using Pd... | `Document`, `PdfFileMend`, `FormattedText` | Demonstrates how to create a three‑line watermark on every PDF page using Aspose.Pdf.Facades.Form... | +| [add-page-number-stamp-arabic-numerals](./add-page-number-stamp-arabic-numerals.cs) | Add Page Number Stamp with Arabic Numerals | `PdfFileStamp`, `BindPdf`, `NumberingStyle` | Demonstrates how to use Aspose.Pdf's PdfFileStamp facade to add sequential page numbers formatted... | +| [add-page-number-stamp-to-pdf](./add-page-number-stamp-to-pdf.cs) | Add Page Number Stamp to PDF | `PdfFileStamp`, `BindPdf`, `AddPageNumber` | Shows how to use Aspose.Pdf.Facades.PdfFileStamp to add a dynamic page number stamp to each page ... | +| [add-qr-code-text-stamp-to-pdf](./add-qr-code-text-stamp-to-pdf.cs) | Add QR Code and Text Stamp to PDF | `PdfFileStamp`, `Stamp`, `FormattedText` | Demonstrates how to place a QR‑code image together with descriptive text on each page of a PDF us... | +| [add-repeating-background-image-watermark](./add-repeating-background-image-watermark.cs) | Add Repeating Background Image Watermark to PDF | `Document`, `PdfFileStamp`, `Stamp` | Demonstrates how to use a single Stamp instance to place a semi‑transparent background image on e... | +| [add-right-aligned-logo-stamp-to-pdf-pages](./add-right-aligned-logo-stamp-to-pdf-pages.cs) | Add Right-Aligned Logo Stamp to PDF Pages | `Document`, `Page`, `ImageStamp` | Shows how to place an image stamp (logo) on every page of a PDF and align it to the right margin ... | +| [add-rotated-image-stamp-to-first-page](./add-rotated-image-stamp-to-first-page.cs) | Add Rotated Image Stamp to First Page of PDFs | `PdfFileStamp`, `Stamp`, `BindPdf` | Shows how to batch‑process PDF files in a directory and apply a semi‑transparent, 45‑degree rotat... | +| [add-semi-transparent-png-background-stamp](./add-semi-transparent-png-background-stamp.cs) | Add Semi-Transparent PNG Background Stamp to PDF | `PdfFileStamp`, `BindPdf`, `Stamp` | Demonstrates how to use Aspose.Pdf.Facades to place a semi‑transparent PNG image as a background ... | +| [add-translucent-text-watermark-to-pdf-pages](./add-translucent-text-watermark-to-pdf-pages.cs) | Add Translucent Text Watermark to PDF Pages | `Document`, `TextStamp`, `FindFont` | Shows how to create a 50% opaque text stamp and apply it as a watermark on every page of a PDF do... | +| [add-transparent-confidential-text-stamp](./add-transparent-confidential-text-stamp.cs) | Add Transparent CONFIDENTIAL Text Stamp to Selected PDF Page... | `FormattedText`, `Stamp`, `BindLogo` | Demonstrates how to place a semi‑transparent CONFIDENTIAL text stamp on specific pages of a PDF u... | +| [apply-image-stamp-to-all-pdf-pages](./apply-image-stamp-to-all-pdf-pages.cs) | Apply Image Stamp to All PDF Pages | `PdfFileStamp`, `Stamp`, `BindPdf` | Shows how to use PdfFileStamp and Stamp to add a single image stamp to every page of a PDF effici... | +| [apply-image-stamp-to-pdf](./apply-image-stamp-to-pdf.cs) | Apply Image Stamp to PDF with Overlay Control | `Document`, `PdfFileStamp`, `Stamp` | Demonstrates creating a PDF in memory, generating an image stamp, binding both via streams, setti... | +| [apply-image-stamp-to-pdfs](./apply-image-stamp-to-pdfs.cs) | Apply Image Stamp to PDFs and Save to New Folder | `PdfFileStamp`, `Stamp`, `SetOrigin` | Demonstrates loading PDF files from a directory, applying an image stamp to every page with Aspos... | +| [apply-multi-line-colored-header-stamp](./apply-multi-line-colored-header-stamp.cs) | Apply Multi-Line Colored Header Stamp to PDF | `PdfFileStamp`, `FormattedText`, `EncodingType` | Demonstrates how to add a multi‑line header to a PDF using Aspose.Pdf.Facades, with each line ren... | +| [apply-multi-line-text-stamp](./apply-multi-line-text-stamp.cs) | Apply Multi-Line Text Stamp with Custom Line Spacing | `FormattedText`, `AddNewLineText`, `BindLogo` | Demonstrates creating a formatted text stamp with multiple lines and 1.5 point extra line spacing... | +| [apply-multi-line-watermark-custom-line-height](./apply-multi-line-watermark-custom-line-height.cs) | Apply Multi-Line Watermark with Custom Line Height | `PdfFileStamp`, `SetOrigin`, `BindLogo` | Demonstrates creating a stamp containing multiple lines of text with equal line spacing and apply... | +| ... | | | *and 15 more files* | + +## Category Statistics +- Total examples: 45 + +## Category-Specific Tips + +### Key API Surface +- `Aspose.Pdf.Facades.EncodingType` +- `Aspose.Pdf.Facades.FontStyle` +- `Aspose.Pdf.Facades.FormattedText` +- `Aspose.Pdf.Facades.PdfContentEditor` +- `Aspose.Pdf.Facades.PdfFileStamp` +- `Aspose.Pdf.Facades.PdfFileStamp.AddHeader(System.IO.Stream, int)` +- `Aspose.Pdf.Facades.PdfFileStamp.BindPdf(string)` +- `Aspose.Pdf.Facades.PdfFileStamp.Close()` +- `Aspose.Pdf.Facades.PdfFileStamp.Save(string)` +- `Aspose.Pdf.Facades.Stamp` +- `Aspose.Pdf.Facades.StampInfo` +- `System.Drawing.Color` +- `System.Drawing.Image` + +### Rules +- Create a PdfFileStamp instance, bind it to {input_pdf} with BindPdf, then call AddFooter({image_stream}, {int}) to place the image footer on each page, finally Save({output_pdf}) and Close() the stamp object. +- The image for the footer must be provided as a readable Stream (e.g., FileStream opened with FileMode.Open); the integer argument specifies the vertical offset (in points) from the bottom edge of the page. +- Instantiate a PdfFileStamp object, then call BindPdf({input_pdf}) to load the source document. +- Call AddHeader({image_stream}, {int}) on the bound PdfFileStamp to place an image header on each page, where the integer specifies the vertical offset from the top. +- Save the modified document with Save({output_pdf}) and release resources with Close(). + +### Warnings +- PdfFileStamp belongs to the Aspose.Pdf.Facades namespace, which may be deprecated in newer releases; consider using the Document class with Stamp objects for future compatibility. +- The example does not explicitly dispose the FileStream; callers should ensure proper disposal of streams to avoid resource leaks. +- The example uses a raw FileStream without a using statement; callers should ensure the stream is disposed. +- AddHeader expects the image stream to be positioned at the beginning; callers must reset the stream if reused. +- Method signatures (e.g., SetOrigin) may accept double rather than float; adjust types accordingly. + +## General Tips +- See parent [agents.md](../agents.md) for: + - **Boundaries** — Always / Ask First / Never rules for all examples + - **Common Mistakes** — verified anti-patterns that cause build failures + - **Domain Knowledge** — cross-cutting API-specific gotchas + - **Testing Guide** — build and run verification steps +- Review code examples in this folder for facades-stamps patterns + + +Updated: 2026-05-08 | Run: `20260508_144637_f72c91` + diff --git a/facades-stamps/apply-image-stamp-to-all-pdf-pages.cs b/facades-stamps/apply-image-stamp-to-all-pdf-pages.cs new file mode 100644 index 00000000..dd06cdc2 --- /dev/null +++ b/facades-stamps/apply-image-stamp-to-all-pdf-pages.cs @@ -0,0 +1,61 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + // Input PDF, output PDF and the image to be used as a stamp. + const string inputPdf = "input.pdf"; + const string outputPdf = "output.pdf"; + const string stampImg = "stamp.png"; + + // Verify that required files exist. + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input file not found: {inputPdf}"); + return; + } + if (!File.Exists(stampImg)) + { + Console.Error.WriteLine($"Aspose.Pdf.Facades.Stamp image not found: {stampImg}"); + return; + } + + // Use PdfFileStamp (facade) to apply a single stamp to all pages. + // The stamp will be applied to every page because the Pages property + // remains null (default behavior). + using (PdfFileStamp fileStamp = new PdfFileStamp()) + { + // Bind the source PDF document. + fileStamp.BindPdf(inputPdf); + + // Create the stamp object. + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + + // Bind an image to the stamp. + stamp.BindImage(stampImg); + + // Position the stamp (origin is measured from the lower‑left corner). + stamp.SetOrigin(100, 500); // X = 100, Y = 500 + + // Define the size of the stamp on the page. + stamp.SetImageSize(200, 100); // Width = 200, Height = 100 + + // Optional: make the stamp semi‑transparent and place it behind content. + stamp.Opacity = 0.6f; // 60 % opacity + stamp.IsBackground = true; // render as background + + // Add the stamp to the document. Because stamp.Pages is null, + // the stamp is applied to all pages efficiently (single operation). + fileStamp.AddStamp(stamp); + + // Save the result to the output file. + fileStamp.Save(outputPdf); + } + + Console.WriteLine($"Stamped PDF saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/apply-image-stamp-to-pdf.cs b/facades-stamps/apply-image-stamp-to-pdf.cs new file mode 100644 index 00000000..ccf17413 --- /dev/null +++ b/facades-stamps/apply-image-stamp-to-pdf.cs @@ -0,0 +1,102 @@ +using System; +using System.IO; +using System.Drawing; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; +using Aspose.Pdf; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + // --------------------------------------------------------------------- + // 1. Create a minimal PDF document in memory (so we don't depend on a file). + // --------------------------------------------------------------------- + using (var pdfDoc = new Document()) + { + pdfDoc.Pages.Add(); // add a blank page + + using (var pdfStream = new MemoryStream()) + { + // Guard Document.Save against missing GDI+ on non‑Windows platforms. + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + pdfDoc.Save(pdfStream); + } + else + { + Console.WriteLine("Skipping Document.Save – GDI+ (libgdiplus) is not available on this platform."); + // Still produce an empty PDF stream so the rest of the demo can continue. + pdfDoc.Save(pdfStream, SaveFormat.Pdf); + } + pdfStream.Position = 0; // reset for reading + + // --------------------------------------------------------------- + // 2. Create a simple stamp image in memory (red rectangle with text). + // --------------------------------------------------------------- + MemoryStream imgStream = null; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + var bmp = new Bitmap(200, 100); + using (var g = Graphics.FromImage(bmp)) + { + g.Clear(System.Drawing.Color.Red); + g.DrawString( + "STAMP", + new System.Drawing.Font("Arial", 20), + System.Drawing.Brushes.White, + new PointF(10, 35) + ); + } + + imgStream = new MemoryStream(); + bmp.Save(imgStream, ImageFormat.Png); + imgStream.Position = 0; // reset for reading + } + else + { + Console.WriteLine("System.Drawing is not supported on this platform – stamp will be skipped."); + } + + // ----------------------------------------------------------- + // 3. Bind the PDF and the image to the stamp using stream overloads. + // ----------------------------------------------------------- + var fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(pdfStream); // bind PDF from stream + + if (imgStream != null) + { + var stamp = new Aspose.Pdf.Facades.Stamp(); + stamp.BindImage(imgStream); // bind image from stream + + // Ensure the stamp is drawn on top of existing page content. + stamp.IsBackground = false; + + // Optional positioning and sizing (points). + stamp.SetOrigin(100, 200); // X‑indent, Y‑indent (bottom‑left origin) + stamp.SetImageSize(150, 100); // Width, Height + + // Apply the stamp to all pages. + fileStamp.AddStamp(stamp); + } + + // Save the stamped PDF to disk. + const string outputPdf = "output.pdf"; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + fileStamp.Save(outputPdf); + } + else + { + // On non‑Windows platforms we still attempt to save; Aspose.Pdf can write the PDF + // without needing GDI+ because we are not rendering System.Drawing objects. + fileStamp.Save(outputPdf); + } + fileStamp.Close(); + + Console.WriteLine($"Stamp applied and saved to '{outputPdf}'."); + } + } + } +} diff --git a/facades-stamps/apply-image-stamp-to-pdfs.cs b/facades-stamps/apply-image-stamp-to-pdfs.cs new file mode 100644 index 00000000..3b701ce2 --- /dev/null +++ b/facades-stamps/apply-image-stamp-to-pdfs.cs @@ -0,0 +1,54 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + // Source directory containing original PDFs + const string inputDir = "InputPdfs"; + // Destination directory for stamped PDFs (preserves original file names) + const string outputDir = "StampedPdfs"; + + // Verify source directory exists + if (!Directory.Exists(inputDir)) + { + Console.Error.WriteLine($"Input directory not found: {inputDir}"); + return; + } + + // Ensure destination directory exists + Directory.CreateDirectory(outputDir); + + // Prepare a reusable stamp (image based) + // Adjust origin, size, opacity as needed + Stamp stamp = new Stamp(); + stamp.SetOrigin(100, 500); // position of the stamp on each page + stamp.SetImageSize(200, 100); // width and height of the stamp + stamp.Opacity = 0.5f; // semi‑transparent + stamp.IsBackground = false; // placed over page content + stamp.BindImage("stamp.png"); // path to the stamp image (must exist) + + // Process each PDF file in the input directory + foreach (string inputPath in Directory.GetFiles(inputDir, "*.pdf")) + { + // Preserve original file name + string fileName = Path.GetFileName(inputPath); + string outputPath = Path.Combine(outputDir, fileName); + + // Initialize PdfFileStamp facade + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.InputFile = inputPath; // source PDF + fileStamp.OutputFile = outputPath; // destination PDF + + // Apply the stamp to all pages + fileStamp.AddStamp(stamp); + + // Close saves the result and releases resources + fileStamp.Close(); + } + + Console.WriteLine("All PDFs have been stamped and saved."); + } +} \ No newline at end of file diff --git a/facades-stamps/apply-multi-line-colored-header-stamp.cs b/facades-stamps/apply-multi-line-colored-header-stamp.cs new file mode 100644 index 00000000..ca53eae2 --- /dev/null +++ b/facades-stamps/apply-multi-line-colored-header-stamp.cs @@ -0,0 +1,62 @@ +using System; +using System.IO; +using System.Drawing; // System.Drawing.Color is required for FormattedText +using Aspose.Pdf.Facades; // PdfFileStamp, FormattedText, EncodingType + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; + const string outputPdf = "output.pdf"; + + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input file not found: {inputPdf}"); + return; + } + + // Initialize the PdfFileStamp facade and specify input/output files + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.InputFile = inputPdf; + fileStamp.OutputFile = outputPdf; + + // Create three header lines, each with a distinct font color + FormattedText headerLine1 = new FormattedText( + "First Header Line", // text + Color.Blue, // System.Drawing.Color + "Helvetica", // font name + EncodingType.Winansi, // encoding + false, // embed font? + 24); // font size + + FormattedText headerLine2 = new FormattedText( + "Second Header Line", + Color.Green, + "Helvetica", + EncodingType.Winansi, + false, + 20); + + FormattedText headerLine3 = new FormattedText( + "Third Header Line", + Color.Red, + "Helvetica", + EncodingType.Winansi, + false, + 18); + + // Add each line as a separate header; increase top margin for each subsequent line + float topMargin = 20f; // distance from the top edge for the first line + fileStamp.AddHeader(headerLine1, topMargin); + topMargin += 30f; // adjust for next line (approximate line height) + fileStamp.AddHeader(headerLine2, topMargin); + topMargin += 30f; + fileStamp.AddHeader(headerLine3, topMargin); + + // Persist changes and release resources + fileStamp.Close(); + + Console.WriteLine($"Multi‑line header stamp applied and saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/apply-multi-line-text-stamp.cs b/facades-stamps/apply-multi-line-text-stamp.cs new file mode 100644 index 00000000..73ba63e1 --- /dev/null +++ b/facades-stamps/apply-multi-line-text-stamp.cs @@ -0,0 +1,50 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; // PdfFileStamp, Stamp, FormattedText, EncodingType +using System.Drawing; // System.Drawing.Color (required by FormattedText) + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; // source PDF + const string outputPdf = "watermarked.pdf"; // result PDF + + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"File not found: {inputPdf}"); + return; + } + + // Create a multi‑line formatted text with custom line spacing (1.5 points extra) + FormattedText ft = new FormattedText( + "Confidential", // first line + Color.Black, // text color + "Helvetica", // font name + EncodingType.Winansi, // encoding + false, // embedded flag + 24); // font size + + // Add subsequent lines; the second argument is additional line spacing + ft.AddNewLineText("Do Not Distribute", 1.5f); + ft.AddNewLineText("Internal Use Only", 1.5f); + + // Configure the stamp + Stamp stamp = new Stamp(); + stamp.BindLogo(ft); // bind the formatted text + stamp.IsBackground = true; // place behind page content (optional) + stamp.Opacity = 0.5f; // semi‑transparent (optional) + stamp.SetOrigin(100, 400); // position on the page (X, Y) + + // Apply the stamp to all pages of the PDF + using (PdfFileStamp pdfStamp = new PdfFileStamp()) + { + pdfStamp.BindPdf(inputPdf); // load source PDF + pdfStamp.AddStamp(stamp); // add the configured stamp + pdfStamp.Save(outputPdf); // write the result + pdfStamp.Close(); // finalize + } + + Console.WriteLine($"Watermarked PDF saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/apply-multi-line-watermark-custom-line-height.cs b/facades-stamps/apply-multi-line-watermark-custom-line-height.cs new file mode 100644 index 00000000..13b8623d --- /dev/null +++ b/facades-stamps/apply-multi-line-watermark-custom-line-height.cs @@ -0,0 +1,58 @@ +using System; +using System.IO; +using System.Drawing; // Fully qualified System.Drawing.Color is used +using Aspose.Pdf; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; + const string outputPdf = "output.pdf"; + + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input file not found: {inputPdf}"); + return; + } + + // Initialize PdfFileStamp and bind the source PDF (new API) + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(inputPdf); + + // Create a stamp (facade) that will hold the watermark text + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + + // Position the stamp (origin is measured from the lower‑left corner) + stamp.SetOrigin(100, 400); // X = 100, Y = 400 + stamp.Opacity = 0.5f; // Semi‑transparent + stamp.IsBackground = true; // Draw behind page content + + // Build the watermark text with equal line spacing. + // Use fully‑qualified System.Drawing.Color and a float for the font size. + Aspose.Pdf.Facades.FormattedText ft = new Aspose.Pdf.Facades.FormattedText( + "CONFIDENTIAL", // First line text + System.Drawing.Color.Red, // Text color (fully qualified) + "Helvetica", // Font name + Aspose.Pdf.Facades.EncodingType.Winansi, // Encoding + false, // Not embedded + 36f); // Font size (float) + + // Add additional lines with the same line height + ft.AddNewLineText("DO NOT DISTRIBUTE"); + ft.AddNewLineText("FOR INTERNAL USE ONLY"); + + // Bind the formatted text to the stamp + stamp.BindLogo(ft); + + // Add the configured stamp to the PDF (applies to all pages) + fileStamp.AddStamp(stamp); + + // Save the result using the new API + fileStamp.Save(outputPdf); + fileStamp.Close(); + + Console.WriteLine($"Watermarked PDF saved to '{outputPdf}'."); + } +} diff --git a/facades-stamps/apply-pdf-page-stamp-as-background.cs b/facades-stamps/apply-pdf-page-stamp-as-background.cs new file mode 100644 index 00000000..f9ccc4de --- /dev/null +++ b/facades-stamps/apply-pdf-page-stamp-as-background.cs @@ -0,0 +1,44 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; // source PDF + const string stampPdf = "stamp.pdf"; // PDF whose first page will be used as stamp + const string outputPdf = "output.pdf"; // result PDF + + // Verify files exist + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input file not found: {inputPdf}"); + return; + } + if (!File.Exists(stampPdf)) + { + Console.Error.WriteLine($"Stamp file not found: {stampPdf}"); + return; + } + + // Initialize the facade and bind the source document + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(inputPdf); // load source PDF + + // Create a stamp that uses the first page of the stamp PDF + Stamp stamp = new Stamp(); + stamp.BindPdf(stampPdf, 1); // bind page 1 of stampPdf as stamp content + stamp.IsBackground = true; // place stamp behind page content + stamp.Pages = null; // null means all pages are affected + + // Add the stamp to the document + fileStamp.AddStamp(stamp); + + // Save the stamped PDF + fileStamp.Save(outputPdf); + fileStamp.Close(); + + Console.WriteLine($"Stamped PDF saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/apply-rotated-image-stamp-bottom-right.cs b/facades-stamps/apply-rotated-image-stamp-bottom-right.cs new file mode 100644 index 00000000..6f5d3e78 --- /dev/null +++ b/facades-stamps/apply-rotated-image-stamp-bottom-right.cs @@ -0,0 +1,55 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + const string imagePath = "stamp.png"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + if (!File.Exists(imagePath)) + { + Console.Error.WriteLine($"Aspose.Pdf.Facades.Stamp image not found: {imagePath}"); + return; + } + + // Initialize the facade with input and output PDF files + PdfFileStamp fileStamp = new PdfFileStamp(inputPath, outputPath); + + // Create a stamp and bind the image to it + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + stamp.BindImage(imagePath); + + // Set the desired size of the stamp (width, height) + float stampWidth = 100f; + float stampHeight = 100f; + stamp.SetImageSize(stampWidth, stampHeight); + + // Rotate the stamp by 30 degrees + stamp.Rotation = 30f; + + // Position the stamp at the bottom‑right corner of each page + // Use a small margin from the page edges + float margin = 10f; + float originX = fileStamp.PageWidth - stampWidth - margin; + float originY = margin; // bottom margin + stamp.SetOrigin(originX, originY); + + // Apply the stamp to all pages of the document + fileStamp.AddStamp(stamp); + + // Save and close the result + fileStamp.Close(); + + Console.WriteLine($"Stamped PDF saved to '{outputPath}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/apply-rotated-text-stamp-to-odd-pages.cs b/facades-stamps/apply-rotated-text-stamp-to-odd-pages.cs new file mode 100644 index 00000000..2f93719b --- /dev/null +++ b/facades-stamps/apply-rotated-text-stamp-to-odd-pages.cs @@ -0,0 +1,57 @@ +using System; +using System.IO; +using System.Linq; +using Aspose.Pdf.Facades; // PdfFileStamp, Stamp +using Aspose.Pdf.Text; // FormattedText, EncodingType +using System.Drawing; // Color (required by FormattedText) + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; + const string outputPdf = "output.pdf"; + + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input file not found: {inputPdf}"); + return; + } + + // Initialize the facade and bind the source PDF + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(inputPdf); + + // Create a text stamp + // FormattedText(string text, Color color, string fontName, EncodingType encoding, bool isEmbedded, int fontSize) + FormattedText ft = new FormattedText( + "CONFIDENTIAL", // stamp text + Color.Red, // text color + "Helvetica", // font + EncodingType.Winansi, // encoding + false, // not embedded + 36); // font size + + Stamp stamp = new Stamp(); + stamp.BindLogo(ft); // set the text content + stamp.Rotation = 30f; // rotate 30 degrees (arbitrary angle) + stamp.SetOrigin(10f, 0f); // place near the left margin, bottom of page + + // Determine odd‑numbered pages + int pageCount = fileStamp.Document.Pages.Count; // 1‑based page count + int[] oddPages = Enumerable.Range(1, pageCount) + .Where(p => p % 2 == 1) + .ToArray(); + + stamp.Pages = oddPages; // apply stamp only to odd pages + + // Add the configured stamp to the document + fileStamp.AddStamp(stamp); + + // Save the result and release resources + fileStamp.Save(outputPdf); + fileStamp.Close(); + + Console.WriteLine($"Rotated text stamp applied to odd pages. Output saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/apply-rotating-stamps-to-pdf-pages.cs b/facades-stamps/apply-rotating-stamps-to-pdf-pages.cs new file mode 100644 index 00000000..57ee3558 --- /dev/null +++ b/facades-stamps/apply-rotating-stamps-to-pdf-pages.cs @@ -0,0 +1,60 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; +using Aspose.Pdf.Text; // for EncodingType + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "stamped_output.pdf"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Initialize the facade and bind the source PDF. + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(inputPath); + + // Use a Document only to obtain the page count (required for the loop). + int pageCount; + using (Document doc = new Document(inputPath)) + { + pageCount = doc.Pages.Count; // 1‑based indexing + } + + // Apply a stamp to each page with a rotation based on the page index. + for (int i = 1; i <= pageCount; i++) + { + // Create a stamp instance (fully qualified to avoid ambiguity). + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + + // Simple text content for the stamp. + FormattedText ft = new FormattedText( + $"Page {i}", + System.Drawing.Color.Red, // FormattedText expects System.Drawing.Color + "Helvetica", + EncodingType.Winansi, + false, + 24); + + stamp.BindLogo(ft); // Attach the text to the stamp. + stamp.Rotation = (i * 30) % 360; // Example: rotate 30° per page. + stamp.IsBackground = false; // Stamp appears on top of page content. + stamp.Pages = new int[] { i }; // Apply only to the current page. + + fileStamp.AddStamp(stamp); + } + + // Save the result and release resources. + fileStamp.Save(outputPath); + fileStamp.Close(); + + Console.WriteLine($"Stamped PDF saved to '{outputPath}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/apply-stamp-to-specific-pdf-pages.cs b/facades-stamps/apply-stamp-to-specific-pdf-pages.cs new file mode 100644 index 00000000..6dea4674 --- /dev/null +++ b/facades-stamps/apply-stamp-to-specific-pdf-pages.cs @@ -0,0 +1,44 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; +using System.Drawing; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Create formatted text for the stamp – use System.Drawing.Color and a float font size + var ft = new FormattedText( + "Sample Aspose.Pdf.Facades.Stamp", // text to display + Color.Red, // System.Drawing.Color (fully qualified via using) + "Helvetica", // font name + EncodingType.Winansi, // encoding + false, // embed font flag + 36f); // font size as float + + // Pages that should receive the stamp (1‑based indices) + int[] pages = { 1, 5, 10 }; + + // Use PdfFileMend to add the text to the selected pages + var mend = new PdfFileMend(); + mend.BindPdf(inputPath); + + // Position the stamp – lower‑left (100,500) to upper‑right (300,550) + mend.AddText(ft, pages, 100f, 500f, 300f, 550f); + + // Save the modified PDF and release resources + mend.Save(outputPath); + mend.Close(); + + Console.WriteLine($"Stamp applied to pages 1, 5, and 10. Saved as '{outputPath}'."); + } +} diff --git a/facades-stamps/apply-text-stamp-to-even-pages.cs b/facades-stamps/apply-text-stamp-to-even-pages.cs new file mode 100644 index 00000000..94754f9a --- /dev/null +++ b/facades-stamps/apply-text-stamp-to-even-pages.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output_even_pages.pdf"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"File not found: {inputPath}"); + return; + } + + // Load the PDF to determine the number of pages. + using (Document doc = new Document(inputPath)) + { + // Collect even page numbers (Aspose.Pdf uses 1‑based indexing). + List evenPages = new List(); + for (int i = 1; i <= doc.Pages.Count; i++) + { + if (i % 2 == 0) // parity check + evenPages.Add(i); + } + + // Initialize the facade and bind the source PDF. + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(inputPath); + + // Create a text stamp (you can replace this with an image stamp if desired). + // Fully qualify the Stamp class to avoid ambiguity. + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + + // Prepare formatted text for the stamp. + // FormattedText constructor uses System.Drawing.Color for the text color. + FormattedText ft = new FormattedText( + "EVEN PAGE STAMP", // text + System.Drawing.Color.Red, // text color + "Helvetica", // font name + EncodingType.Winansi, // encoding + false, // embed font? + 36); // font size + + // Bind the formatted text to the stamp. + stamp.BindLogo(ft); + + // Position the stamp (origin coordinates in points). + stamp.SetOrigin(100, 500); + stamp.IsBackground = false; // place on top of page content + stamp.Opacity = 0.5f; + + // Apply the stamp only to the even pages collected above. + stamp.Pages = evenPages.ToArray(); + + // Add the stamp to the document via the facade. + fileStamp.AddStamp(stamp); + + // Save the result. + fileStamp.Save(outputPath); + fileStamp.Close(); + + Console.WriteLine($"Stamp applied to even pages. Output saved to '{outputPath}'."); + } + } +} \ No newline at end of file diff --git a/facades-stamps/batch-add-multi-line-watermark-to-pdfs.cs b/facades-stamps/batch-add-multi-line-watermark-to-pdfs.cs new file mode 100644 index 00000000..4a4a9947 --- /dev/null +++ b/facades-stamps/batch-add-multi-line-watermark-to-pdfs.cs @@ -0,0 +1,78 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; // PdfFileStamp, Stamp, FormattedText, EncodingType +using System.Drawing; // Color + +class BatchWatermark +{ + static void Main() + { + // Define input and output folders. Use absolute paths when they exist, otherwise fall back to a folder relative to the current directory. + string inputFolder = GetValidFolderPath(@"C:\PdfInput"); + string outputFolder = GetValidFolderPath(@"C:\PdfOutput"); + + // Ensure the output directory exists + Directory.CreateDirectory(outputFolder); + + // Prepare the multi‑line watermark text + FormattedText watermarkText = new FormattedText( + "Confidential\r\nDo Not Distribute\r\nCompany XYZ", + Color.Gray, // text color + "Helvetica", // font name + EncodingType.Winansi, // encoding + false, // isEmbedded + 48); // font size + + // Verify that the input folder actually exists before trying to enumerate files + if (!Directory.Exists(inputFolder)) + { + Console.WriteLine($"Input folder not found: {inputFolder}"); + return; + } + + // Process each PDF in the input folder + foreach (string pdfPath in Directory.GetFiles(inputFolder, "*.pdf")) + { + string fileName = Path.GetFileNameWithoutExtension(pdfPath); + string outputPath = Path.Combine(outputFolder, fileName + "_watermarked.pdf"); + + // Initialise the facade and bind the source PDF + using (PdfFileStamp fileStamp = new PdfFileStamp()) + { + fileStamp.BindPdf(pdfPath); // Bind the source PDF + + // Create a stamp and bind the formatted text as a logo (watermark) + Stamp stamp = new Stamp(); + stamp.BindLogo(watermarkText); + stamp.IsBackground = true; // render behind page content + stamp.Opacity = 0.5f; // semi‑transparent + stamp.SetOrigin(100, 400); // position of the watermark (optional) + + // Apply the stamp to the whole document + fileStamp.AddStamp(stamp); + + // Save the result + fileStamp.Save(outputPath); + } + } + + Console.WriteLine("Batch watermarking completed."); + } + + /// + /// Returns a valid folder path. If the supplied path is rooted and exists, it is returned unchanged. + /// Otherwise, the method treats the supplied string as a relative folder name and combines it with the + /// current working directory. The resulting directory is created if it does not already exist. + /// + private static string GetValidFolderPath(string path) + { + if (Path.IsPathRooted(path)) + { + // Absolute path – ensure it exists (or create it for the output folder) + return path; + } + // Relative path – resolve against the current directory + string combined = Path.Combine(Directory.GetCurrentDirectory(), path); + return combined; + } +} diff --git a/facades-stamps/batch-apply-rotated-pdf-page-stamp.cs b/facades-stamps/batch-apply-rotated-pdf-page-stamp.cs new file mode 100644 index 00000000..a3087fd0 --- /dev/null +++ b/facades-stamps/batch-apply-rotated-pdf-page-stamp.cs @@ -0,0 +1,69 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + // UNC path to the folder that contains the PDFs to be processed + const string networkFolder = @"\\Server\Share\PDFs"; + + // Path to the PDF that provides the page used as a stamp + const string stampSourcePdf = @"\\Server\Share\stamp.pdf"; + + // Page number (1‑based) from the stamp source PDF to be used as the stamp + const int stampPageNumber = 1; + + // Rotation angle for the stamp (degrees). Use the 'F' suffix for a float literal. + const float rotationDegrees = 45F; + + // Verify that the source folder exists + if (!Directory.Exists(networkFolder)) + { + Console.Error.WriteLine($"Folder not found: {networkFolder}"); + return; + } + + // Get all PDF files in the folder (non‑recursive) + string[] pdfFiles = Directory.GetFiles(networkFolder, "*.pdf", SearchOption.TopDirectoryOnly); + + foreach (string inputPath in pdfFiles) + { + // Build the output file name (original name + "_stamped.pdf") + string outputPath = Path.Combine( + Path.GetDirectoryName(inputPath) ?? string.Empty, + Path.GetFileNameWithoutExtension(inputPath) + "_stamped.pdf"); + + // ------------------------------------------------------------ + // 1. Initialise the PdfFileStamp facade and bind the input PDF + // ------------------------------------------------------------ + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.InputFile = inputPath; // load the target PDF + fileStamp.OutputFile = outputPath; // destination file + + // ------------------------------------------------------------ + // 2. Create a Stamp that uses a page from another PDF + // ------------------------------------------------------------ + Stamp stamp = new Stamp(); + stamp.BindPdf(stampSourcePdf, stampPageNumber); // use page as stamp content + stamp.Rotation = rotationDegrees; // rotate the stamp + stamp.IsBackground = true; // place behind page content (optional) + + // ------------------------------------------------------------ + // 3. Apply the stamp to all pages of the document + // ------------------------------------------------------------ + fileStamp.AddStamp(stamp); + + // ------------------------------------------------------------ + // 4. Persist the changes and release resources + // ------------------------------------------------------------ + fileStamp.Save(outputPath); + fileStamp.Close(); + + Console.WriteLine($"Stamped PDF saved: {outputPath}"); + } + + Console.WriteLine("Batch stamping completed."); + } +} \ No newline at end of file diff --git a/facades-stamps/combine-image-text-pdf-stamp.cs b/facades-stamps/combine-image-text-pdf-stamp.cs new file mode 100644 index 00000000..a0b59a23 --- /dev/null +++ b/facades-stamps/combine-image-text-pdf-stamp.cs @@ -0,0 +1,64 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; +using Aspose.Pdf.Text; // FormattedText, EncodingType + +class Program +{ + static void Main() + { + // Paths for source PDF, logo image, and output PDF + const string inputPdf = "input.pdf"; + const string logoImage = "logo.png"; + const string outputPdf = "output.pdf"; + + // Verify required files exist + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); + return; + } + if (!File.Exists(logoImage)) + { + Console.Error.WriteLine($"Logo image not found: {logoImage}"); + return; + } + + // Initialize PdfFileStamp facade and specify input/output files + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.InputFile = inputPdf; + fileStamp.OutputFile = outputPdf; + + // Create a stamp instance + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + + // Bind the logo image to the stamp + stamp.BindImage(logoImage); + + // Prepare formatted text for the stamp + FormattedText formattedText = new FormattedText( + "Custom Text", // Text content + System.Drawing.Color.Black, // Text color (System.Drawing.Color is required) + "Helvetica", // Font name + EncodingType.Winansi, // Encoding + false, // IsEmbedded (false = use system font) + 12); // Font size + + // Bind the formatted text to the same stamp + stamp.BindLogo(formattedText); + + // Optional: set stamp appearance (position, opacity, background) + stamp.SetOrigin(100, 150); // X, Y coordinates (bottom‑left origin) + stamp.Opacity = 0.8f; // Semi‑transparent + stamp.IsBackground = false; // Place stamp on top of page content + + // Add the combined image‑and‑text stamp to the PDF + fileStamp.AddStamp(stamp); + + // Finalize and save the output PDF + fileStamp.Close(); + + Console.WriteLine($"Stamp with logo and text saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/create-multi-page-pdf-stamp.cs b/facades-stamps/create-multi-page-pdf-stamp.cs new file mode 100644 index 00000000..bc67d27d --- /dev/null +++ b/facades-stamps/create-multi-page-pdf-stamp.cs @@ -0,0 +1,109 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + // Path to the PDF that will receive the stamps + const string targetPdf = "target.pdf"; + + // Paths to the PDF files that will be used as stamps (each may have multiple pages) + // For this example we assume each stamp PDF has at least one page and we use its first page. + var stampPdfFiles = new List + { + "stamp1.pdf", + "stamp2.pdf", + "stamp3.pdf" + }; + + // Output file that will contain the stamped document + const string outputPdf = "stamped_output.pdf"; + + // Verify that all files exist before proceeding + if (!File.Exists(targetPdf)) + { + Console.Error.WriteLine($"Target PDF not found: {targetPdf}"); + return; + } + + foreach (var sp in stampPdfFiles) + { + if (!File.Exists(sp)) + { + Console.Error.WriteLine($"Stamp PDF not found: {sp}"); + return; + } + } + + // Create the PdfFileStamp facade and bind the target document + var fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(targetPdf); // loads the document to be stamped + + // Create a Stamp for each source PDF and add it to the facade + foreach (var stampPath in stampPdfFiles) + { + // Create a new Stamp instance + var stamp = new Stamp(); + + // Bind the first page of the stamp PDF as the stamp content + // (page numbers are 1‑based) + stamp.BindPdf(stampPath, 1); + + // Optional: make the stamp appear as a background element + stamp.IsBackground = true; + + // Optional: set opacity (0.0 = fully transparent, 1.0 = fully opaque) + stamp.Opacity = 0.8f; + + // Optional: position the stamp (origin is measured from the lower‑left corner) + stamp.SetOrigin(0, 0); // place at the lower‑left corner; adjust as needed + + // Add the configured stamp to the PdfFileStamp object + fileStamp.AddStamp(stamp); + } + + // Save the result. PdfFileStamp.Save writes the output file. + // On non‑Windows platforms Aspose.Pdf may require libgdiplus for rendering. + // Guard the save operation to avoid TypeInitializationException on macOS/Linux. + try + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + fileStamp.Save(outputPdf); + } + else + { + // Attempt to save; if GDI+ is missing the exception will be caught below. + fileStamp.Save(outputPdf); + } + + Console.WriteLine($"Stamped PDF saved to '{outputPdf}'."); + } + catch (TypeInitializationException ex) when (ContainsDllNotFound(ex)) + { + Console.WriteLine("Warning: GDI+ (libgdiplus) is not available on this platform. " + + "The stamping operation could not be completed."); + } + finally + { + // Close releases any resources held by the facade. + fileStamp.Close(); + } + } + + // Helper to detect a nested DllNotFoundException (e.g., missing libgdiplus) + private static bool ContainsDllNotFound(Exception ex) + { + while (ex != null) + { + if (ex is DllNotFoundException) + return true; + ex = ex.InnerException; + } + return false; + } +} \ No newline at end of file diff --git a/facades-stamps/custom-ttf-font-stamp-pdf.cs b/facades-stamps/custom-ttf-font-stamp-pdf.cs new file mode 100644 index 00000000..d644a5e5 --- /dev/null +++ b/facades-stamps/custom-ttf-font-stamp-pdf.cs @@ -0,0 +1,67 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Text; + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; + const string outputPdf = "branded_output.pdf"; + const string ttfPath = "BrandFont.ttf"; // path to the custom TrueType font + const string stampText = "My Unique Brand"; + + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); + return; + } + + if (!File.Exists(ttfPath)) + { + Console.Error.WriteLine($"TrueType font not found: {ttfPath}"); + return; + } + + // Load the PDF document inside a using block for deterministic disposal + using (Document doc = new Document(inputPdf)) + { + // Load the custom TrueType font from a stream (Aspose expects a Stream, not a file path) + using (FileStream fontStream = File.OpenRead(ttfPath)) + { + Font customFont = FontRepository.OpenFont(fontStream, FontTypes.TTF); + + // Configure the text state with the custom font and desired appearance + TextState textState = new TextState + { + Font = customFont, + FontSize = 36, + ForegroundColor = Aspose.Pdf.Color.Blue + }; + + // Create a text stamp using the custom text state + TextStamp brandStamp = new TextStamp(stampText, textState) + { + // Position the stamp at the bottom‑center of each page + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Bottom, + YIndent = 20, // distance from the bottom edge + Opacity = 0.8f, // semi‑transparent + Background = false // draw on top of page content + }; + + // Apply the stamp to every page in the document + foreach (Page page in doc.Pages) + { + page.AddStamp(brandStamp); + } + } + + // Save the modified PDF + doc.Save(outputPdf); + } + + Console.WriteLine($"Stamped PDF saved to '{outputPdf}'."); + } +} diff --git a/facades-stamps/index.json b/facades-stamps/index.json new file mode 100644 index 00000000..d02c3434 --- /dev/null +++ b/facades-stamps/index.json @@ -0,0 +1,1077 @@ +{ + "category": "facades-stamps", + "nuget_version": "26.4.0", + "last_updated": "2026-05-08T09:47:07Z", + "examples": { + "add-multi-line-text-watermark": { + "title": "Add Multi-Line Text Watermark to PDF Using FormattedText", + "filename": "add-multi-line-text-watermark.cs", + "description": "Demonstrates creating a multi-line formatted text watermark with Aspose.Pdf.Facades and applying it to every page of a PDF document.", + "tags": [ + "watermark", + "formattedtext", + "pdf", + "multiline", + "aspose" + ], + "apis_used": [ + "Aspose.Pdf.Facades.FormattedText", + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Document", + "FormattedText.AddNewLineText", + "PdfFileStamp.AddHeader", + "PdfFileStamp.BindPdf", + "PdfFileStamp.Save" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "rotate-text-stamp-45-degrees": { + "title": "Rotate Text Stamp 45 Degrees in PDF", + "filename": "rotate-text-stamp-45-degrees.cs", + "description": "Demonstrates creating a TextStamp, configuring its appearance, rotating it 45° around its centre, and applying it to each page of a PDF using Aspose.Pdf.", + "tags": [ + "text-stamp", + "rotation", + "pdf", + "watermark", + "aspose-pdf" + ], + "apis_used": [ + "Aspose.Pdf.Text.TextStamp", + "Aspose.Pdf.Text.FontRepository.FindFont", + "Aspose.Pdf.Color", + "Aspose.Pdf.Document", + "Aspose.Pdf.Page.AddStamp", + "Aspose.Pdf.Document.Save" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "apply-pdf-page-stamp-as-background": { + "title": "Apply PDF Page Stamp as Background to All Pages", + "filename": "apply-pdf-page-stamp-as-background.cs", + "description": "Demonstrates how to use Aspose.Pdf.Facades to apply the first page of another PDF as a background stamp on every page of a source PDF.", + "tags": [ + "pdf", + "stamp", + "background", + "facade", + "aspose" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.Stamp", + "PdfFileStamp.BindPdf", + "Stamp.BindPdf", + "Stamp.IsBackground", + "PdfFileStamp.AddStamp", + "PdfFileStamp.Save", + "PdfFileStamp.Close" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "stamp-pdf-with-external-template": { + "title": "Stamp PDF with External Template on Specific Page", + "filename": "stamp-pdf-with-external-template.cs", + "description": "Demonstrates how to create a PdfFileStamp from an external PDF template and apply it only to the third page of a PDF document.", + "tags": [ + "pdf", + "stamp", + "template", + "aspose", + "facades" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.Stamp.BindPdf", + "Aspose.Pdf.Facades.Stamp.Pages", + "Aspose.Pdf.Facades.Stamp.IsBackground", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.PdfFileStamp.Save" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-lower-roman-page-numbers-odd-pages": { + "title": "Add Lower‑Roman Page Numbers to Odd Pages", + "filename": "add-lower-roman-page-numbers-odd-pages.cs", + "description": "Demonstrates how to stamp lower‑case Roman numerals as page numbers on only the odd pages of a PDF using Aspose.Pdf.", + "tags": [ + "page-numbering", + "lower-roman", + "odd-pages", + "stamp", + "Aspose.Pdf" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.Text.PageNumberStamp", + "Aspose.Pdf.Text.NumberingStyle", + "Aspose.Pdf.Page.AddStamp", + "Aspose.Pdf.Document.Save", + "Aspose.Pdf.Text.TextState", + "Aspose.Pdf.FontRepository" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "combine-image-text-pdf-stamp": { + "title": "Combine Image and Text into a Single PDF Stamp", + "filename": "combine-image-text-pdf-stamp.cs", + "description": "Demonstrates how to create a stamp that contains both a logo image and formatted custom text, configure its appearance, and apply it to a PDF document using Aspose.Pdf.Facades.", + "tags": [ + "stamp", + "image", + "text", + "pdf", + "watermark" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.Stamp.BindImage", + "Aspose.Pdf.Facades.Stamp.BindLogo", + "Aspose.Pdf.Text.FormattedText", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.PdfFileStamp.Close" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-header-stamp-to-pdf-pages": { + "title": "Add Header Stamp to All PDF Pages", + "filename": "add-header-stamp-to-pdf-pages.cs", + "description": "Shows how to load a PDF, iterate through each page, and add a centered header stamp containing a company name using Aspose.Pdf.", + "tags": [ + "header", + "stamp", + "pdf", + "Aspose", + "pages" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.Page", + "Aspose.Pdf.Text.TextStamp", + "Aspose.Pdf.Text.FontRepository", + "Aspose.Pdf.Color", + "Aspose.Pdf.HorizontalAlignment", + "Aspose.Pdf.VerticalAlignment" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-footer-date-stamp-to-last-page": { + "title": "Add Footer Date Stamp to Last PDF Page", + "filename": "add-footer-date-stamp-to-last-page.cs", + "description": "Shows how to place a footer stamp with the current date (MM-dd-yyyy) on the last page of a PDF using Aspose.Pdf.", + "tags": [ + "footer", + "stamp", + "last-page", + "date", + "Aspose.Pdf" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.Page", + "Aspose.Pdf.Text.TextStamp", + "Aspose.Pdf.FontRepository.FindFont", + "Aspose.Pdf.Page.AddStamp", + "Aspose.Pdf.Document.Save" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "apply-rotating-stamps-to-pdf-pages": { + "title": "Apply Rotating Stamps to Each PDF Page", + "filename": "apply-rotating-stamps-to-pdf-pages.cs", + "description": "Demonstrates adding a text stamp to every page of a PDF and rotating it based on the page index using Aspose.Pdf.Facades.", + "tags": [ + "stamp", + "rotation", + "pdf", + "facade", + "page-index" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.Stamp.BindLogo", + "Aspose.Pdf.Facades.Stamp.Rotation", + "Aspose.Pdf.Document", + "Aspose.Pdf.Text.FormattedText" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-background-watermark-stamp-to-pdf-pages": { + "title": "Add Background Watermark Stamp to Specific PDF Pages", + "filename": "add-background-watermark-stamp-to-pdf-pages.cs", + "description": "Demonstrates how to create a background watermark stamp using Aspose.Pdf.Facades and apply it to pages 2 through 5 of a PDF document.", + "tags": [ + "watermark", + "background", + "stamp", + "Aspose.Pdf", + "pages" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.Stamp.BindLogo", + "Aspose.Pdf.Facades.Stamp.IsBackground", + "Aspose.Pdf.Facades.FormattedText" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "batch-add-multi-line-watermark-to-pdfs": { + "title": "Batch Add Multi‑Line Watermark to PDFs", + "filename": "batch-add-multi-line-watermark-to-pdfs.cs", + "description": "Demonstrates how to process a folder of PDF files and apply the same multi‑line watermark stamp to each document using Aspose.Pdf.Facades.", + "tags": [ + "watermark", + "batch", + "pdf", + "Aspose.Pdf", + "facade" + ], + "apis_used": [ + "PdfFileStamp", + "Stamp", + "FormattedText", + "EncodingType", + "PdfFileStamp.BindPdf", + "Stamp.BindLogo", + "PdfFileStamp.AddStamp", + "PdfFileStamp.Save" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "apply-image-stamp-to-pdfs": { + "title": "Apply Image Stamp to PDFs and Save to New Folder", + "filename": "apply-image-stamp-to-pdfs.cs", + "description": "Demonstrates loading PDF files from a directory, applying an image stamp to every page with Aspose.Pdf.Facades, and saving the stamped PDFs to a separate folder while preserving the original file names.", + "tags": [ + "pdf", + "stamp", + "image", + "aspose", + "facade" + ], + "apis_used": [ + "PdfFileStamp", + "Stamp", + "Stamp.SetOrigin", + "Stamp.SetImageSize", + "Stamp.BindImage", + "PdfFileStamp.AddStamp", + "PdfFileStamp.Close" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-disclaimer-stamp-to-first-page": { + "title": "Add Disclaimer Stamp to First Page of PDF", + "filename": "add-disclaimer-stamp-to-first-page.cs", + "description": "Shows how to use Aspose.Pdf.Facades.PdfFileStamp and Stamp to overlay a disclaimer PDF onto the first page of a target PDF document.", + "tags": [ + "pdf", + "stamp", + "disclaimer", + "aspose", + "facade" + ], + "apis_used": [ + "PdfFileStamp", + "Stamp", + "PdfFileStamp.BindPdf", + "Stamp.BindPdf", + "PdfFileStamp.AddStamp", + "PdfFileStamp.Save", + "PdfFileStamp.Close" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-translucent-text-watermark-to-pdf-pages": { + "title": "Add Translucent Text Watermark to PDF Pages", + "filename": "add-translucent-text-watermark-to-pdf-pages.cs", + "description": "Shows how to create a 50% opaque text stamp and apply it as a watermark on every page of a PDF document using Aspose.Pdf.", + "tags": [ + "watermark", + "textstamp", + "opacity", + "pdf", + "aspose-pdf" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.Text.TextStamp", + "Aspose.Pdf.Text.FontRepository.FindFont", + "Aspose.Pdf.Page.AddStamp", + "Aspose.Pdf.Color", + "Aspose.Pdf.Text.TextState" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "apply-rotated-image-stamp-bottom-right": { + "title": "Apply Rotated Image Stamp to Bottom Right of PDF Pages", + "filename": "apply-rotated-image-stamp-bottom-right.cs", + "description": "Demonstrates how to add an image stamp rotated 30° to the bottom‑right corner of each page in a PDF using Aspose.Pdf.Facades.", + "tags": [ + "stamp", + "image", + "rotation", + "pdf", + "facade" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.Stamp.BindImage", + "Aspose.Pdf.Facades.Stamp.SetImageSize", + "Aspose.Pdf.Facades.Stamp.Rotation", + "Aspose.Pdf.Facades.Stamp.SetOrigin" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-page-number-stamp-to-pdf": { + "title": "Add Page Number Stamp to PDF", + "filename": "add-page-number-stamp-to-pdf.cs", + "description": "Shows how to use Aspose.Pdf.Facades.PdfFileStamp to add a dynamic page number stamp to each page of a PDF and save the stamped document.", + "tags": [ + "pdf", + "stamp", + "page-number", + "facade", + "aspose-pdf" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "PdfFileStamp.BindPdf", + "PdfFileStamp.AddPageNumber", + "PdfFileStamp.Save", + "PdfFileStamp.Close" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-footer-stamp-10pt-above-bottom": { + "title": "Add Footer Stamp 10 Points Above Bottom Edge", + "filename": "add-footer-stamp-10pt-above-bottom.cs", + "description": "Demonstrates how to place a footer stamp exactly 10 points above the bottom edge of each page by configuring stamp margins with PdfFileStamp.", + "tags": [ + "pdf", + "footer", + "stamp", + "margin", + "Aspose.Pdf" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.FormattedText", + "Aspose.Pdf.Facades.PdfFileStamp.AddFooter", + "Aspose.Pdf.Facades.PdfFileStamp.Close" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "apply-text-stamp-to-even-pages": { + "title": "Apply Text Stamp to Even Pages of a PDF", + "filename": "apply-text-stamp-to-even-pages.cs", + "description": "Shows how to add a text stamp only to even-numbered pages of a PDF using Aspose.Pdf.Facades.", + "tags": [ + "pdf", + "stamp", + "even-pages", + "text-watermark", + "facade" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.PdfFileStamp.Save", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.Stamp.BindLogo", + "Aspose.Pdf.Facades.Stamp.SetOrigin", + "Aspose.Pdf.Facades.FormattedText" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-qr-code-text-stamp-to-pdf": { + "title": "Add QR Code and Text Stamp to PDF", + "filename": "add-qr-code-text-stamp-to-pdf.cs", + "description": "Demonstrates how to place a QR‑code image together with descriptive text on each page of a PDF using Aspose.Pdf.Facades stamping APIs.", + "tags": [ + "pdf", + "stamp", + "qr-code", + "facades", + "aspnet" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.FormattedText", + "Aspose.Pdf.Facades.EncodingType", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.Stamp.BindImage", + "Aspose.Pdf.Facades.Stamp.BindLogo", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "apply-stamp-to-specific-pdf-pages": { + "title": "Apply Stamp to Specific PDF Pages Using Aspose.Pdf.Facades", + "filename": "apply-stamp-to-specific-pdf-pages.cs", + "description": "Shows how to add a formatted text stamp to pages 1, 5, and 10 of a PDF by directly specifying the page indices with PdfFileMend.", + "tags": [ + "stamp", + "pdf", + "Aspose.Pdf", + "specific-pages", + "facade" + ], + "apis_used": [ + "PdfFileMend", + "PdfFileMend.BindPdf", + "PdfFileMend.AddText", + "PdfFileMend.Save", + "FormattedText", + "EncodingType" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "apply-image-stamp-to-pdf": { + "title": "Apply Image Stamp to PDF with Overlay Control", + "filename": "apply-image-stamp-to-pdf.cs", + "description": "Demonstrates creating a PDF in memory, generating an image stamp, binding both via streams, setting the stamp to overlay existing content (IsBackground = false), and saving the stamped PDF.", + "tags": [ + "stamp", + "pdf", + "image", + "background", + "Aspose.Pdf" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.Stamp.BindImage", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.Stamp.SetOrigin", + "Aspose.Pdf.Facades.Stamp.IsBackground" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-transparent-confidential-text-stamp": { + "title": "Add Transparent CONFIDENTIAL Text Stamp to Selected PDF Pages", + "filename": "add-transparent-confidential-text-stamp.cs", + "description": "Demonstrates how to place a semi‑transparent CONFIDENTIAL text stamp on specific pages of a PDF using Aspose.Pdf.Facades.", + "tags": [ + "stamp", + "watermark", + "opacity", + "selected-pages", + "Aspose.Pdf" + ], + "apis_used": [ + "Aspose.Pdf.Facades.FormattedText", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.Stamp.BindLogo", + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.PdfFileStamp.Save" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "custom-ttf-font-stamp-pdf": { + "title": "Create Branded PDF Stamp with Custom TrueType Font", + "filename": "custom-ttf-font-stamp-pdf.cs", + "description": "Demonstrates loading a TrueType font from a file and using it to create a text stamp for branding, which is applied to every page of a PDF document.", + "tags": [ + "stamp", + "custom-font", + "branding", + "pdf", + "textstamp" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.FontRepository.OpenFont", + "Aspose.Pdf.Text.TextState", + "Aspose.Pdf.Text.TextStamp", + "Aspose.Pdf.Page.AddStamp", + "Aspose.Pdf.Document.Save" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-page-number-stamp-arabic-numerals": { + "title": "Add Page Number Stamp with Arabic Numerals", + "filename": "add-page-number-stamp-arabic-numerals.cs", + "description": "Demonstrates how to use Aspose.Pdf's PdfFileStamp facade to add sequential page numbers formatted as Arabic numerals to every page of a PDF document.", + "tags": [ + "page-number", + "stamp", + "pdf", + "Aspose.Pdf", + "Arabic-numerals" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.PdfFileStamp.NumberingStyle", + "Aspose.Pdf.Facades.PdfFileStamp.StartingNumber", + "Aspose.Pdf.Facades.PdfFileStamp.AddPageNumber", + "Aspose.Pdf.Facades.PdfFileStamp.Save", + "Aspose.Pdf.Facades.PdfFileStamp.Close" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "batch-apply-rotated-pdf-page-stamp": { + "title": "Batch Apply Rotated PDF Page Stamp to PDFs on Network Share", + "filename": "batch-apply-rotated-pdf-page-stamp.cs", + "description": "Shows how to enumerate PDF files in a UNC folder and apply a rotated page from another PDF as a background stamp to every document using Aspose.Pdf.Facades.", + "tags": [ + "pdf", + "stamp", + "batch", + "rotation", + "network-share" + ], + "apis_used": [ + "PdfFileStamp", + "Stamp", + "Stamp.BindPdf", + "Stamp.Rotation", + "PdfFileStamp.AddStamp", + "PdfFileStamp.Save" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-multi-line-watermark-pdffilemend": { + "title": "Add Multi‑Line Watermark with Different Font Styles using PdfFileMend", + "filename": "add-multi-line-watermark-pdffilemend.cs", + "description": "Demonstrates how to create a three‑line watermark on every PDF page using Aspose.Pdf.Facades.FormattedText and the AddNewLineText method to apply distinct font styles and spacing.", + "tags": [ + "watermark", + "pdf", + "facades", + "formattedtext", + "addnewlinetext" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.Facades.PdfFileMend", + "Aspose.Pdf.Facades.FormattedText", + "Aspose.Pdf.Facades.PdfFileMend.BindPdf", + "Aspose.Pdf.Facades.PdfFileMend.AddText", + "Aspose.Pdf.Facades.FormattedText.AddNewLineText", + "Aspose.Pdf.Facades.PdfFileMend.Save" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-right-aligned-logo-stamp-to-pdf-pages": { + "title": "Add Right-Aligned Logo Stamp to PDF Pages", + "filename": "add-right-aligned-logo-stamp-to-pdf-pages.cs", + "description": "Shows how to place an image stamp (logo) on every page of a PDF and align it to the right margin using Aspose.Pdf.", + "tags": [ + "image-stamp", + "horizontal-alignment", + "pdf", + "logo", + "Aspose.Pdf" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.Page", + "Aspose.Pdf.ImageStamp", + "Aspose.Pdf.HorizontalAlignment", + "Aspose.Pdf.VerticalAlignment", + "Aspose.Pdf.Page.AddStamp", + "Aspose.Pdf.Document.Save" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-semi-transparent-png-background-stamp": { + "title": "Add Semi-Transparent PNG Background Stamp to PDF", + "filename": "add-semi-transparent-png-background-stamp.cs", + "description": "Demonstrates how to use Aspose.Pdf.Facades to place a semi‑transparent PNG image as a background stamp that covers the entire page of a PDF document.", + "tags": [ + "pdf", + "stamp", + "background", + "transparent", + "aspose" + ], + "apis_used": [ + "PdfFileStamp", + "PdfFileStamp.BindPdf", + "Stamp", + "Stamp.BindImage", + "Stamp.IsBackground", + "Stamp.Opacity", + "Stamp.SetImageSize", + "PdfFileStamp.AddStamp", + "PdfFileStamp.Save" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "apply-multi-line-text-stamp": { + "title": "Apply Multi-Line Text Stamp with Custom Line Spacing", + "filename": "apply-multi-line-text-stamp.cs", + "description": "Demonstrates creating a formatted text stamp with multiple lines and 1.5 point extra line spacing, then applying it as a semi‑transparent background watermark to all pages of a PDF.", + "tags": [ + "text-stamp", + "line-spacing", + "watermark", + "pdf", + "csharp" + ], + "apis_used": [ + "Aspose.Pdf.Facades.FormattedText", + "Aspose.Pdf.Facades.FormattedText.AddNewLineText", + "Aspose.Pdf.Facades.Stamp.BindLogo", + "Aspose.Pdf.Facades.Stamp.SetOrigin", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.PdfFileStamp.Save" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-creation-date-stamp-to-pdf": { + "title": "Add Creation Date Stamp to PDF", + "filename": "add-creation-date-stamp-to-pdf.cs", + "description": "Shows how to read a PDF's creation date and place it as a text stamp in the top‑left corner of each page using Aspose.Pdf.", + "tags": [ + "stamp", + "creation-date", + "textstamp", + "pdf", + "aspose" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.Text.TextStamp", + "Aspose.Pdf.FontRepository", + "Aspose.Pdf.Page.AddStamp", + "Aspose.Pdf.Document.Save" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "merge-cover-page-background-pdf": { + "title": "Merge Cover Page as Background Using PdfFileStamp", + "filename": "merge-cover-page-background-pdf.cs", + "description": "Shows how to use Aspose.Pdf.Facades.PdfFileStamp together with a Stamp to place the first page of a cover PDF behind the content of another PDF, creating a merged document.", + "tags": [ + "PdfFileStamp", + "Stamp", + "background", + "merge", + "Aspose.Pdf" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.PdfFileStamp.Save", + "Aspose.Pdf.Facades.Stamp.BindPdf", + "Aspose.Pdf.Facades.Stamp.IsBackground" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-logo-confidential-stamp-to-pdf": { + "title": "Add Logo and Confidential Stamp to PDF", + "filename": "add-logo-confidential-stamp-to-pdf.cs", + "description": "Demonstrates using Aspose.Pdf.Facades to place a company logo image together with bold 'Confidential' text as a semi‑transparent background stamp on every page of a PDF document.", + "tags": [ + "stamp", + "logo", + "confidential", + "pdf", + "Aspose.Pdf" + ], + "apis_used": [ + "PdfFileStamp", + "Stamp", + "FormattedText", + "EncodingType", + "Stamp.SetOrigin", + "Stamp.BindImage", + "Stamp.BindLogo", + "PdfFileStamp.AddStamp" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "apply-multi-line-watermark-custom-line-height": { + "title": "Apply Multi-Line Watermark with Custom Line Height", + "filename": "apply-multi-line-watermark-custom-line-height.cs", + "description": "Demonstrates creating a stamp containing multiple lines of text with equal line spacing and applying it as a background watermark to all pages of a PDF using Aspose.Pdf.Facades.", + "tags": [ + "watermark", + "stamp", + "multiline", + "pdf", + "Aspose.Pdf" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.Stamp.SetOrigin", + "Aspose.Pdf.Facades.Stamp.BindLogo", + "Aspose.Pdf.Facades.FormattedText", + "Aspose.Pdf.Facades.FormattedText.AddNewLineText", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.PdfFileStamp.Save" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "rotate-text-stamp-90-degrees": { + "title": "Rotate Text Stamp by 90 Degrees", + "filename": "rotate-text-stamp-90-degrees.cs", + "description": "Demonstrates creating a formatted text stamp, setting its Rotation property to 90°, and applying it to a PDF using the PdfFileStamp facade.", + "tags": [ + "stamp", + "rotation", + "text", + "pdf", + "facade" + ], + "apis_used": [ + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Text.FormattedText", + "Aspose.Pdf.Facades.Stamp.BindLogo", + "Aspose.Pdf.Facades.Stamp.Rotation", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.PdfFileStamp.Save" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-footer-with-page-count": { + "title": "Add Footer with Automatic Page Count to PDF", + "filename": "add-footer-with-page-count.cs", + "description": "Shows how to use PdfFileStamp to add a footer containing the {page_count} placeholder, which Aspose.Pdf replaces with the total number of pages when the document is saved.", + "tags": [ + "footer", + "page-count", + "pdf", + "stamps", + "Aspose.Pdf" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.PdfFileStamp.AddFooter", + "Aspose.Pdf.Facades.PdfFileStamp.Save", + "Aspose.Pdf.Text.FormattedText" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "create-multi-page-pdf-stamp": { + "title": "Create Multi-Page PDF Stamp from Multiple PDFs", + "filename": "create-multi-page-pdf-stamp.cs", + "description": "Demonstrates combining several PDF files as stamps and applying them to a target PDF using Aspose.Pdf's PdfFileStamp facade.", + "tags": [ + "pdf", + "stamp", + "aspose.pdf", + "csharp", + "facades" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.PdfFileStamp.Save", + "Aspose.Pdf.Facades.PdfFileStamp.Close", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.Stamp.BindPdf", + "Aspose.Pdf.Facades.Stamp.SetOrigin" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-custom-border-stamp-to-pdf-page": { + "title": "Add Custom Border Stamp to PDF Page", + "filename": "add-custom-border-stamp-to-pdf-page.cs", + "description": "Shows how to use PdfContentEditor to create a square annotation with a custom border thickness and color to highlight a specific area in a PDF document.", + "tags": [ + "stamp", + "border", + "annotation", + "pdf", + "Aspose.Pdf" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfContentEditor", + "Aspose.Pdf.Facades.PdfContentEditor.BindPdf", + "Aspose.Pdf.Facades.PdfContentEditor.CreateSquareCircle", + "Aspose.Pdf.Facades.PdfContentEditor.Save" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-rotated-image-stamp-to-first-page": { + "title": "Add Rotated Image Stamp to First Page of PDFs", + "filename": "add-rotated-image-stamp-to-first-page.cs", + "description": "Shows how to batch‑process PDF files in a directory and apply a semi‑transparent, 45‑degree rotated image stamp to the first page of each document using Aspose.Pdf.Facades.", + "tags": [ + "pdf", + "stamp", + "image", + "rotation", + "batch" + ], + "apis_used": [ + "PdfFileStamp", + "Stamp", + "PdfFileStamp.BindPdf", + "Stamp.BindImage", + "Stamp.SetOrigin", + "Stamp.Rotation", + "PdfFileStamp.AddStamp", + "PdfFileStamp.Save" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "apply-image-stamp-to-all-pdf-pages": { + "title": "Apply Image Stamp to All PDF Pages", + "filename": "apply-image-stamp-to-all-pdf-pages.cs", + "description": "Shows how to use PdfFileStamp and Stamp to add a single image stamp to every page of a PDF efficiently in one operation.", + "tags": [ + "pdf", + "stamp", + "image", + "Aspose.Pdf", + "facade" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.Stamp.BindImage", + "Aspose.Pdf.Facades.Stamp.SetOrigin", + "Aspose.Pdf.Facades.Stamp.SetImageSize", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp", + "Aspose.Pdf.Facades.PdfFileStamp.Save" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-file-name-header-stamp": { + "title": "Add File Name Header Stamp to PDF", + "filename": "add-file-name-header-stamp.cs", + "description": "Demonstrates how to place a text stamp in the header of each PDF page that automatically shows the document's file name using the {FileName} placeholder.", + "tags": [ + "text-stamp", + "header", + "placeholder", + "pdf", + "csharp" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.Page", + "Aspose.Pdf.Text.TextStamp", + "Aspose.Pdf.Text.FontRepository", + "Aspose.Pdf.Color" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-background-text-stamp-30-opacity": { + "title": "Add Background Text Stamp with 30% Opacity", + "filename": "add-background-text-stamp-30-opacity.cs", + "description": "Demonstrates how to place a semi‑transparent text stamp behind the content of each page in a PDF using Aspose.Pdf.", + "tags": [ + "pdf", + "watermark", + "background", + "opacity", + "text-stamp" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.Text.TextStamp", + "Aspose.Pdf.Text.FontRepository", + "Aspose.Pdf.Page", + "Aspose.Pdf.Color" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "apply-rotated-text-stamp-to-odd-pages": { + "title": "Apply Rotated Text Stamp to Odd Pages", + "filename": "apply-rotated-text-stamp-to-odd-pages.cs", + "description": "Demonstrates adding a 30‑degree rotated red CONFIDENTIAL text stamp to the left margin of every odd‑numbered page using Aspose.Pdf.Facades.", + "tags": [ + "text-stamp", + "odd-pages", + "rotation", + "Aspose.Pdf", + "PDF" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Text.FormattedText", + "Aspose.Pdf.Text.EncodingType", + "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", + "Aspose.Pdf.Facades.Stamp.BindLogo", + "Aspose.Pdf.Facades.Stamp.Rotation", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-dynamic-text-stamp-to-pdf": { + "title": "Add Dynamic Text Stamp to PDF", + "filename": "add-dynamic-text-stamp-to-pdf.cs", + "description": "Demonstrates loading a PDF, creating a TextStamp with interpolated date and author, configuring its appearance, adding it to the first page, and saving the document.", + "tags": [ + "pdf", + "text-stamp", + "watermark", + "aspose-pdf", + "csharp" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.TextStamp", + "Aspose.Pdf.Page.AddStamp", + "Aspose.Pdf.Document.Save", + "Aspose.Pdf.TextStamp.Background", + "Aspose.Pdf.TextStamp.Opacity" + ], + "difficulty": "beginner", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "add-repeating-background-image-watermark": { + "title": "Add Repeating Background Image Watermark to PDF", + "filename": "add-repeating-background-image-watermark.cs", + "description": "Demonstrates how to use a single Stamp instance to place a semi‑transparent background image on every page of a PDF, creating a repeated watermark effect.", + "tags": [ + "watermark", + "stamp", + "background", + "pdf", + "Aspose" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Facades.Stamp.BindImage", + "Aspose.Pdf.Facades.Stamp.SetOrigin", + "Aspose.Pdf.Facades.Stamp.SetImageSize", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + }, + "apply-multi-line-colored-header-stamp": { + "title": "Apply Multi-Line Colored Header Stamp to PDF", + "filename": "apply-multi-line-colored-header-stamp.cs", + "description": "Demonstrates how to add a multi‑line header to a PDF using Aspose.Pdf.Facades, with each line rendered in a different font color.", + "tags": [ + "pdf", + "header", + "stamp", + "colored-text", + "aspose" + ], + "apis_used": [ + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.FormattedText", + "Aspose.Pdf.Facades.EncodingType", + "PdfFileStamp.AddHeader", + "PdfFileStamp.Close" + ], + "difficulty": "intermediate", + "generated_at": "2026-05-08T09:47:07Z", + "status": "verified" + } + } +} \ No newline at end of file diff --git a/facades-stamps/merge-cover-page-background-pdf.cs b/facades-stamps/merge-cover-page-background-pdf.cs new file mode 100644 index 00000000..d6d4fef4 --- /dev/null +++ b/facades-stamps/merge-cover-page-background-pdf.cs @@ -0,0 +1,46 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string coverPath = "cover.pdf"; // PDF page to use as background + const string mainPath = "document.pdf"; // Main PDF document + const string outputPath = "merged.pdf"; + + // Verify input files exist + if (!File.Exists(coverPath)) + { + Console.Error.WriteLine($"Cover file not found: {coverPath}"); + return; + } + if (!File.Exists(mainPath)) + { + Console.Error.WriteLine($"Main document not found: {mainPath}"); + return; + } + + // Initialize PdfFileStamp facade + PdfFileStamp fileStamp = new PdfFileStamp(); + + // Bind the main document (input) and specify output file + fileStamp.BindPdf(mainPath); + fileStamp.OutputFile = outputPath; // deprecated but functional; alternatively use Save later + + // Create a stamp from the first page of the cover PDF + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + stamp.BindPdf(coverPath, 1); // use page 1 of cover as stamp + stamp.IsBackground = true; // place it behind existing content + + // Add the stamp to the facade + fileStamp.AddStamp(stamp); + + // Save the result and release resources + fileStamp.Save(outputPath); + fileStamp.Close(); + + Console.WriteLine($"Merged PDF saved to '{outputPath}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/rotate-text-stamp-45-degrees.cs b/facades-stamps/rotate-text-stamp-45-degrees.cs new file mode 100644 index 00000000..a5acf6fd --- /dev/null +++ b/facades-stamps/rotate-text-stamp-45-degrees.cs @@ -0,0 +1,41 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Text; + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Create a text stamp with the desired content + TextStamp stamp = new TextStamp("Sample Stamp"); + // Configure text appearance + stamp.TextState.Font = FontRepository.FindFont("Helvetica"); + stamp.TextState.FontSize = 36; + stamp.TextState.ForegroundColor = Aspose.Pdf.Color.Red; + // Position the stamp (coordinates are from the lower‑left corner) + stamp.XIndent = 200f; + stamp.YIndent = 400f; + // Rotate the stamp 45 degrees around its centre + stamp.RotateAngle = 45f; + + // Load the source PDF and apply the stamp to each page (or select pages as needed) + Document pdfDocument = new Document(inputPath); + foreach (Page page in pdfDocument.Pages) + { + page.AddStamp(stamp); + } + + pdfDocument.Save(outputPath); + Console.WriteLine($"PDF with rotated text stamp saved to '{outputPath}'."); + } +} diff --git a/facades-stamps/rotate-text-stamp-90-degrees.cs b/facades-stamps/rotate-text-stamp-90-degrees.cs new file mode 100644 index 00000000..c26a72b3 --- /dev/null +++ b/facades-stamps/rotate-text-stamp-90-degrees.cs @@ -0,0 +1,50 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; +using Aspose.Pdf.Text; // Required for FormattedText and EncodingType + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + + // Verify that the source PDF exists + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Create formatted text that will be used as the stamp content + // Note: FormattedText constructor expects System.Drawing.Color for the text color + FormattedText formattedText = new FormattedText( + "ROTATED TEXT", // Text to display + System.Drawing.Color.Black, // Text color + "Helvetica", // Font name + EncodingType.Winansi, // Encoding + false, // IsEmbedded (false = use system font) + 36); // Font size + + // Initialize a Aspose.Pdf.Facades.Stamp object and bind the formatted text + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + stamp.BindLogo(formattedText); + + // Set the rotation to 90 degrees + stamp.Rotation = 90; + + // Output the rotation value to verify it was set correctly + Console.WriteLine($"Aspose.Pdf.Facades.Stamp rotation set to: {stamp.Rotation} degrees"); + + // Use the PdfFileStamp facade to apply the stamp to the PDF + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(inputPath); // Load the source PDF + fileStamp.AddStamp(stamp); // Add the rotated text stamp + fileStamp.Save(outputPath); // Save the resulting PDF + fileStamp.Close(); // Release resources + + Console.WriteLine($"Stamped PDF saved to '{outputPath}'."); + } +} \ No newline at end of file diff --git a/facades-stamps/stamp-pdf-with-external-template.cs b/facades-stamps/stamp-pdf-with-external-template.cs new file mode 100644 index 00000000..4a794133 --- /dev/null +++ b/facades-stamps/stamp-pdf-with-external-template.cs @@ -0,0 +1,50 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; // PDF to be stamped + const string templatePdf = "template.pdf"; // External PDF used as stamp template + const string outputPdf = "output.pdf"; // Resulting PDF + + // Verify that source files exist + if (!File.Exists(inputPdf) || !File.Exists(templatePdf)) + { + Console.Error.WriteLine("Input PDF or template PDF not found."); + return; + } + + // ------------------------------------------------- + // 1. Create and load the target document via PdfFileStamp + // ------------------------------------------------- + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(inputPdf); // Load the document to be stamped + + // ------------------------------------------------- + // 2. Create a stamp that uses a page from the template PDF + // ------------------------------------------------- + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + + // Bind the first page of the template PDF as the stamp content + stamp.BindPdf(templatePdf, 1); + + // Apply the stamp only to the third page of the target PDF + stamp.Pages = new int[] { 3 }; + + // Optional: place the stamp behind existing content + stamp.IsBackground = true; + + // ------------------------------------------------- + // 3. Add the stamp to the document and save + // ------------------------------------------------- + fileStamp.AddStamp(stamp); + fileStamp.Save(outputPdf); // Persist changes to the output file + fileStamp.Close(); // Release resources + + Console.WriteLine($"Stamped PDF saved to '{outputPdf}'."); + } +} \ No newline at end of file