From 25f4d5177e1dc7a2fe1d31c35cab22b193115ba6 Mon Sep 17 00:00:00 2001 From: Aspose-Tester Date: Thu, 20 Aug 2026 01:07:21 -0700 Subject: [PATCH 1/2] Add 28 example(s) for facades-texts-and-images --- facades-texts-and-images/AGENTS.md | 79 ++- facades-texts-and-images/README.md | 47 -- .../add-background-png-to-all-pdf-pages.cs | 85 ++- .../add-header-image-to-pdf-documents.cs | 48 ++ .../add-header-image-to-pdfs.cs | 66 -- .../add-image-and-text-audit-pdf.cs | 94 --- ...mage-and-text-to-pdf-with-audit-logging.cs | 74 +++ .../add-image-and-text-watermark-to-pdf.cs | 94 +-- ...image-to-all-pdf-pages-dynamic-position.cs | 84 --- ...image-to-each-pdf-page-dynamic-position.cs | 77 +++ .../add-image-to-pdf-get-memorystream.cs | 73 --- .../add-image-to-pdf-page.cs | 98 ++- .../add-image-to-pdf-using-pdffilemend.cs | 47 ++ ...add-image-to-pdf-with-format-validation.cs | 53 ++ .../add-image-to-pdf-with-pdffilemend.cs | 47 -- .../add-image-verify-pdf-byte-size.cs | 114 ++++ .../add-images-to-pdf-with-error-handling.cs | 37 +- .../add-multi-line-text-block-page-3.cs | 62 ++ .../add-multi-line-text-left-margin-page-3.cs | 64 -- .../add-png-image-to-pdf-page.cs | 77 +-- ...add-promotional-text-multiple-pdf-pages.cs | 58 -- ...-promotional-text-to-specific-pdf-pages.cs | 44 ++ ...add-text-at-coordinates-verify-position.cs | 133 +++++ .../add-tiff-image-to-last-page-pdf.cs | 58 ++ .../add-tiff-image-to-last-pdf-page.cs | 60 -- .../add-word-wrapped-footer-to-pdf.cs | 41 -- .../add-wrapped-footer-to-pdf-pages.cs | 61 ++ .../async-add-image-to-pdf.cs | 142 +++-- .../batch-add-company-logo-to-pdfs.cs | 68 +++ .../batch-add-logo-to-pdf-pages.cs | 76 --- .../batch-extract-images-from-pdfs.cs | 99 ++- ...ure-word-wrapping-bywords-add-long-text.cs | 53 ++ .../configure-word-wrapping-bywords.cs | 46 -- .../extract-images-from-pdf-pages-2-5.cs | 43 -- .../extract-images-from-pdf-pages.cs | 47 ++ .../extract-images-from-pdf-to-png.cs | 40 +- facades-texts-and-images/index.json | 563 +++++++++--------- ...sert-png-signature-image-every-pdf-page.cs | 57 -- ...t-png-signature-image-on-every-pdf-page.cs | 51 ++ .../overlay-semi-transparent-gif-on-pdf.cs | 68 ++- .../remove-all-images-from-pdf.cs | 58 +- .../remove-image-from-pdf-page.cs | 16 +- .../replace-jpeg-with-bmp-first-page.cs | 65 ++ ...eplace-jpeg-with-bmp-using-replaceimage.cs | 85 --- ...place-low-res-images-with-high-res-pngs.cs | 71 +++ .../replace-lowres-images-with-highres-png.cs | 52 -- ...-jpg-png-gif-bmp-or-tiff-files-are-used.cs | 58 -- ...verify-free-text-annotation-coordinates.cs | 146 ----- 48 files changed, 1866 insertions(+), 1913 deletions(-) delete mode 100644 facades-texts-and-images/README.md create mode 100644 facades-texts-and-images/add-header-image-to-pdf-documents.cs delete mode 100644 facades-texts-and-images/add-header-image-to-pdfs.cs delete mode 100644 facades-texts-and-images/add-image-and-text-audit-pdf.cs create mode 100644 facades-texts-and-images/add-image-and-text-to-pdf-with-audit-logging.cs delete mode 100644 facades-texts-and-images/add-image-to-all-pdf-pages-dynamic-position.cs create mode 100644 facades-texts-and-images/add-image-to-each-pdf-page-dynamic-position.cs delete mode 100644 facades-texts-and-images/add-image-to-pdf-get-memorystream.cs create mode 100644 facades-texts-and-images/add-image-to-pdf-using-pdffilemend.cs create mode 100644 facades-texts-and-images/add-image-to-pdf-with-format-validation.cs delete mode 100644 facades-texts-and-images/add-image-to-pdf-with-pdffilemend.cs create mode 100644 facades-texts-and-images/add-image-verify-pdf-byte-size.cs create mode 100644 facades-texts-and-images/add-multi-line-text-block-page-3.cs delete mode 100644 facades-texts-and-images/add-multi-line-text-left-margin-page-3.cs delete mode 100644 facades-texts-and-images/add-promotional-text-multiple-pdf-pages.cs create mode 100644 facades-texts-and-images/add-promotional-text-to-specific-pdf-pages.cs create mode 100644 facades-texts-and-images/add-text-at-coordinates-verify-position.cs create mode 100644 facades-texts-and-images/add-tiff-image-to-last-page-pdf.cs delete mode 100644 facades-texts-and-images/add-tiff-image-to-last-pdf-page.cs delete mode 100644 facades-texts-and-images/add-word-wrapped-footer-to-pdf.cs create mode 100644 facades-texts-and-images/add-wrapped-footer-to-pdf-pages.cs create mode 100644 facades-texts-and-images/batch-add-company-logo-to-pdfs.cs delete mode 100644 facades-texts-and-images/batch-add-logo-to-pdf-pages.cs create mode 100644 facades-texts-and-images/configure-word-wrapping-bywords-add-long-text.cs delete mode 100644 facades-texts-and-images/configure-word-wrapping-bywords.cs delete mode 100644 facades-texts-and-images/extract-images-from-pdf-pages-2-5.cs create mode 100644 facades-texts-and-images/extract-images-from-pdf-pages.cs delete mode 100644 facades-texts-and-images/insert-png-signature-image-every-pdf-page.cs create mode 100644 facades-texts-and-images/insert-png-signature-image-on-every-pdf-page.cs create mode 100644 facades-texts-and-images/replace-jpeg-with-bmp-first-page.cs delete mode 100644 facades-texts-and-images/replace-jpeg-with-bmp-using-replaceimage.cs create mode 100644 facades-texts-and-images/replace-low-res-images-with-high-res-pngs.cs delete mode 100644 facades-texts-and-images/replace-lowres-images-with-highres-png.cs delete mode 100644 facades-texts-and-images/validate-image-format-before-calling-addimage-to-ensure-only-jpg-png-gif-bmp-or-tiff-files-are-used.cs delete mode 100644 facades-texts-and-images/verify-free-text-annotation-coordinates.cs diff --git a/facades-texts-and-images/AGENTS.md b/facades-texts-and-images/AGENTS.md index 2aef86dff..ae03e4dac 100644 --- a/facades-texts-and-images/AGENTS.md +++ b/facades-texts-and-images/AGENTS.md @@ -8,7 +8,7 @@ parent: ../agents.md # AGENTS - facades-texts-and-images -> **Facades texts and images** in PDF using C# / .NET -- **28** verified, compile-tested examples for **Aspose.PDF for .NET** 26.7.0. Each `.cs` file is a standalone, build-validated console example, generated and runtime-checked by an AI agent before publishing. +> **Facades texts and images** in PDF using C# / .NET -- **28** verified, compile-tested examples for **Aspose.PDF for .NET** 26.8.0. Each `.cs` file is a standalone, build-validated console example, generated and runtime-checked by an AI agent before publishing. ## Persona @@ -23,19 +23,18 @@ See the root [agents.md](../agents.md) for repository-wide conventions and bound ## Required Namespaces -- `using Aspose.Pdf.Facades;` (27/28 files) ← category-specific -- `using Aspose.Pdf;` (17/28 files) ← category-specific -- `using Aspose.Pdf.Text;` (3/28 files) -- `using Aspose.Pdf.Annotations;` (1/28 files) -- `using Aspose.Pdf.Drawing;` (1/28 files) +- `using Aspose.Pdf.Facades;` (28/28 files) ← category-specific +- `using Aspose.Pdf;` (14/28 files) ← category-specific +- `using Aspose.Pdf.Text;` (5/28 files) - `using System;` (28/28 files) -- `using System.IO;` (26/28 files) -- `using System.Drawing;` (5/28 files) -- `using System.Drawing.Imaging;` (2/28 files) -- `using System.Threading.Tasks;` (2/28 files) +- `using System.IO;` (27/28 files) +- `using System.Drawing.Imaging;` (3/28 files) +- `using System.Drawing;` (2/28 files) +- `using System.Linq;` (2/28 files) +- `using Microsoft.VisualStudio.TestTools.UnitTesting;` (1/28 files) - `using NUnit.Framework;` (1/28 files) -- `using System.Runtime.Versioning;` (1/28 files) - `using System.Threading;` (1/28 files) +- `using System.Threading.Tasks;` (1/28 files) ## Common Code Pattern @@ -52,34 +51,34 @@ tool.Save("output.pdf"); | File | Title | Key APIs | Description | |------|-------|----------|-------------| -| [add-background-png-to-all-pdf-pages](./add-background-png-to-all-pdf-pages.cs) | Add Background PNG to All PDF Pages | `PdfFileMend`, `BindPdf`, `AddImage` | Demonstrates how to overlay a PNG image as a full‑page background on every page of a PDF using th... | -| [add-header-image-to-pdfs](./add-header-image-to-pdfs.cs) | Add Header Image to PDFs | `PdfFileStamp`, `BindPdf`, `AddHeader` | Shows how to attach a header image to each page of multiple PDF documents and save the modified f... | -| [add-image-and-text-audit-pdf](./add-image-and-text-audit-pdf.cs) | Add Image and Text to PDF with Audit Logging | `Document`, `PdfFileMend`, `AddImage` | Demonstrates how to insert an image and a text annotation into a PDF using Aspose.Pdf facades whi... | -| [add-image-and-text-watermark-to-pdf](./add-image-and-text-watermark-to-pdf.cs) | Add Image and Text Watermark to PDF Pages | `Document`, `Page`, `ImageStamp` | Demonstrates how to overlay a semi‑transparent image and centered text as a watermark on each pag... | -| [add-image-to-all-pdf-pages-dynamic-position](./add-image-to-all-pdf-pages-dynamic-position.cs) | Add Image to All PDF Pages with Dynamic Positioning | `Document`, `PdfFileMend`, `Page` | Demonstrates loading a PDF, calculating each page's dimensions, and placing an image at the botto... | -| [add-image-to-pdf-get-memorystream](./add-image-to-pdf-get-memorystream.cs) | Add Image to PDF and Return MemoryStream | `PdfFileMend`, `BindPdf`, `AddImage` | Shows how to bind an existing PDF with Aspose.Pdf.Facades.PdfFileMend, add an image to the first ... | -| [add-image-to-pdf-page](./add-image-to-pdf-page.cs) | Add Image to Specific PDF Page | `Document`, `PdfFileMend`, `AddImage` | Shows how to insert an image onto a chosen PDF page at given rectangle coordinates using Aspose.P... | -| [add-image-to-pdf-with-pdffilemend](./add-image-to-pdf-with-pdffilemend.cs) | Add Image to PDF Using PdfFileMend with Try‑Finally | `PdfFileMend`, `BindPdf`, `AddImage` | Demonstrates how to bind a PDF, add an image stamp to a page, save the modified document, and gua... | -| [add-images-to-pdf-with-error-handling](./add-images-to-pdf-with-error-handling.cs) | Add Images to PDF with Error Handling | `PdfFileMend`, `AddImage`, `Close` | Demonstrates how to insert multiple images into a PDF using Aspose.Pdf's PdfFileMend class while ... | -| [add-multi-line-text-left-margin-page-3](./add-multi-line-text-left-margin-page-3.cs) | Add Multi‑Line Text with Custom Line Spacing to Left Margin ... | `PdfFileMend`, `BindPdf`, `Save` | Demonstrates how to insert a multi‑line text block with custom line spacing into the left margin ... | -| [add-png-image-to-pdf-page](./add-png-image-to-pdf-page.cs) | Add PNG Image to PDF Page Using PdfFileMend | `PdfFileMend`, `BindPdf`, `AddImage` | Demonstrates how to bind an existing PDF with PdfFileMend, insert a PNG image onto page two at sp... | -| [add-promotional-text-multiple-pdf-pages](./add-promotional-text-multiple-pdf-pages.cs) | Add Promotional Text to Multiple PDF Pages | `PdfFileMend`, `BindPdf`, `AddText` | Demonstrates inserting the same promotional text on pages 3, 5, and 7 of a PDF using PdfFileMend.... | -| [add-tiff-image-to-last-pdf-page](./add-tiff-image-to-last-pdf-page.cs) | Add TIFF Image to Last Page of PDF with PdfFileMend | `PdfFileMend`, `BindPdf`, `AddImage` | Demonstrates using PdfFileMend to bind an existing PDF, determine its last page, and embed a TIFF... | -| [add-word-wrapped-footer-to-pdf](./add-word-wrapped-footer-to-pdf.cs) | Add Word‑by‑Word Wrapped Footer to PDF Pages | `PdfFileStamp`, `FormattedText`, `BindPdf` | Shows how to add a formatted text footer that automatically wraps word‑by‑word across the page wi... | -| [async-add-image-to-pdf](./async-add-image-to-pdf.cs) | Asynchronously Add Image to PDF with PdfFileMend | `PdfFileMend`, `BindPdf`, `AddImage` | Shows how to add an image to a specific page of a PDF file asynchronously by wrapping the synchro... | -| [batch-add-logo-to-pdf-pages](./batch-add-logo-to-pdf-pages.cs) | Batch Add Logo to PDF Pages | `Document`, `PdfFileMend`, `BindPdf` | Shows how to iterate through a folder of PDF files and overlay a PNG company logo at the top‑righ... | -| [batch-extract-images-from-pdfs](./batch-extract-images-from-pdfs.cs) | Batch Extract Images from PDFs with Page‑Based Naming | `SplitToPages`, `BindPdf`, `ExtractImage` | The example splits each PDF into single‑page files, extracts all images from each page, and saves... | -| [configure-word-wrapping-bywords](./configure-word-wrapping-bywords.cs) | Configure Word Wrapping ByWords and Add Wrapped Text | `Document`, `PdfFileMend`, `FormattedText` | Demonstrates enabling word‑wrap, setting the wrap mode to ByWords, and adding a long paragraph th... | -| [extract-images-from-pdf-pages-2-5](./extract-images-from-pdf-pages-2-5.cs) | Extract Images from PDF Pages 2‑5 | `PdfExtractor`, `BindPdf`, `StartPage` | Shows how to extract all images from a specific page range in a PDF using Aspose.Pdf.Facades.PdfE... | -| [extract-images-from-pdf-to-png](./extract-images-from-pdf-to-png.cs) | Extract Images from PDF to PNG | `PdfExtractor`, `BindPdf`, `ExtractImage` | Shows how to use Aspose.Pdf.Facades.PdfExtractor to extract every image from a PDF document and s... | -| [insert-png-signature-image-every-pdf-page](./insert-png-signature-image-every-pdf-page.cs) | Insert PNG Signature Image on Every PDF Page | `Document`, `PdfFileMend`, `BindPdf` | Shows how to use PdfFileMend to add a PNG signature image to the bottom‑left corner of each page ... | -| [overlay-semi-transparent-gif-on-pdf](./overlay-semi-transparent-gif-on-pdf.cs) | Overlay Semi-Transparent GIF onto PDF Image | `PdfFileMend`, `CompositingParameters`, `BlendMode` | Demonstrates how to overlay a semi‑transparent GIF onto an existing PDF page that already contain... | -| [remove-all-images-from-pdf](./remove-all-images-from-pdf.cs) | Remove All Images from a PDF | `PdfContentEditor`, `BindPdf`, `DeleteImage` | Shows how to load a PDF, delete every image on all pages using Aspose.Pdf.Facades, and save the m... | -| [remove-image-from-pdf-page](./remove-image-from-pdf-page.cs) | Remove Image from PDF Page using Aspose.Pdf | `PdfContentEditor`, `BindPdf`, `DeleteImage` | Demonstrates how to delete a specific image identified by its object ID from a given page of a PD... | -| [replace-jpeg-with-bmp-using-replaceimage](./replace-jpeg-with-bmp-using-replaceimage.cs) | Replace JPEG with Higher‑Resolution BMP Using ReplaceImage | `Document`, `Page`, `Image` | Demonstrates how to create a PDF with an embedded JPEG, generate a higher‑resolution BMP in memor... | -| [replace-lowres-images-with-highres-png](./replace-lowres-images-with-highres-png.cs) | Replace Low-Resolution Images with High-Resolution PNGs in P... | `Document`, `PdfContentEditor`, `BindPdf` | Shows how to iterate through PDF pages and replace each embedded image with a high‑resolution PNG... | -| [validate-image-format-before-calling-addimage-to-e...](./validate-image-format-before-calling-addimage-to-ensure-only-jpg-png-gif-bmp-or-tiff-files-are-used.cs) | Validate Image Format Before Calling Addimage To Ensure Only... | `PdfFileMend` | Validate Image Format Before Calling Addimage To Ensure Only Jpg Png Gif Bmp Or Tiff Files Are Used | -| [verify-free-text-annotation-coordinates](./verify-free-text-annotation-coordinates.cs) | Verify Free Text Annotation Coordinates with PdfContentEdito... | `PdfContentEditor`, `Document`, `BindPdf` | Shows how to add a free‑text annotation to a PDF using PdfContentEditor and unit‑test that its re... | +| [add-background-png-to-all-pdf-pages](./add-background-png-to-all-pdf-pages.cs) | Add Background PNG to All PDF Pages | `Document`, `Rect`, `BindPdf` | Shows how to load a PDF, retrieve each page's dimensions, and overlay a PNG image as a background... | +| [add-header-image-to-pdf-documents](./add-header-image-to-pdf-documents.cs) | Add Header Image to PDF Documents | `PdfFileStamp`, `BindPdf`, `AddHeader` | Shows how to insert a header image into one or more PDF files using Aspose.Pdf.Facades.PdfFileSta... | +| [add-image-and-text-to-pdf-with-audit-logging](./add-image-and-text-to-pdf-with-audit-logging.cs) | Add Image and Text to PDF with Audit Logging | `Document`, `PdfFileMend`, `AddImage` | Loads a PDF, adds an image and a formatted text watermark to page 1, logs each AddImage and AddTe... | +| [add-image-and-text-watermark-to-pdf](./add-image-and-text-watermark-to-pdf.cs) | Add Image and Semi‑Transparent Text Watermark to PDF | `PdfFileStamp`, `Stamp`, `FormattedText` | Demonstrates how to combine an image and semi‑transparent text into a single stamp and apply it a... | +| [add-image-to-each-pdf-page-dynamic-position](./add-image-to-each-pdf-page-dynamic-position.cs) | Add Image to Each PDF Page with Dynamic Positioning | `Document`, `Page`, `PdfFileMend` | Loads a PDF, calculates each page's dimensions, and places a PNG image in the bottom‑right corner... | +| [add-image-to-pdf-page](./add-image-to-pdf-page.cs) | Add Image to Specific PDF Page | `PdfFileMend`, `BindPdf`, `AddImage` | Shows how to use Aspose.Pdf.Facades to insert an image onto a chosen page of a PDF at given recta... | +| [add-image-to-pdf-using-pdffilemend](./add-image-to-pdf-using-pdffilemend.cs) | Add Image to PDF Using PdfFileMend with Try‑Finally | `PdfFileMend`, `BindPdf`, `AddImage` | Demonstrates how to bind a PDF, insert an image on a page, save the result, and guarantee that Pd... | +| [add-image-to-pdf-with-format-validation](./add-image-to-pdf-with-format-validation.cs) | Add Image to PDF with Format Validation | `PdfFileMend`, `BindPdf`, `AddImage` | Demonstrates how to validate an image's file format and then add the image to a PDF page using As... | +| [add-image-verify-pdf-byte-size](./add-image-verify-pdf-byte-size.cs) | Add Image to PDF and Verify Byte Size Increase | `Document`, `PdfFileMend`, `BindPdf` | Creates a minimal PDF, binds it with PdfFileMend, adds a PNG image, saves the modified document, ... | +| [add-images-to-pdf-with-error-handling](./add-images-to-pdf-with-error-handling.cs) | Add Images to PDF with Error Handling | `PdfFileMend`, `AddImage`, `Close` | Demonstrates how to insert multiple images into a PDF using Aspose.Pdf's PdfFileMend facade while... | +| [add-multi-line-text-block-page-3](./add-multi-line-text-block-page-3.cs) | Add Multi‑Line Text Block with Custom Line Spacing to Page 3 | `PdfFileMend`, `Document`, `Page` | Demonstrates how to use the PdfFileMend facade to bind an existing PDF, create a multi‑line TextP... | +| [add-png-image-to-pdf-page](./add-png-image-to-pdf-page.cs) | Add PNG Image to Specific PDF Page using PdfFileMend | `PdfFileMend`, `BindPdf`, `AddImage` | Demonstrates how to bind an existing PDF with PdfFileMend, insert a PNG image onto page two at de... | +| [add-promotional-text-to-specific-pdf-pages](./add-promotional-text-to-specific-pdf-pages.cs) | Add Promotional Text to Specific PDF Pages | `PdfFileStamp`, `Stamp`, `FormattedText` | Shows how to insert the same promotional message on pages 3, 5, and 7 of a PDF using Aspose.Pdf's... | +| [add-text-at-coordinates-verify-position](./add-text-at-coordinates-verify-position.cs) | Add Text at Specific Coordinates and Verify Position | `Document`, `Page`, `TextFragment` | Creates a blank PDF, adds a text fragment at defined X/Y coordinates using TextBuilder, saves and... | +| [add-tiff-image-to-last-page-pdf](./add-tiff-image-to-last-page-pdf.cs) | Add TIFF Image to Last Page of PDF using PdfFileMend | `PdfFileMend`, `BindPdf`, `AddImage` | Demonstrates how to use Aspose.Pdf.Facades.PdfFileMend to embed a TIFF image onto the final page ... | +| [add-wrapped-footer-to-pdf-pages](./add-wrapped-footer-to-pdf-pages.cs) | Add Word‑by‑Word Wrapped Footer to PDF Pages | `Document`, `PageInfo`, `FormattedText` | Shows how to use Aspose.Pdf Facade API to add a formatted footer that wraps word‑by‑word across t... | +| [async-add-image-to-pdf](./async-add-image-to-pdf.cs) | Asynchronously Add Image to PDF Using PdfFileMend | `PdfFileMend`, `BindPdf`, `AddImage` | Demonstrates how to modify a PDF on a background thread by adding an image to the first page with... | +| [batch-add-company-logo-to-pdfs](./batch-add-company-logo-to-pdfs.cs) | Batch Add Company Logo to PDFs | `PdfFileMend`, `BindPdf`, `AddImage` | Shows how to process all PDF files in a folder and overlay a PNG company logo at the top‑right co... | +| [batch-extract-images-from-pdfs](./batch-extract-images-from-pdfs.cs) | Batch Extract Images from PDFs with Page and Index Naming | `PdfExtractor`, `BindPdf`, `StartPage` | Shows how to process multiple PDF files, extract images from each page using Aspose.Pdf.Facades.P... | +| [configure-word-wrapping-bywords-add-long-text](./configure-word-wrapping-bywords-add-long-text.cs) | Configure Word Wrapping ByWords and Add Long Text to PDF | `Document`, `PdfFileMend`, `IsWordWrap` | The example shows how to enable word wrapping on a PDF using PdfFileMend, set the wrap mode to By... | +| [extract-images-from-pdf-pages](./extract-images-from-pdf-pages.cs) | Extract Images from Specific PDF Pages | `PdfExtractor`, `BindPdf`, `StartPage` | Shows how to use Aspose.Pdf.Facades.PdfExtractor to extract all images from pages 2‑5 of a PDF an... | +| [extract-images-from-pdf-to-png](./extract-images-from-pdf-to-png.cs) | Extract Images from PDF to PNG using PdfExtractor | `PdfExtractor`, `BindPdf`, `ExtractImage` | Demonstrates how to use Aspose.Pdf's PdfExtractor to extract all images from a PDF document and s... | +| [insert-png-signature-image-on-every-pdf-page](./insert-png-signature-image-on-every-pdf-page.cs) | Insert PNG Signature Image on Every PDF Page | `PdfFileMend`, `BindPdf`, `AddImage` | Demonstrates how to use PdfFileMend to add a PNG signature image to the bottom‑left corner of eac... | +| [overlay-semi-transparent-gif-on-pdf](./overlay-semi-transparent-gif-on-pdf.cs) | Overlay Semi-Transparent GIF on PDF | `PdfFileMend`, `BindPdf`, `AddImage` | Demonstrates how to place a semi‑transparent GIF over an existing PNG in a PDF using CompositingP... | +| [remove-all-images-from-pdf](./remove-all-images-from-pdf.cs) | Remove All Images from PDF | `PdfContentEditor`, `BindPdf`, `DeleteImage` | Shows how to delete every image in a PDF using Aspose.Pdf's PdfContentEditor facade and save the ... | +| [remove-image-from-pdf-page](./remove-image-from-pdf-page.cs) | Remove Image from Specific PDF Page | `PdfContentEditor`, `BindPdf`, `DeleteImage` | Demonstrates how to delete a particular image identified by its object ID from page four of a PDF... | +| [replace-jpeg-with-bmp-first-page](./replace-jpeg-with-bmp-first-page.cs) | Replace JPEG with High‑Resolution BMP on First PDF Page | `Document`, `PdfContentEditor`, `BindPdf` | Demonstrates how to replace the first image on page one of a PDF with a higher‑resolution BMP usi... | +| [replace-low-res-images-with-high-res-pngs](./replace-low-res-images-with-high-res-pngs.cs) | Replace Low-Resolution Images with High-Resolution PNGs in P... | `Document`, `PdfContentEditor`, `PdfExtractor` | Demonstrates how to iterate through each page of a PDF, detect embedded images, and replace low‑r... | ## Category Statistics - Total examples: 28 @@ -124,5 +123,5 @@ tool.Save("output.pdf"); - Review code examples in this folder for facades-texts-and-images patterns -Updated: 2026-07-17 | Run: `20260717_171638_da3b3e` +Updated: 2026-08-20 | Run: `20260820_001147_12d7b3` diff --git a/facades-texts-and-images/README.md b/facades-texts-and-images/README.md deleted file mode 100644 index d959ab6d2..000000000 --- a/facades-texts-and-images/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# Facades texts and images - -> **Facades texts and images** in PDF using C# / .NET -- **28** verified, compile-tested examples for **Aspose.PDF for .NET** 26.7.0. Each `.cs` file is a standalone, build-validated console example, generated and runtime-checked by an AI agent before publishing. - -- Category: `facades-texts-and-images` -- Examples: 28 -- NuGet: `Aspose.PDF 26.7.0` -- target `net10.0` - -## Examples - -- [`add-background-png-to-all-pdf-pages.cs`](./add-background-png-to-all-pdf-pages.cs) -- Add background png to all pdf pages -- [`add-header-image-to-pdfs.cs`](./add-header-image-to-pdfs.cs) -- Add header image to pdfs -- [`add-image-and-text-audit-pdf.cs`](./add-image-and-text-audit-pdf.cs) -- Add image and text audit pdf -- [`add-image-and-text-watermark-to-pdf.cs`](./add-image-and-text-watermark-to-pdf.cs) -- Add image and text watermark to pdf -- [`add-image-to-all-pdf-pages-dynamic-position.cs`](./add-image-to-all-pdf-pages-dynamic-position.cs) -- Add image to all pdf pages dynamic position -- [`add-image-to-pdf-get-memorystream.cs`](./add-image-to-pdf-get-memorystream.cs) -- Add image to pdf get memorystream -- [`add-image-to-pdf-page.cs`](./add-image-to-pdf-page.cs) -- Add image to pdf page -- [`add-image-to-pdf-with-pdffilemend.cs`](./add-image-to-pdf-with-pdffilemend.cs) -- Add image to pdf with pdffilemend -- [`add-images-to-pdf-with-error-handling.cs`](./add-images-to-pdf-with-error-handling.cs) -- Add images to pdf with error handling -- [`add-multi-line-text-left-margin-page-3.cs`](./add-multi-line-text-left-margin-page-3.cs) -- Add multi line text left margin page 3 -- [`add-png-image-to-pdf-page.cs`](./add-png-image-to-pdf-page.cs) -- Add png image to pdf page -- [`add-promotional-text-multiple-pdf-pages.cs`](./add-promotional-text-multiple-pdf-pages.cs) -- Add promotional text multiple pdf pages -- [`add-tiff-image-to-last-pdf-page.cs`](./add-tiff-image-to-last-pdf-page.cs) -- Add tiff image to last pdf page -- [`add-word-wrapped-footer-to-pdf.cs`](./add-word-wrapped-footer-to-pdf.cs) -- Add word wrapped footer to pdf -- [`async-add-image-to-pdf.cs`](./async-add-image-to-pdf.cs) -- Async add image to pdf -- [`batch-add-logo-to-pdf-pages.cs`](./batch-add-logo-to-pdf-pages.cs) -- Batch add logo to pdf pages -- [`batch-extract-images-from-pdfs.cs`](./batch-extract-images-from-pdfs.cs) -- Batch extract images from pdfs -- [`configure-word-wrapping-bywords.cs`](./configure-word-wrapping-bywords.cs) -- Configure word wrapping bywords -- [`extract-images-from-pdf-pages-2-5.cs`](./extract-images-from-pdf-pages-2-5.cs) -- Extract images from pdf pages 2 5 -- [`extract-images-from-pdf-to-png.cs`](./extract-images-from-pdf-to-png.cs) -- Extract images from pdf to png -- [`insert-png-signature-image-every-pdf-page.cs`](./insert-png-signature-image-every-pdf-page.cs) -- Insert png signature image every pdf page -- [`overlay-semi-transparent-gif-on-pdf.cs`](./overlay-semi-transparent-gif-on-pdf.cs) -- Overlay semi transparent gif on pdf -- [`remove-all-images-from-pdf.cs`](./remove-all-images-from-pdf.cs) -- Remove all images from pdf -- [`remove-image-from-pdf-page.cs`](./remove-image-from-pdf-page.cs) -- Remove image from pdf page -- [`replace-jpeg-with-bmp-using-replaceimage.cs`](./replace-jpeg-with-bmp-using-replaceimage.cs) -- Replace jpeg with bmp using replaceimage -- [`replace-lowres-images-with-highres-png.cs`](./replace-lowres-images-with-highres-png.cs) -- Replace lowres images with highres png -- [`validate-image-format-before-calling-addimage-to-ensure-only-jpg-png-gif-bmp-or-tiff-files-are-used.cs`](./validate-image-format-before-calling-addimage-to-ensure-only-jpg-png-gif-bmp-or-tiff-files-are-used.cs) -- Validate image format before calling addimage to ensure only jpg png gif bmp or tiff files are used -- [`verify-free-text-annotation-coordinates.cs`](./verify-free-text-annotation-coordinates.cs) -- Verify free text annotation coordinates - -## See Also - -- [`AGENTS.md`](./AGENTS.md) -- category-specific anti-patterns, API surface, and conventions for AI coding agents -- [`../AGENTS.md`](../AGENTS.md) -- repository-wide agent guide -- [`../README.md`](../README.md) -- full category index and project overview -- [Aspose.PDF for .NET docs](https://docs.aspose.com/pdf/net/) - -> Each `.cs` file is a standalone, build-validated console example. Drop into a fresh `dotnet new console` project, add the `Aspose.PDF` NuGet (version above), and run. diff --git a/facades-texts-and-images/add-background-png-to-all-pdf-pages.cs b/facades-texts-and-images/add-background-png-to-all-pdf-pages.cs index 13a0e37bb..5108c1858 100644 --- a/facades-texts-and-images/add-background-png-to-all-pdf-pages.cs +++ b/facades-texts-and-images/add-background-png-to-all-pdf-pages.cs @@ -7,56 +7,75 @@ class Program { static void Main() { - const string inputPdfPath = "input.pdf"; - const string outputPdfPath = "output.pdf"; - const string backgroundPng = "background.png"; + const string inputPdf = "input.pdf"; + const string outputPdf = "output.pdf"; + const string imagePath = "background.png"; - // Validate input files - if (!File.Exists(inputPdfPath)) + // Validate files + if (!File.Exists(inputPdf)) { - Console.Error.WriteLine($"Input PDF not found: {inputPdfPath}"); + Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); return; } - if (!File.Exists(backgroundPng)) + if (!File.Exists(imagePath)) { - Console.Error.WriteLine($"Background image not found: {backgroundPng}"); + Console.Error.WriteLine($"Background image not found: {imagePath}"); return; } - // Create the PdfFileMend facade - PdfFileMend mender = new PdfFileMend(); - - // Load the source PDF - mender.BindPdf(inputPdfPath); + // ----------------------------------------------------------------- + // 1. Load the PDF to obtain page count and page rectangles. + // Aspose.Pdf uses 1‑based page indexing. + // ----------------------------------------------------------------- + int pageCount; + (double llx, double lly, double urx, double ury)[] pageRects; - // Open the background image once and reuse the stream for each page - using (FileStream imgStream = File.OpenRead(backgroundPng)) + using (Document doc = new Document(inputPdf)) { - // Get total page count (Aspose.Pdf uses 1‑based indexing) - int pageCount = mender.Document.Pages.Count; + pageCount = doc.Pages.Count; + pageRects = new (double, double, double, double)[pageCount]; - // Iterate over all pages and add the image as background - for (int pageNum = 1; pageNum <= pageCount; pageNum++) + for (int i = 1; i <= pageCount; i++) { - // Reset stream position for each AddImage call - imgStream.Position = 0; + var rect = doc.Pages[i].Rect; + pageRects[i - 1] = (rect.LLX, rect.LLY, rect.URX, rect.URY); + } + } + + // ----------------------------------------------------------------- + // 2. Initialise PdfFileMend without the obsolete destination ctor. + // Bind the source PDF, then add images, and finally Save. + // ----------------------------------------------------------------- + PdfFileMend mender = new PdfFileMend(); + mender.BindPdf(inputPdf); - // Retrieve page dimensions - Page page = mender.Document.Pages[pageNum]; - float pageWidth = (float)page.Rect.Width; - float pageHeight = (float)page.Rect.Height; + // ----------------------------------------------------------------- + // 3. Iterate over all pages and add the background image. + // Use the stream overload of AddImage and cast coordinates to float. + // ----------------------------------------------------------------- + for (int i = 1; i <= pageCount; i++) + { + var (llx, lly, urx, ury) = pageRects[i - 1]; - // Add the image covering the whole page - // lowerLeftX = 0, lowerLeftY = 0, upperRightX = pageWidth, upperRightY = pageHeight - mender.AddImage(imgStream, pageNum, 0, 0, pageWidth, pageHeight); + using (FileStream imgStream = File.OpenRead(imagePath)) + { + mender.AddImage( + imgStream, + i, + (float)llx, + (float)lly, + (float)urx, + (float)ury); } } - // Save the modified PDF - mender.Save(outputPdfPath); - - // Release resources + // ----------------------------------------------------------------- + // 4. Save the modified PDF and release resources. + // ----------------------------------------------------------------- + mender.Save(outputPdf); mender.Close(); + + Console.WriteLine($"Background image added to all {pageCount} pages. Output saved to '{outputPdf}'."); } -} \ No newline at end of file +} diff --git a/facades-texts-and-images/add-header-image-to-pdf-documents.cs b/facades-texts-and-images/add-header-image-to-pdf-documents.cs new file mode 100644 index 000000000..92b7fd2b7 --- /dev/null +++ b/facades-texts-and-images/add-header-image-to-pdf-documents.cs @@ -0,0 +1,48 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main(string[] args) + { + // Expect at least a header image path and one PDF file path + if (args.Length < 2) + { + Console.Error.WriteLine("Usage: app.exe [ ...]"); + return; + } + + string headerImagePath = args[0]; + if (!File.Exists(headerImagePath)) + { + Console.Error.WriteLine($"Header image not found: {headerImagePath}"); + return; + } + + // Process each PDF file supplied on the command line + for (int i = 1; i < args.Length; i++) + { + string inputPdfPath = args[i]; + if (!File.Exists(inputPdfPath)) + { + Console.Error.WriteLine($"PDF not found: {inputPdfPath}"); + continue; + } + + // Create an output file name by appending "_header" before the extension + string outputPdfPath = Path.Combine( + Path.GetDirectoryName(inputPdfPath) ?? string.Empty, + Path.GetFileNameWithoutExtension(inputPdfPath) + "_header.pdf"); + + // Use PdfFileStamp to add the header image + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(inputPdfPath); // Load the source PDF + fileStamp.AddHeader(headerImagePath, 50f); // Add image as header with a top margin of 50 units + fileStamp.Save(outputPdfPath); // Write the modified PDF to the output path + fileStamp.Close(); // Release resources + + Console.WriteLine($"Processed: {inputPdfPath} → {outputPdfPath}"); + } + } +} \ No newline at end of file diff --git a/facades-texts-and-images/add-header-image-to-pdfs.cs b/facades-texts-and-images/add-header-image-to-pdfs.cs deleted file mode 100644 index dc79cd9a9..000000000 --- a/facades-texts-and-images/add-header-image-to-pdfs.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.IO; -using Aspose.Pdf.Facades; - -class Program -{ - static void Main() - { - // Path to the header image that will be added to each PDF. - const string headerImagePath = "header.jpg"; - - // List of PDF files to process. - string[] inputPdfFiles = new[] - { - "document1.pdf", - "document2.pdf", - "document3.pdf" - }; - - // Directory where the output PDFs with headers will be saved. - const string outputDirectory = "ProcessedPdfs"; - - // Ensure the output directory exists. - Directory.CreateDirectory(outputDirectory); - - // Verify that the header image exists before processing. - if (!File.Exists(headerImagePath)) - { - Console.Error.WriteLine($"Header image not found: {headerImagePath}"); - return; - } - - foreach (string inputPath in inputPdfFiles) - { - // Skip missing input files. - if (!File.Exists(inputPath)) - { - Console.Error.WriteLine($"Input PDF not found: {inputPath}"); - continue; - } - - // Build the output file path. - string outputPath = Path.Combine( - outputDirectory, - Path.GetFileNameWithoutExtension(inputPath) + "_withHeader.pdf"); - - // Use PdfFileStamp to add the header image. - using (PdfFileStamp stamp = new PdfFileStamp()) - { - // Bind the source PDF. - stamp.BindPdf(inputPath); - - // Add the header image. Top margin is set to 20 points. - stamp.AddHeader(headerImagePath, 20f); - - // Save the modified PDF to the output path. - stamp.Save(outputPath); - - // Close the stamp facade (writes any remaining changes). - stamp.Close(); - } - - Console.WriteLine($"Processed: {inputPath} → {outputPath}"); - } - } -} \ No newline at end of file diff --git a/facades-texts-and-images/add-image-and-text-audit-pdf.cs b/facades-texts-and-images/add-image-and-text-audit-pdf.cs deleted file mode 100644 index 9c0c0ca65..000000000 --- a/facades-texts-and-images/add-image-and-text-audit-pdf.cs +++ /dev/null @@ -1,94 +0,0 @@ -using System; -using System.IO; -using System.Drawing; // for System.Drawing.Rectangle -using Aspose.Pdf; -using Aspose.Pdf.Facades; - -class PdfAuditProcessor -{ - // Simple audit logger – appends a line to a log file. - private static void LogOperation(string operation, int pageNumber, string detail) - { - string timestamp = DateTime.UtcNow.ToString("o"); // ISO 8601 format - string logLine = $"{timestamp} | {operation} | Page: {pageNumber} | Detail: {detail}"; - File.AppendAllText("audit.log", logLine + Environment.NewLine); - } - - static void Main() - { - const string inputPdfPath = "input.pdf"; - const string outputPdfPath = "output.pdf"; - - // ----- Add Image using PdfFileMend ----- - const string imagePath = "logo.png"; - int imagePage = 1; - float imgLlX = 50f, imgLlY = 700f, imgUrX = 150f, imgUrY = 800f; - - // Ensure input files exist - if (!File.Exists(inputPdfPath)) - { - Console.Error.WriteLine($"Input PDF not found: {inputPdfPath}"); - return; - } - if (!File.Exists(imagePath)) - { - Console.Error.WriteLine($"Image file not found: {imagePath}"); - return; - } - - // Load PDF and bind it to PdfFileMend - using (Document doc = new Document(inputPdfPath)) - using (PdfFileMend mend = new PdfFileMend()) - { - mend.BindPdf(doc); // initialize facade with the document - - // Add the image - using (FileStream imgStream = File.OpenRead(imagePath)) - { - bool added = mend.AddImage(imgStream, imagePage, imgLlX, imgLlY, imgUrX, imgUrY); - if (added) - { - LogOperation("AddImage", imagePage, Path.GetFileName(imagePath)); - } - else - { - Console.Error.WriteLine("Failed to add image."); - } - } - - // Save intermediate result (still the final output file) - mend.Save(outputPdfPath); - } - - // ----- Add Text using PdfContentEditor ----- - const string textContent = "Confidential"; - int textPage = 2; - // System.Drawing.Rectangle expects (x, y, width, height) - System.Drawing.Rectangle textRect = new System.Drawing.Rectangle( - 100, // X (lower‑left X) - 500, // Y (lower‑left Y) - 300 - 100, // Width - 550 - 500); // Height - - const string fontName = "Helvetica"; - const int fontSize = 24; - const bool isBold = false; - const string colorHex = "#FF0000"; // Red in hex - - // Load the PDF (the one just saved with the image) and bind it to PdfContentEditor - using (Document doc = new Document(outputPdfPath)) - using (PdfContentEditor editor = new PdfContentEditor()) - { - editor.BindPdf(doc); // initialize facade with the document - - // Create a text annotation on the specified page - editor.CreateText(textRect, textContent, fontName, isBold, colorHex, fontSize); - LogOperation("AddText", textPage, textContent); - - // Save final PDF - editor.Save(outputPdfPath); - } - - Console.WriteLine($"Processing completed. Output saved to '{outputPdfPath}'. Audit log written to 'audit.log'."); - } -} \ No newline at end of file diff --git a/facades-texts-and-images/add-image-and-text-to-pdf-with-audit-logging.cs b/facades-texts-and-images/add-image-and-text-to-pdf-with-audit-logging.cs new file mode 100644 index 000000000..239acd3e9 --- /dev/null +++ b/facades-texts-and-images/add-image-and-text-to-pdf-with-audit-logging.cs @@ -0,0 +1,74 @@ +using System; +using System.IO; +using System.Drawing; // for System.Drawing.Color +using Aspose.Pdf; +using Aspose.Pdf.Facades; // Facades types (PdfFileMend, FormattedText, EncodingType) + +class Program +{ + // Simple logger that writes to console (could be redirected to a file) + static void LogOperation(string operation, string fileName, int pageNumber) + { + string timestamp = DateTime.Now.ToString("o"); // ISO 8601 format + Console.WriteLine($"{timestamp} | {operation} | Page: {pageNumber} | File: {fileName}"); + } + + static void Main() + { + const string inputPdfPath = "input.pdf"; + const string outputPdfPath = "output.pdf"; + + const string imagePath = "logo.png"; // image to add + const string textToAdd = "Confidential"; // text to add + + // Coordinates for image and text (lower‑left X/Y, upper‑right X/Y for image; + // X/Y for text). Adjust as needed. + const float imgLlX = 50f, imgLlY = 700f, imgUrX = 150f, imgUrY = 800f; + const float textX = 200f, textY = 750f; + + // Ensure the source PDF exists + if (!File.Exists(inputPdfPath)) + { + Console.Error.WriteLine($"Source PDF not found: {inputPdfPath}"); + return; + } + + // Ensure the image file exists + if (!File.Exists(imagePath)) + { + Console.Error.WriteLine($"Image file not found: {imagePath}"); + return; + } + + // Load the PDF document (lifecycle rule: use using) + using (Document doc = new Document(inputPdfPath)) + { + // Initialize PdfFileMend with the loaded document (facade for adding content) + using (PdfFileMend mend = new PdfFileMend(doc)) + { + // ---- Add Image ------------------------------------------------- + bool imgResult = mend.AddImage(imagePath, 1, imgLlX, imgLlY, imgUrX, imgUrY); + LogOperation("AddImage", Path.GetFileName(imagePath), 1); + + // ---- Add Text -------------------------------------------------- + // FormattedText constructor expects System.Drawing.Color and a float font size. + FormattedText ft = new FormattedText( + textToAdd, + System.Drawing.Color.Red, + "Helvetica", + EncodingType.Winansi, + false, + 24f); + + // AddText overload that accepts a single page number. + bool txtResult = mend.AddText(ft, 1, textX, textY); + LogOperation("AddText", "FormattedText", 1); + } + + // Save the modified document (lifecycle rule: save inside using) + doc.Save(outputPdfPath); + } + + Console.WriteLine($"Processing completed. Output saved to '{outputPdfPath}'."); + } +} diff --git a/facades-texts-and-images/add-image-and-text-watermark-to-pdf.cs b/facades-texts-and-images/add-image-and-text-watermark-to-pdf.cs index 3679a7ed2..dc510eb49 100644 --- a/facades-texts-and-images/add-image-and-text-watermark-to-pdf.cs +++ b/facades-texts-and-images/add-image-and-text-watermark-to-pdf.cs @@ -1,66 +1,66 @@ using System; using System.IO; using Aspose.Pdf; +using Aspose.Pdf.Facades; using Aspose.Pdf.Text; -using Aspose.Pdf.Drawing; class Program { static void Main() { - const string inputPdf = "input.pdf"; - const string outputPdf = "watermarked.pdf"; - const string imagePath = "logo.png"; + const string inputPdf = "input.pdf"; + const string outputPdf = "watermarked.pdf"; + const string imagePath = "logo.png"; const string watermarkText = "CONFIDENTIAL"; - if (!File.Exists(inputPdf) || !File.Exists(imagePath)) + if (!File.Exists(inputPdf)) { - Console.Error.WriteLine("Missing input PDF or image file."); + Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); return; } - // Load the source PDF - using (Document doc = new Document(inputPdf)) + if (!File.Exists(imagePath)) { - // Iterate through all pages and add the image + text watermark - foreach (Page page in doc.Pages) - { - // ------------------------------------------------------------ - // 1. Add the image as a semi‑transparent background using ImageStamp - // ------------------------------------------------------------ - ImageStamp imgStamp = new ImageStamp(imagePath) - { - // Stretch the image to cover the whole page - Width = page.PageInfo.Width, - Height = page.PageInfo.Height, - // Make the image semi‑transparent (0 = fully transparent, 1 = opaque) - Opacity = 0.2f, - // Place it behind the page content - Background = true - }; - page.AddStamp(imgStamp); + Console.Error.WriteLine($"Watermark image not found: {imagePath}"); + return; + } - // ------------------------------------------------------------ - // 2. Add the text watermark on top of the image - // ------------------------------------------------------------ - TextFragment tf = new TextFragment(watermarkText) - { - // Center the text on the page using alignment properties - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center - }; - tf.TextState.Font = FontRepository.FindFont("Arial"); - tf.TextState.FontSize = 72; - tf.TextState.FontStyle = FontStyles.Bold; - // Gray with ~30% opacity (alpha = 77 out of 255) - tf.TextState.ForegroundColor = Color.FromArgb(77, 128, 128, 128); - // RenderingMode defaults to Fill, so no explicit setting needed - page.Paragraphs.Add(tf); - } + // Initialize the facade and bind the source PDF + PdfFileStamp fileStamp = new PdfFileStamp(); + fileStamp.BindPdf(inputPdf); - // Save the watermarked PDF - doc.Save(outputPdf); - Console.WriteLine($"Watermarked PDF saved to '{outputPdf}'."); - } + // Create a stamp that contains both an image and semi‑transparent text + Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp(); + + // Bind the image to the stamp + stamp.BindImage(imagePath); + + // Create formatted text (System.Drawing.Color is required by FormattedText) + FormattedText ft = new FormattedText( + watermarkText, // text + System.Drawing.Color.Red, // text color + "Helvetica", // font name + EncodingType.Winansi, // encoding + false, // embed font + 48); // font size + + // Bind the text to the same stamp + stamp.BindLogo(ft); + + // Position the stamp (center of the page, adjust as needed) + stamp.SetOrigin(200, 400); // X, Y coordinates + + // Make the stamp appear behind existing content and set transparency + stamp.IsBackground = true; + stamp.Opacity = 0.5f; // 50 % transparent + + // Add the stamp to all pages of the document + fileStamp.AddStamp(stamp); + + // Save the result + fileStamp.Save(outputPdf); + fileStamp.Close(); + + Console.WriteLine($"Watermarked PDF saved to '{outputPdf}'."); } -} +} \ No newline at end of file diff --git a/facades-texts-and-images/add-image-to-all-pdf-pages-dynamic-position.cs b/facades-texts-and-images/add-image-to-all-pdf-pages-dynamic-position.cs deleted file mode 100644 index 4159f66bb..000000000 --- a/facades-texts-and-images/add-image-to-all-pdf-pages-dynamic-position.cs +++ /dev/null @@ -1,84 +0,0 @@ -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 imagePath = "logo.png"; // image to place - const string outputPdf = "output.pdf"; // result PDF - - if (!File.Exists(inputPdf)) - { - Console.Error.WriteLine($"Source PDF not found: {inputPdf}"); - return; - } - if (!File.Exists(imagePath)) - { - Console.Error.WriteLine($"Image file not found: {imagePath}"); - return; - } - - // Load the PDF document (lifecycle rule: wrap in using) - using (Document doc = new Document(inputPdf)) - { - // Create the PdfFileMend facade bound to the loaded document - using (PdfFileMend mender = new PdfFileMend(doc)) - { - // Open the image stream once – it will be reused for all pages - using (FileStream imgStream = File.OpenRead(imagePath)) - { - // Iterate over all pages (Aspose.Pdf uses 1‑based indexing) - for (int pageNum = 1; pageNum <= doc.Pages.Count; pageNum++) - { - Page page = doc.Pages[pageNum]; - - // Retrieve page dimensions from the MediaBox (in points) - double pageLlx = page.MediaBox.LLX; - double pageLly = page.MediaBox.LLY; - double pageUrx = page.MediaBox.URX; - double pageUry = page.MediaBox.URY; - - double pageWidth = pageUrx - pageLlx; - double pageHeight = pageUry - pageLly; - - // Desired image size: 15 % of page width, keep aspect ratio - const double widthFactor = 0.15; - double imageWidth = pageWidth * widthFactor; - double imageHeight = imageWidth; // square placeholder; adjust as needed - - // Margin from page edges (5 % of page width) - double margin = pageWidth * 0.05; - - // Place image at bottom‑right corner - double lowerLeftX = pageUrx - margin - imageWidth; - double lowerLeftY = pageLly + margin; - double upperRightX = pageUrx - margin; - double upperRightY = lowerLeftY + imageHeight; - - // Add the image to the current page - // AddImage(Stream, int, float, float, float, float) - mender.AddImage( - imgStream, - pageNum, - (float)lowerLeftX, - (float)lowerLeftY, - (float)upperRightX, - (float)upperRightY); - - // Reset the stream position for the next iteration - imgStream.Position = 0; - } - } - - // Save the modified PDF (lifecycle rule: use Save) - mender.Save(outputPdf); - } - } - - Console.WriteLine($"Image placed on all pages. Output saved to '{outputPdf}'."); - } -} \ No newline at end of file diff --git a/facades-texts-and-images/add-image-to-each-pdf-page-dynamic-position.cs b/facades-texts-and-images/add-image-to-each-pdf-page-dynamic-position.cs new file mode 100644 index 000000000..b95cd8302 --- /dev/null +++ b/facades-texts-and-images/add-image-to-each-pdf-page-dynamic-position.cs @@ -0,0 +1,77 @@ +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 = "output.pdf"; // PDF with added images + const string imagePath = "logo.png"; // image to place + + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); + return; + } + if (!File.Exists(imagePath)) + { + Console.Error.WriteLine($"Image file not found: {imagePath}"); + return; + } + + // Load the PDF document (lifecycle rule: use using for disposal) + using (Document doc = new Document(inputPdf)) + { + // Initialize PdfFileMend facade on the loaded document + PdfFileMend mend = new PdfFileMend(doc); + + // Iterate through all pages (Aspose.Pdf uses 1‑based indexing) + for (int pageNum = 1; pageNum <= doc.Pages.Count; pageNum++) + { + Page page = doc.Pages[pageNum]; + + // Retrieve page dimensions (in points; 1 point = 1/72 inch) + double pageWidth = page.Rect.Width; + double pageHeight = page.Rect.Height; + + // Define desired image size as a fraction of the page size + // Here we use 20 % of the page width for both width and height + double imgWidth = pageWidth * 0.20; + double imgHeight = pageHeight * 0.20; + + // Define a margin from the page borders (e.g., 10 points) + const double margin = 10.0; + + // Calculate lower‑left and upper‑right coordinates so the image + // appears in the bottom‑right corner of the page + double lowerLeftX = pageWidth - imgWidth - margin; + double lowerLeftY = margin; + double upperRightX = pageWidth - margin; + double upperRightY = margin + imgHeight; + + // Add the image to the current page. + // The stream must be opened for each call because AddImage consumes it. + using (FileStream imgStream = File.OpenRead(imagePath)) + { + mend.AddImage( + imgStream, // image stream + pageNum, // target page number + (float)lowerLeftX, // lower‑left X + (float)lowerLeftY, // lower‑left Y + (float)upperRightX, // upper‑right X + (float)upperRightY // upper‑right Y + ); + } + } + + // Save the modified PDF (lifecycle rule: use Save(string)) + mend.Save(outputPdf); + mend.Close(); // optional but explicit + } + + Console.WriteLine($"Image placed on each page and saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-texts-and-images/add-image-to-pdf-get-memorystream.cs b/facades-texts-and-images/add-image-to-pdf-get-memorystream.cs deleted file mode 100644 index 82447cb42..000000000 --- a/facades-texts-and-images/add-image-to-pdf-get-memorystream.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.IO; -using System.Threading.Tasks; -using Aspose.Pdf.Facades; - -public static class PdfImageHelper -{ - /// - /// Adds an image to the first page of an existing PDF and returns the modified PDF as a . - /// The caller can write the stream to an HTTP response, a file, or any other destination. - /// - /// Full path to the source PDF. - /// Full path to the image that will be placed on the PDF. - /// A containing the modified PDF. The stream's position is set to 0. - public static async Task AddImageAndGetStreamAsync(string pdfFilePath, string imageFilePath) - { - if (string.IsNullOrEmpty(pdfFilePath)) - throw new ArgumentException("PDF file path is required.", nameof(pdfFilePath)); - if (string.IsNullOrEmpty(imageFilePath)) - throw new ArgumentException("Image file path is required.", nameof(imageFilePath)); - - if (!File.Exists(pdfFilePath)) - throw new FileNotFoundException("Source PDF not found.", pdfFilePath); - if (!File.Exists(imageFilePath)) - throw new FileNotFoundException("Image file not found.", imageFilePath); - - // PdfFileMend is a facade that can modify an existing PDF (add images, texts, etc.). - using (PdfFileMend pdfMend = new PdfFileMend()) - { - // Bind the existing PDF document. - pdfMend.BindPdf(pdfFilePath); - - // Add the image to page 1. - // Parameters: image path, page number (1‑based), lower‑left X, lower‑left Y, upper‑right X, upper‑right Y. - pdfMend.AddImage(imageFilePath, 1, 100f, 500f, 300f, 700f); - - // Prepare a memory stream to hold the modified PDF. - var pdfStream = new MemoryStream(); - pdfMend.Save(pdfStream); - pdfStream.Position = 0; // reset for reading - return pdfStream; // caller owns the stream - } - } -} - -// Added entry point to satisfy the compiler when the project is built as an executable. -public class Program -{ - public static async Task Main(string[] args) - { - // Simple demonstration of the helper. In a real web application you would write the - // returned stream directly to the HttpResponse. - if (args.Length < 2) - { - Console.WriteLine("Usage: "); - return; - } - - string pdfPath = args[0]; - string imagePath = args[1]; - - using MemoryStream modifiedPdf = await PdfImageHelper.AddImageAndGetStreamAsync(pdfPath, imagePath); - - // For console/demo purposes write the result to a file. - const string outputPath = "modified.pdf"; - using (FileStream file = new FileStream(outputPath, FileMode.Create, FileAccess.Write)) - { - await modifiedPdf.CopyToAsync(file); - } - - Console.WriteLine($"Modified PDF saved to {outputPath}"); - } -} diff --git a/facades-texts-and-images/add-image-to-pdf-page.cs b/facades-texts-and-images/add-image-to-pdf-page.cs index ee5c4df48..8bd7a656d 100644 --- a/facades-texts-and-images/add-image-to-pdf-page.cs +++ b/facades-texts-and-images/add-image-to-pdf-page.cs @@ -1,16 +1,15 @@ using System; using System.IO; -using Aspose.Pdf; using Aspose.Pdf.Facades; -public static class PdfHelper +public static class PdfImageHelper { /// - /// Adds an image to a specific page of a PDF document at the given rectangle coordinates. + /// Adds an image to a specific page of a PDF file at the given rectangle coordinates. /// - /// Path to the source PDF file. + /// Path to the source PDF. /// Path where the modified PDF will be saved. - /// Path to the image file to be added. + /// Path to the image file to insert. /// 1‑based page number where the image will be placed. /// X coordinate of the lower‑left corner of the image rectangle. /// Y coordinate of the lower‑left corner of the image rectangle. @@ -26,43 +25,82 @@ public static void AddImageToPdf( float upperRightX, float upperRightY) { - // Validate input arguments - if (string.IsNullOrWhiteSpace(inputPdfPath)) - throw new ArgumentException("Input PDF path is required.", nameof(inputPdfPath)); - if (string.IsNullOrWhiteSpace(outputPdfPath)) - throw new ArgumentException("Output PDF path is required.", nameof(outputPdfPath)); - if (string.IsNullOrWhiteSpace(imagePath)) - throw new ArgumentException("Image path is required.", nameof(imagePath)); + // Validate arguments (optional but helpful) if (!File.Exists(inputPdfPath)) - throw new FileNotFoundException("Input PDF not found.", inputPdfPath); + throw new FileNotFoundException($"Input PDF not found: {inputPdfPath}"); + if (!File.Exists(imagePath)) - throw new FileNotFoundException("Image file not found.", imagePath); - if (pageNumber < 1) - throw new ArgumentOutOfRangeException(nameof(pageNumber), "Page number must be 1 or greater."); + throw new FileNotFoundException($"Image file not found: {imagePath}"); - // Load the PDF document inside a using block for deterministic disposal. - using (Document doc = new Document(inputPdfPath)) + // PdfFileMend is a facade for adding images/text to existing PDFs. + // It implements IDisposable, so we wrap it in a using block. + using (PdfFileMend mender = new PdfFileMend()) { - // PdfFileMend works on the loaded Document instance. - using (PdfFileMend mend = new PdfFileMend(doc)) - { - // Add the image to the specified page and rectangle. - // The AddImage overload that accepts a file path is used. - mend.AddImage(imagePath, pageNumber, lowerLeftX, lowerLeftY, upperRightX, upperRightY); - } + // Bind the source PDF file. + mender.BindPdf(inputPdfPath); + + // Add the image to the specified page and rectangle. + // This uses the AddImage(string, int, float, float, float, float) overload. + bool success = mender.AddImage(imagePath, pageNumber, lowerLeftX, lowerLeftY, upperRightX, upperRightY); + if (!success) + throw new InvalidOperationException("Failed to add image to the PDF."); + + // Save the modified PDF to the output path. + mender.Save(outputPdfPath); - // Save the modified document to the desired output location. - doc.Save(outputPdfPath); + // Close the facade (optional; using will also call Dispose). + mender.Close(); } } } -// A minimal entry point is required for a console‑type project. public class Program { + /// + /// Entry point required for a console‑application build. Demonstrates the helper usage. + /// public static void Main(string[] args) { - // No operation – the class library can be used from other code. - // This stub satisfies the compiler's requirement for a static Main method. + // Expected arguments: + // 0: input PDF path + // 1: output PDF path + // 2: image file path + // 3: page number (1‑based) + // 4: lower‑left X + // 5: lower‑left Y + // 6: upper‑right X + // 7: upper‑right Y + if (args.Length < 8) + { + Console.WriteLine("Usage: "); + return; + } + + string inputPdf = args[0]; + string outputPdf = args[1]; + string imagePath = args[2]; + if (!int.TryParse(args[3], out int pageNumber)) + { + Console.WriteLine("Invalid page number."); + return; + } + if (!float.TryParse(args[4], out float llx) || + !float.TryParse(args[5], out float lly) || + !float.TryParse(args[6], out float urx) || + !float.TryParse(args[7], out float ury)) + { + Console.WriteLine("Invalid coordinate values."); + return; + } + + try + { + PdfImageHelper.AddImageToPdf(inputPdf, outputPdf, imagePath, pageNumber, llx, lly, urx, ury); + Console.WriteLine("Image added successfully."); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } } } diff --git a/facades-texts-and-images/add-image-to-pdf-using-pdffilemend.cs b/facades-texts-and-images/add-image-to-pdf-using-pdffilemend.cs new file mode 100644 index 000000000..2cfda985d --- /dev/null +++ b/facades-texts-and-images/add-image-to-pdf-using-pdffilemend.cs @@ -0,0 +1,47 @@ +using System; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; + const string outputPdf = "output.pdf"; + const string imagePath = "logo.png"; + + // Verify required files exist + if (!System.IO.File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); + return; + } + if (!System.IO.File.Exists(imagePath)) + { + Console.Error.WriteLine($"Image file not found: {imagePath}"); + return; + } + + // Create the PdfFileMend facade + PdfFileMend mend = new PdfFileMend(); + + try + { + // Bind the source PDF document + mend.BindPdf(inputPdf); + + // Example operation: add an image to page 1 + // Parameters: image file path, page number, lower‑left X, lower‑left Y, upper‑right X, upper‑right Y + mend.AddImage(imagePath, 1, 100f, 500f, 300f, 700f); + + // Save the modified PDF + mend.Save(outputPdf); + } + finally + { + // Ensure the facade is closed and resources are released + mend.Close(); + } + + Console.WriteLine($"Modified PDF saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-texts-and-images/add-image-to-pdf-with-format-validation.cs b/facades-texts-and-images/add-image-to-pdf-with-format-validation.cs new file mode 100644 index 000000000..25ac004e8 --- /dev/null +++ b/facades-texts-and-images/add-image-to-pdf-with-format-validation.cs @@ -0,0 +1,53 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + // Input PDF, output PDF and image to be added + const string inputPdfPath = "input.pdf"; + const string outputPdfPath = "output.pdf"; + const string imagePath = "picture.png"; + + // Verify that the source files exist + if (!File.Exists(inputPdfPath)) + { + Console.Error.WriteLine($"PDF file not found: {inputPdfPath}"); + return; + } + if (!File.Exists(imagePath)) + { + Console.Error.WriteLine($"Image file not found: {imagePath}"); + return; + } + + // Validate image format – only JPG, PNG, GIF, BMP, or TIFF are allowed + string ext = Path.GetExtension(imagePath).ToLowerInvariant(); + string[] allowedExtensions = { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tif", ".tiff" }; + if (Array.IndexOf(allowedExtensions, ext) < 0) + { + Console.Error.WriteLine($"Unsupported image format: {ext}"); + return; + } + + // Use PdfFileMend (Aspose.Pdf.Facades) to add the image to the PDF + PdfFileMend pdfMend = new PdfFileMend(); + pdfMend.BindPdf(inputPdfPath); // Load the PDF document + // Add the image to page 1; coordinates are lower‑left (10,10) and upper‑right (200,200) + bool success = pdfMend.AddImage(imagePath, 1, 10, 10, 200, 200); + if (!success) + { + Console.Error.WriteLine("Failed to add the image to the PDF."); + pdfMend.Close(); + return; + } + + // Save the modified PDF + pdfMend.Save(outputPdfPath); + pdfMend.Close(); + + Console.WriteLine($"Image successfully added. Output saved to '{outputPdfPath}'."); + } +} \ No newline at end of file diff --git a/facades-texts-and-images/add-image-to-pdf-with-pdffilemend.cs b/facades-texts-and-images/add-image-to-pdf-with-pdffilemend.cs deleted file mode 100644 index cc20b3d44..000000000 --- a/facades-texts-and-images/add-image-to-pdf-with-pdffilemend.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.IO; -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; - } - - PdfFileMend mend = null; - try - { - // Initialize the facade with the source PDF - mend = new PdfFileMend(); - mend.BindPdf(inputPath); - - // Example modification: add an image to page 1 - if (File.Exists(imagePath)) - { - // AddImage(string imageFile, int pageNumber, float llx, float lly, float urx, float ury) - mend.AddImage(imagePath, 1, 100, 500, 300, 800); - } - - // Persist the changes - mend.Save(outputPath); - } - finally - { - // Ensure the facade is closed even if an exception occurs - if (mend != null) - { - mend.Close(); - } - } - - Console.WriteLine($"Modified PDF saved to '{outputPath}'."); - } -} \ No newline at end of file diff --git a/facades-texts-and-images/add-image-verify-pdf-byte-size.cs b/facades-texts-and-images/add-image-verify-pdf-byte-size.cs new file mode 100644 index 000000000..e2d2ebd1a --- /dev/null +++ b/facades-texts-and-images/add-image-verify-pdf-byte-size.cs @@ -0,0 +1,114 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; +using NUnit.Framework; // Added to bring stub attributes into scope + +// Minimal NUnit stubs so the test project can compile without the real NUnit package. +namespace NUnit.Framework +{ + [AttributeUsage(AttributeTargets.Class)] + public sealed class TestFixtureAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Method)] + public sealed class TestAttribute : Attribute { } + + public static class Assert + { + public static void IsTrue(bool condition, string? message = null) + { + if (!condition) + throw new Exception(message ?? "Assert.IsTrue failed."); + } + + public static void Greater(int actual, int expected, string? message = null) + { + if (actual <= expected) + throw new Exception(message ?? $"Assert.Greater failed. Expected greater than {expected}, but was {actual}."); + } + } +} + +namespace AsposePdfTests +{ + [TestFixture] + public class PdfFileMendTests + { + // A tiny 1x1 pixel PNG (transparent) encoded in base64. + private static readonly byte[] SamplePng = Convert.FromBase64String( + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/5+BAQAE/wJ" + + "Z6VYAAAAASUVORK5CYII="); + + [Test] + public void AddingImage_IncreasesPdfByteSize() + { + // ------------------------------------------------------------ + // Step 1: Create a minimal PDF document (one blank page) + // ------------------------------------------------------------ + byte[] originalPdfBytes; + using (Document doc = new Document()) + { + // Add a single blank page + doc.Pages.Add(); + + // Save the document to a memory stream + using (MemoryStream originalStream = new MemoryStream()) + { + doc.Save(originalStream); + originalPdfBytes = originalStream.ToArray(); + } + } + + // Record the original size + int originalSize = originalPdfBytes.Length; + + // ------------------------------------------------------------ + // Step 2: Bind the PDF to PdfFileMend and add an image + // ------------------------------------------------------------ + // Bind the existing PDF from a memory stream + using (PdfFileMend pdfMend = new PdfFileMend()) + { + using (MemoryStream sourceStream = new MemoryStream(originalPdfBytes)) + { + pdfMend.BindPdf(sourceStream); + } + + // Add the sample PNG to page 1 at coordinates (10,10)-(100,100) + using (MemoryStream imageStream = new MemoryStream(SamplePng)) + { + bool added = pdfMend.AddImage(imageStream, 1, 10f, 10f, 100f, 100f); + Assert.IsTrue(added, "Image should be added successfully."); + } + + // ------------------------------------------------------------ + // Step 3: Save the modified PDF to a new memory stream + // ------------------------------------------------------------ + byte[] modifiedPdfBytes; + using (MemoryStream modifiedStream = new MemoryStream()) + { + pdfMend.Save(modifiedStream); + modifiedPdfBytes = modifiedStream.ToArray(); + } + + // Record the modified size + int modifiedSize = modifiedPdfBytes.Length; + + // ------------------------------------------------------------ + // Step 4: Verify that the PDF size increased after adding the image + // ------------------------------------------------------------ + Assert.Greater(modifiedSize, originalSize, + $"Modified PDF size ({modifiedSize} bytes) should be greater than original size ({originalSize} bytes)."); + } + } + } +} + +// Dummy entry point to satisfy the compiler when building as an executable. +public static class Program +{ + public static void Main(string[] args) + { + // No runtime logic required – tests are discovered and run by the test runner. + // This method exists solely to provide a valid entry point for the project. + } +} diff --git a/facades-texts-and-images/add-images-to-pdf-with-error-handling.cs b/facades-texts-and-images/add-images-to-pdf-with-error-handling.cs index 503e125f9..7a115a7df 100644 --- a/facades-texts-and-images/add-images-to-pdf-with-error-handling.cs +++ b/facades-texts-and-images/add-images-to-pdf-with-error-handling.cs @@ -6,51 +6,50 @@ class Program { static void Main() { - // Input and output PDF files + // Paths for the source PDF, the resulting PDF, and the images to add const string inputPdf = "input.pdf"; const string outputPdf = "output.pdf"; - - // List of image file paths to add string[] imagePaths = { "image1.jpg", "image2.png", "missing.jpg" }; - // Verify the source PDF exists + // Verify that the source PDF exists if (!File.Exists(inputPdf)) { - Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); + Console.Error.WriteLine($"Source PDF not found: {inputPdf}"); return; } - // Initialize PdfFileMend with source and destination files + // Initialize the PdfFileMend facade with input and output files PdfFileMend mend = new PdfFileMend(inputPdf, outputPdf); - // Target page and rectangle coordinates (lower‑left and upper‑right) - int targetPage = 1; - float lowerLeftX = 10f; - float lowerLeftY = 10f; - float upperRightX = 100f; - float upperRightY = 100f; - - // Process each image, handling any exceptions that occur + // Iterate over each image and attempt to add it to page 1 foreach (string imgPath in imagePaths) { try { - // Attempt to add the image; AddImage returns true on success - bool added = mend.AddImage(imgPath, targetPage, lowerLeftX, lowerLeftY, upperRightX, upperRightY); + // Ensure the image file exists before attempting to add it + if (!File.Exists(imgPath)) + { + throw new FileNotFoundException("Image file not found", imgPath); + } + + // Add the image to page 1 with specified rectangle coordinates + // (lowerLeftX, lowerLeftY) = (10, 10), (upperRightX, upperRightY) = (100, 100) + bool added = mend.AddImage(imgPath, 1, 10, 10, 100, 100); + + // If AddImage returns false, log the failure if (!added) { - // The method reported failure without throwing Console.Error.WriteLine($"AddImage returned false for: {imgPath}"); } } catch (Exception ex) { - // Log the problematic image file path and the exception message + // Log the problematic image path and the exception details Console.Error.WriteLine($"Error adding image '{imgPath}': {ex.Message}"); } } - // Finalize and write the output PDF + // Finalize and save the modified PDF mend.Close(); Console.WriteLine($"Processing complete. Output saved to '{outputPdf}'."); diff --git a/facades-texts-and-images/add-multi-line-text-block-page-3.cs b/facades-texts-and-images/add-multi-line-text-block-page-3.cs new file mode 100644 index 000000000..af6e5d340 --- /dev/null +++ b/facades-texts-and-images/add-multi-line-text-block-page-3.cs @@ -0,0 +1,62 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; +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; + } + + // Use PdfFileMend (a Facades class) to bind the existing PDF, + // modify it with core API objects, and save the result. + using (PdfFileMend mend = new PdfFileMend()) + { + // Bind the source PDF document. + mend.BindPdf(inputPath); + + // Access the underlying Document object. + Document doc = mend.Document; + + // Page indexing in Aspose.Pdf is 1‑based. + Page page3 = doc.Pages[3]; + + // Create a multi‑line text paragraph. + TextParagraph paragraph = new TextParagraph(); + + // Position the paragraph at the left margin. + // Rectangle(left, bottom, right, top) + paragraph.Rectangle = new Aspose.Pdf.Rectangle( + 0, // left (margin edge) + 0, // bottom + 200, // right (width of the text block) + page3.PageInfo.Height); // top (full page height) + + // Enable word wrapping (optional, based on needs). + paragraph.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords; + + // Append lines with custom line spacing (additional spacing after each line). + paragraph.AppendLine("First line of text", 5f); // 5 points extra spacing + paragraph.AppendLine("Second line of text", 10f); // 10 points extra spacing + paragraph.AppendLine("Third line of text", 0f); // default spacing + + // Append the paragraph to page three. + TextBuilder builder = new TextBuilder(page3); + builder.AppendParagraph(paragraph); + + // Save the modified PDF using the facade. + mend.Save(outputPath); + } + + Console.WriteLine($"Multi‑line text added to page 3 and saved as '{outputPath}'."); + } +} \ No newline at end of file diff --git a/facades-texts-and-images/add-multi-line-text-left-margin-page-3.cs b/facades-texts-and-images/add-multi-line-text-left-margin-page-3.cs deleted file mode 100644 index b759e346a..000000000 --- a/facades-texts-and-images/add-multi-line-text-left-margin-page-3.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.IO; -using Aspose.Pdf; -using Aspose.Pdf.Facades; -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 using the Facades API - using (PdfFileMend pdfMend = new PdfFileMend()) - { - pdfMend.BindPdf(inputPath); - - // Access the underlying Document - Document doc = pdfMend.Document; - - // Verify that page 3 exists (Aspose.Pdf uses 1‑based indexing) - if (doc.Pages.Count < 3) - { - Console.Error.WriteLine("The document has fewer than 3 pages."); - return; - } - - Page page = doc.Pages[3]; - - // Define a rectangle that occupies the left margin of the page - // (0,0) is lower‑left; use the full page height for the rectangle - double pageHeight = page.PageInfo.Height; - TextParagraph paragraph = new TextParagraph - { - // Left margin width of 150 units - Rectangle = new Aspose.Pdf.Rectangle(0, 0, 150, pageHeight) - }; - - // Enable word‑wrap within the rectangle - paragraph.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords; - - // Append multiple lines with custom line spacing (extra spacing after each line) - paragraph.AppendLine("First line of text", 5f); // 5 units extra spacing - paragraph.AppendLine("Second line with more spacing", 10f); // 10 units extra spacing - paragraph.AppendLine("Third line", 0f); // default spacing - - // Append the paragraph to page 3 - TextBuilder builder = new TextBuilder(page); - builder.AppendParagraph(paragraph); - - // Save the modified PDF using the Facades API - pdfMend.Save(outputPath); - } - - Console.WriteLine($"Modified PDF saved to '{outputPath}'."); - } -} \ No newline at end of file diff --git a/facades-texts-and-images/add-png-image-to-pdf-page.cs b/facades-texts-and-images/add-png-image-to-pdf-page.cs index 7e5090f7a..dc554d7a4 100644 --- a/facades-texts-and-images/add-png-image-to-pdf-page.cs +++ b/facades-texts-and-images/add-png-image-to-pdf-page.cs @@ -1,67 +1,42 @@ using System; -using System.Drawing; -using System.Drawing.Imaging; -using Aspose.Pdf; +using System.IO; using Aspose.Pdf.Facades; class Program { static void Main() { - // Paths for the PDF and PNG files used in the demo - const string inputPdfPath = "input.pdf"; - const string outputPdfPath = "output.pdf"; - const string pngImagePath = "image.png"; + const string inputPdf = "input.pdf"; + const string outputPdf = "output.pdf"; + const string imagePath = "image.png"; - // --------------------------------------------------------------------- - // 1. Create a minimal source PDF (2 pages) if it does not already exist. - // --------------------------------------------------------------------- - if (!System.IO.File.Exists(inputPdfPath)) + // Define image rectangle coordinates (lower‑left and upper‑right) + float lowerLeftX = 100f; + float lowerLeftY = 200f; + float upperRightX = 300f; + float upperRightY = 400f; + + if (!File.Exists(inputPdf)) { - using (Document seed = new Document()) - { - // Add two blank pages – page 2 is required for the image insertion. - seed.Pages.Add(); - seed.Pages.Add(); - seed.Save(inputPdfPath); - } + Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); + return; } - // --------------------------------------------------------------------- - // 2. Create a simple PNG image if it does not already exist. - // --------------------------------------------------------------------- - if (!System.IO.File.Exists(pngImagePath)) + if (!File.Exists(imagePath)) { - using (Bitmap bmp = new Bitmap(100, 100)) - { - using (Graphics g = Graphics.FromImage(bmp)) - { - g.Clear(System.Drawing.Color.Transparent); - using (Pen pen = new Pen(System.Drawing.Color.Blue, 5)) - { - g.DrawEllipse(pen, 10, 10, 80, 80); - } - } - bmp.Save(pngImagePath, ImageFormat.Png); - } + Console.Error.WriteLine($"Image file not found: {imagePath}"); + return; } - // Coordinates for the image rectangle on page 2 (lower‑left X/Y, upper‑right X/Y) - const float lowerLeftX = 100f; - const float lowerLeftY = 200f; - const float upperRightX = 300f; - const float upperRightY = 400f; - - // --------------------------------------------------------------------- - // 3. Bind the PDF, add the image, and save the result. - // --------------------------------------------------------------------- - PdfFileMend mend = new PdfFileMend(); - mend.BindPdf(inputPdfPath); - // Page numbers are 1‑based; we target page 2. - mend.AddImage(pngImagePath, 2, lowerLeftX, lowerLeftY, upperRightX, upperRightY); - mend.Save(outputPdfPath); - mend.Close(); + // Bind the PDF, add the PNG to page 2, and save the result + using (PdfFileMend mender = new PdfFileMend()) + { + mender.BindPdf(inputPdf); + mender.AddImage(imagePath, 2, lowerLeftX, lowerLeftY, upperRightX, upperRightY); + mender.Save(outputPdf); + mender.Close(); // optional, Dispose will also close + } - Console.WriteLine($"Image added to page 2 and saved as '{outputPdfPath}'."); + Console.WriteLine($"Image added to page 2 and saved as '{outputPdf}'."); } -} +} \ No newline at end of file diff --git a/facades-texts-and-images/add-promotional-text-multiple-pdf-pages.cs b/facades-texts-and-images/add-promotional-text-multiple-pdf-pages.cs deleted file mode 100644 index deebeeec1..000000000 --- a/facades-texts-and-images/add-promotional-text-multiple-pdf-pages.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.IO; -using Aspose.Pdf; -using Aspose.Pdf.Facades; -using Aspose.Pdf.Text; - -class Program -{ - static void Main() - { - const string inputPath = "input.pdf"; - const string outputPath = "output.pdf"; - const string promoText = "Special Offer: Get 20% off on all items!"; - - if (!File.Exists(inputPath)) - { - Console.Error.WriteLine($"Input file not found: {inputPath}"); - return; - } - - // Pages where the promotional message will be placed (1‑based indexing) - int[] targetPages = new int[] { 3, 5, 7 }; - - // Define the rectangle where the text will appear (lower‑left and upper‑right coordinates) - float lowerLeftX = 100f; // distance from left edge - float lowerLeftY = 700f; // distance from bottom edge - float upperRightX = 500f; // width of the text box - float upperRightY = 750f; // height of the text box - - // Create formatted text. Note: FormattedText uses System.Drawing.Color for the color parameter. - FormattedText ft = new FormattedText( - promoText, - System.Drawing.Color.Black, // text color - "Helvetica", // font name - EncodingType.Winansi, // encoding - false, // embed font? - 12); // font size - - // Use PdfFileMend to add the text to the specified pages. - using (PdfFileMend mend = new PdfFileMend()) - { - // Bind the source PDF. - mend.BindPdf(inputPath); - - // Add the promotional text to the selected pages. - // The method signature: - // AddText(FormattedText text, int[] pageNums, - // float lowerLeftX, float lowerLeftY, - // float upperRightX, float upperRightY) - mend.AddText(ft, targetPages, lowerLeftX, lowerLeftY, upperRightX, upperRightY); - - // Save the modified document. - mend.Save(outputPath); - } - - Console.WriteLine($"Promotional message added to pages 3, 5, and 7. Output saved to '{outputPath}'."); - } -} \ No newline at end of file diff --git a/facades-texts-and-images/add-promotional-text-to-specific-pdf-pages.cs b/facades-texts-and-images/add-promotional-text-to-specific-pdf-pages.cs new file mode 100644 index 000000000..9d079546d --- /dev/null +++ b/facades-texts-and-images/add-promotional-text-to-specific-pdf-pages.cs @@ -0,0 +1,44 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; // Facade API (PdfFileStamp, Stamp) +using Aspose.Pdf.Text; // FormattedText, EncodingType + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + const string promoText = "Special Offer: 20% OFF!"; + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Create formatted text for the promotional message. + // FormattedText constructor requires System.Drawing.Color for the text color. + FormattedText formatted = new FormattedText( + promoText, // text + System.Drawing.Color.Red, // text color + "Helvetica", // font name + EncodingType.Winansi, // encoding + false, // embed font? + 24); // font size + + // Create a stamp, bind the formatted text, and restrict it to pages 3, 5 and 7. + Stamp stamp = new Stamp(); + stamp.BindLogo(formatted); + stamp.Pages = new int[] { 3, 5, 7 }; // 1‑based page numbers + + // Apply the stamp to the PDF using PdfFileStamp. + using (PdfFileStamp fileStamp = new PdfFileStamp(inputPath, outputPath)) + { + fileStamp.AddStamp(stamp); + fileStamp.Close(); // finalize and write the output file + } + + Console.WriteLine($"Promotional message added to pages 3, 5, and 7. Saved as '{outputPath}'."); + } +} \ No newline at end of file diff --git a/facades-texts-and-images/add-text-at-coordinates-verify-position.cs b/facades-texts-and-images/add-text-at-coordinates-verify-position.cs new file mode 100644 index 000000000..f535f4a7c --- /dev/null +++ b/facades-texts-and-images/add-text-at-coordinates-verify-position.cs @@ -0,0 +1,133 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; +using Aspose.Pdf.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +// --------------------------------------------------------------------------- +// Minimal stubs for MSTest attributes and Assert when the MSTest package is not +// referenced. They are placed in the same namespace that the test code expects. +// --------------------------------------------------------------------------- +namespace Microsoft.VisualStudio.TestTools.UnitTesting +{ + [AttributeUsage(AttributeTargets.Class)] + public sealed class TestClassAttribute : Attribute { } + + [AttributeUsage(AttributeTargets.Method)] + public sealed class TestMethodAttribute : Attribute { } + + public static class Assert + { + public static void IsTrue(bool condition, string? message = null) + { + if (!condition) + throw new Exception(message ?? "Assert.IsTrue failed."); + } + } +} + +namespace AsposePdfFacadesTests +{ + [TestClass] + public class AddTextCoordinateTests + { + // Expected coordinates for the added text (in points; 1 inch = 72 points) + private const float ExpectedX = 100f; + private const float ExpectedY = 200f; + private const string TestString = "SampleText"; + + // Helper method to create a simple one‑page PDF document + private static Document CreateBlankDocument() + { + // Create a new PDF document and add a single blank page + Document doc = new Document(); + doc.Pages.Add(); + return doc; + } + + // Helper method to add text at a specific position using TextBuilder (core API) + private static void AddTextAtPosition(Document doc, int pageNumber, string text, float x, float y) + { + // Obtain the target page (Aspose.Pdf uses 1‑based indexing) + Page page = doc.Pages[pageNumber]; + + // Create a TextFragment with the desired string + TextFragment fragment = new TextFragment(text); + + // Set the lower‑left corner of the text (baseline position) + fragment.Position = new Position(x, y); + + // Use TextBuilder to append the fragment to the page + TextBuilder builder = new TextBuilder(page); + builder.AppendText(fragment); + } + + // Helper method to extract the first occurrence of a string and return its position + private static Position GetTextPosition(Document doc, int pageNumber, string searchText) + { + // Use TextFragmentAbsorber to locate the text on the specified page + TextFragmentAbsorber absorber = new TextFragmentAbsorber(searchText); + doc.Pages[pageNumber].Accept(absorber); + + // Ensure the text was found + if (absorber.TextFragments.Count == 0) + throw new InvalidOperationException($"Text \"{searchText}\" not found on page {pageNumber}."); + + // Return the Position of the first found fragment + return absorber.TextFragments[0].Position; + } + + [TestMethod] + public void VerifyAddedTextAppearsAtExpectedCoordinates() + { + // Create a temporary file path for the generated PDF + string tempPdfPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".pdf"); + + try + { + // ------------------------------------------------------------ + // 1. Create a blank PDF and add the test text at the expected coordinates + // ------------------------------------------------------------ + using (Document doc = CreateBlankDocument()) + { + AddTextAtPosition(doc, pageNumber: 1, text: TestString, x: ExpectedX, y: ExpectedY); + + // Save the document to a temporary file + doc.Save(tempPdfPath); + } + + // ------------------------------------------------------------ + // 2. Load the saved PDF and verify the text position + // ------------------------------------------------------------ + using (Document loadedDoc = new Document(tempPdfPath)) + { + Position actualPos = GetTextPosition(loadedDoc, pageNumber: 1, searchText: TestString); + + // Allow a small tolerance due to floating‑point rounding + const float tolerance = 0.01f; + + Assert.IsTrue(Math.Abs(actualPos.XIndent - ExpectedX) <= tolerance, + $"X coordinate mismatch. Expected: {ExpectedX}, Actual: {actualPos.XIndent}"); + + Assert.IsTrue(Math.Abs(actualPos.YIndent - ExpectedY) <= tolerance, + $"Y coordinate mismatch. Expected: {ExpectedY}, Actual: {actualPos.YIndent}"); + } + } + finally + { + // Clean up the temporary file + if (File.Exists(tempPdfPath)) + { + try { File.Delete(tempPdfPath); } catch { /* ignore cleanup errors */ } + } + } + } + } + + // Dummy entry point to satisfy the compiler when building as an executable. + public class Program + { + public static void Main() { } + } +} diff --git a/facades-texts-and-images/add-tiff-image-to-last-page-pdf.cs b/facades-texts-and-images/add-tiff-image-to-last-page-pdf.cs new file mode 100644 index 000000000..d0ffd6c74 --- /dev/null +++ b/facades-texts-and-images/add-tiff-image-to-last-page-pdf.cs @@ -0,0 +1,58 @@ +using System; +using System.IO; +using Aspose.Pdf; // Document class for page count +using Aspose.Pdf.Facades; // PdfFileMend facade + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; // Source PDF + const string tiffImage = "image.tiff"; // TIFF to embed + const string outputPdf = "output.pdf"; // Result PDF + + // Validate input files + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); + return; + } + if (!File.Exists(tiffImage)) + { + Console.Error.WriteLine($"TIFF image not found: {tiffImage}"); + return; + } + + // PdfFileMend adds images/text to existing PDFs without altering existing content + using (PdfFileMend mender = new PdfFileMend()) + { + // Load the PDF file into the facade + mender.BindPdf(inputPdf); + + // Determine the last page number (Aspose.Pdf uses 1‑based indexing) + int lastPage = mender.Document.Pages.Count; + + // Define the rectangle where the image will be placed on the page + // (lower‑left X/Y and upper‑right X/Y in points) + float lowerLeftX = 50f; + float lowerLeftY = 50f; + float upperRightX = 200f; + float upperRightY = 200f; + + // Add the TIFF image to the last page + bool success = mender.AddImage(tiffImage, lastPage, + lowerLeftX, lowerLeftY, + upperRightX, upperRightY); + if (!success) + { + Console.Error.WriteLine("Failed to add the image to the PDF."); + return; + } + + // Save the modified PDF to a new file + mender.Save(outputPdf); + } + + Console.WriteLine($"TIFF image added to the last page. Output saved as '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-texts-and-images/add-tiff-image-to-last-pdf-page.cs b/facades-texts-and-images/add-tiff-image-to-last-pdf-page.cs deleted file mode 100644 index 4af1c44f7..000000000 --- a/facades-texts-and-images/add-tiff-image-to-last-pdf-page.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.IO; -using Aspose.Pdf; -using Aspose.Pdf.Facades; - -class Program -{ - static void Main() - { - const string inputPdfPath = "input.pdf"; // source PDF - const string outputPdfPath = "output.pdf"; // PDF with added image - const string tiffImagePath = "image.tiff"; // TIFF to embed - - if (!File.Exists(inputPdfPath)) - { - Console.Error.WriteLine($"Input PDF not found: {inputPdfPath}"); - return; - } - - if (!File.Exists(tiffImagePath)) - { - Console.Error.WriteLine($"TIFF image not found: {tiffImagePath}"); - return; - } - - try - { - // Initialize the PdfFileMend facade - PdfFileMend mend = new PdfFileMend(); - - // Bind the source PDF file - mend.BindPdf(inputPdfPath); - - // Determine the last page number (Aspose.Pdf uses 1‑based indexing) - int lastPageNumber = mend.Document.Pages.Count; - - // Define image placement rectangle (example coordinates) - // lower‑left corner (x=50, y=50), upper‑right corner (x=300, y=300) - float lowerLeftX = 50f; - float lowerLeftY = 50f; - float upperRightX = 300f; - float upperRightY = 300f; - - // Add the TIFF image to the last page without affecting existing content - mend.AddImage(tiffImagePath, lastPageNumber, lowerLeftX, lowerLeftY, upperRightX, upperRightY); - - // Save the modified PDF - mend.Save(outputPdfPath); - - // Release resources - mend.Close(); - - Console.WriteLine($"TIFF image added to page {lastPageNumber}. Output saved to '{outputPdfPath}'."); - } - catch (Exception ex) - { - Console.Error.WriteLine($"Error: {ex.Message}"); - } - } -} \ No newline at end of file diff --git a/facades-texts-and-images/add-word-wrapped-footer-to-pdf.cs b/facades-texts-and-images/add-word-wrapped-footer-to-pdf.cs deleted file mode 100644 index 64dc657df..000000000 --- a/facades-texts-and-images/add-word-wrapped-footer-to-pdf.cs +++ /dev/null @@ -1,41 +0,0 @@ -using System; -using System.IO; -using Aspose.Pdf.Facades; -using Aspose.Pdf; - -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 footer. - // The constructor sets the text, color, font, encoding, embed flag and font size. - // Word‑by‑word wrapping is performed automatically when the footer is added. - FormattedText footer = new FormattedText( - "This is a sample footer that will wrap word by word across the page width.", - System.Drawing.Color.DarkGray, - "Helvetica", - EncodingType.Winansi, - false, - 9); - - // Use PdfFileStamp facade to bind the source PDF, add the footer, and save the result. - using (PdfFileStamp stamp = new PdfFileStamp()) - { - stamp.BindPdf(inputPath); // load the PDF - stamp.AddFooter(footer, 15f); // add footer with a 15‑point bottom margin - stamp.Save(outputPath); // write the output PDF - stamp.Close(); // finalize the operation - } - - Console.WriteLine($"Footer added successfully. Output saved to '{outputPath}'."); - } -} \ No newline at end of file diff --git a/facades-texts-and-images/add-wrapped-footer-to-pdf-pages.cs b/facades-texts-and-images/add-wrapped-footer-to-pdf-pages.cs new file mode 100644 index 000000000..07e2196b6 --- /dev/null +++ b/facades-texts-and-images/add-wrapped-footer-to-pdf-pages.cs @@ -0,0 +1,61 @@ +using System; +using System.IO; +using System.Drawing; // System.Drawing.Color for FormattedText +using System.Linq; // Enumerable.Range for page list +using Aspose.Pdf; // Document, PageInfo, etc. +using Aspose.Pdf.Facades; // FormattedText, EncodingType, PdfFileMend + +class Program +{ + static void Main() + { + const string inputPath = "input.pdf"; + const string outputPath = "output.pdf"; + const float bottomMargin = 20f; // Margin from the bottom edge of each page + const float footerHeight = 30f; // Approximate height of the footer area + + if (!File.Exists(inputPath)) + { + Console.Error.WriteLine($"Input file not found: {inputPath}"); + return; + } + + // Load the document to obtain page dimensions and count. + Document doc = new Document(inputPath); + int pageCount = doc.Pages.Count; + // Build an array containing every page number (1‑based). + int[] allPages = Enumerable.Range(1, pageCount).ToArray(); + + // Create the formatted text that will appear in the footer. + // Note: use System.Drawing.Color, not Aspose.Pdf.Color, and a float for font size. + Aspose.Pdf.Facades.FormattedText footer = new Aspose.Pdf.Facades.FormattedText( + "This is a sample footer text that should wrap word by word across the page width.", + System.Drawing.Color.Black, + "Helvetica", + Aspose.Pdf.Facades.EncodingType.Winansi, + false, + 10f); // font size + + // Determine the width of the first page (all pages share the same size in most PDFs). + float pageWidth = (float)doc.Pages[1].PageInfo.Width; + + // Use PdfFileMend (the Facade API) to add the footer to every page. + PdfFileMend mend = new PdfFileMend(); + mend.BindPdf(inputPath); + // AddText parameters: formatted text, page numbers, lower‑left X, lower‑left Y, upper‑right X, upper‑right Y. + // The rectangle is placed at the bottom of the page using the bottomMargin. + mend.AddText( + footer, + allPages, + 0f, // llx (left edge) + bottomMargin, // lly (bottom margin) + pageWidth, // urx (right edge) + bottomMargin + footerHeight); // ury (top of footer area) + + // Save the modified PDF. + mend.Save(outputPath); + mend.Close(); + + Console.WriteLine($"Footer added successfully. Output saved to '{outputPath}'."); + } +} diff --git a/facades-texts-and-images/async-add-image-to-pdf.cs b/facades-texts-and-images/async-add-image-to-pdf.cs index aec10d786..baec24012 100644 --- a/facades-texts-and-images/async-add-image-to-pdf.cs +++ b/facades-texts-and-images/async-add-image-to-pdf.cs @@ -2,96 +2,92 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -using Aspose.Pdf.Facades; // Facade API for PDF modifications +using Aspose.Pdf.Facades; // PdfFileMend resides here -namespace PdfAsyncModification +class PdfModifier { - public static class PdfMendExtensions + /// + /// Asynchronously adds an image to the first page of a PDF and saves the result. + /// All PdfFileMend operations are executed on a background thread via Task.Run + /// to avoid blocking the calling thread. + /// + /// Path to the source PDF file. + /// Path where the modified PDF will be saved. + /// Path to the image file to be added. + /// Optional cancellation token. + /// A task representing the asynchronous operation. + public static Task ModifyPdfAsync( + string inputPdfPath, + string outputPdfPath, + string imagePath, + CancellationToken cancellationToken = default) { - /// - /// Asynchronously adds an image to a PDF file using PdfFileMend. - /// The operation is executed on a background thread via Task.Run to avoid blocking the caller. - /// - /// Path to the source PDF file. - /// Path where the modified PDF will be saved. - /// Path to the image file to be added. - /// 1‑based page number where the image will be placed. - /// X coordinate (lower‑left) of the image rectangle. - /// Y coordinate (lower‑left) of the image rectangle. - /// Width of the image rectangle. - /// Height of the image rectangle. - /// Optional cancellation token. - /// A task representing the asynchronous operation. - public static Task AddImageAsync( - string inputPdfPath, - string outputPdfPath, - string imagePath, - int pageNumber, - float x, - float y, - float width, - float height, - CancellationToken cancellationToken = default) + // Validate arguments early + if (string.IsNullOrWhiteSpace(inputPdfPath)) + throw new ArgumentException("Input PDF path is required.", nameof(inputPdfPath)); + if (string.IsNullOrWhiteSpace(outputPdfPath)) + throw new ArgumentException("Output PDF path is required.", nameof(outputPdfPath)); + if (string.IsNullOrWhiteSpace(imagePath)) + throw new ArgumentException("Image path is required.", nameof(imagePath)); + + // Run the blocking PdfFileMend work on a thread‑pool thread + return Task.Run(() => { - // Validate arguments early to fail fast. - if (string.IsNullOrWhiteSpace(inputPdfPath)) - throw new ArgumentException("Input PDF path is required.", nameof(inputPdfPath)); - if (string.IsNullOrWhiteSpace(outputPdfPath)) - throw new ArgumentException("Output PDF path is required.", nameof(outputPdfPath)); - if (string.IsNullOrWhiteSpace(imagePath)) - throw new ArgumentException("Image path is required.", nameof(imagePath)); + // Throw if cancellation was requested before we start + cancellationToken.ThrowIfCancellationRequested(); + + // Ensure the PDF file exists if (!File.Exists(inputPdfPath)) throw new FileNotFoundException("Input PDF not found.", inputPdfPath); if (!File.Exists(imagePath)) throw new FileNotFoundException("Image file not found.", imagePath); - if (pageNumber < 1) - throw new ArgumentOutOfRangeException(nameof(pageNumber), "Page number must be 1 or greater."); - // Wrap the synchronous PdfFileMend work in Task.Run. - return Task.Run(() => + // Use a using block for deterministic disposal of the facade (lifecycle rule) + using (PdfFileMend mend = new PdfFileMend()) { - // Respect cancellation request before starting heavy work. - cancellationToken.ThrowIfCancellationRequested(); + // Bind the source PDF file + mend.BindPdf(inputPdfPath); - // PdfFileMend does not require a Document instance; it works directly on files. - // Use a using block to ensure resources are released promptly. - using (PdfFileMend pdfMend = new PdfFileMend()) + // Open the image stream (will be disposed automatically by the using below) + using (FileStream imgStream = File.OpenRead(imagePath)) { - // Bind the source PDF. - pdfMend.BindPdf(inputPdfPath); - - // Add the image to the specified page and rectangle. - // AddImage(string imagePath, int pageNumber, float x, float y, float width, float height) - pdfMend.AddImage(imagePath, pageNumber, x, y, width, height); - - // Save the modified PDF to the output location. - pdfMend.Save(outputPdfPath); + // Add the image to page 1 at the desired rectangle. + // Coordinates are in points (1/72 inch). Adjust as needed. + // The method returns a bool indicating success; we can ignore it or handle it. + bool added = mend.AddImage(imgStream, 1, 10f, 10f, 100f, 100f); + if (!added) + throw new InvalidOperationException("Failed to add image to PDF."); } - // Throw if cancellation was requested during the operation. - cancellationToken.ThrowIfCancellationRequested(); - }, cancellationToken); - } + // Save the modified PDF to the output path + mend.Save(outputPdfPath); + + // Close releases any internal resources (optional because of using) + mend.Close(); + } + }, cancellationToken); } - // Simple entry point to satisfy the compiler for a console‑style project. - // The method is async so callers can await asynchronous PDF work if they wish. - public class Program + // Example usage + static async Task Main(string[] args) { - public static async Task Main(string[] args) + // Example file paths – replace with real paths as needed + const string inputPdf = "sample_input.pdf"; + const string outputPdf = "sample_output.pdf"; + const string imageFile = "logo.png"; + + try + { + await ModifyPdfAsync(inputPdf, outputPdf, imageFile); + Console.WriteLine($"PDF modified and saved to '{outputPdf}'."); + } + catch (OperationCanceledException) + { + Console.WriteLine("Operation was cancelled."); + } + catch (Exception ex) { - // No mandatory execution logic – the library can be used via the - // PdfMendExtensions.AddImageAsync method from other code. - // Example (commented out) of how to call the async method: - // await PdfMendExtensions.AddImageAsync( - // "source.pdf", - // "modified.pdf", - // "logo.png", - // pageNumber: 1, - // x: 100, - // y: 500, - // width: 200, - // height: 100); + Console.Error.WriteLine($"Error: {ex.Message}"); } } -} +} \ No newline at end of file diff --git a/facades-texts-and-images/batch-add-company-logo-to-pdfs.cs b/facades-texts-and-images/batch-add-company-logo-to-pdfs.cs new file mode 100644 index 000000000..353283fa9 --- /dev/null +++ b/facades-texts-and-images/batch-add-company-logo-to-pdfs.cs @@ -0,0 +1,68 @@ +using System; +using System.IO; +using System.Linq; +using Aspose.Pdf; +using Aspose.Pdf.Facades; + +class BatchAddLogo +{ + static void Main() + { + // Folder containing the PDFs to process + const string inputFolder = @"C:\PdfInput"; + // Folder where the processed PDFs will be saved + const string outputFolder = @"C:\PdfOutput"; + // Path to the company logo PNG + const string logoPath = @"C:\Assets\company_logo.png"; + + // Ensure output folder exists + Directory.CreateDirectory(outputFolder); + + // Process each PDF file in the input folder + foreach (string pdfFile in Directory.GetFiles(inputFolder, "*.pdf")) + { + // Bind the PDF, add the logo, and save the result + using (PdfFileMend mend = new PdfFileMend()) + { + // Load the PDF into the facade + mend.BindPdf(pdfFile); + + // Determine the pages to which the logo will be added (all pages) + int pageCount = mend.Document.Pages.Count; // 1‑based indexing + int[] allPages = Enumerable.Range(1, pageCount).ToArray(); + + // Retrieve page dimensions from the first page (assumes uniform size) + Page firstPage = mend.Document.Pages[1]; + float pageWidth = (float)firstPage.PageInfo.Width; // explicit cast from double to float + float pageHeight = (float)firstPage.PageInfo.Height; // explicit cast from double to float + + // Desired logo size (adjust as needed) + const float logoWidth = 100f; // points + const float logoHeight = 50f; // points + + // Position the logo at the top‑right corner with a 10‑point margin + float lowerLeftX = pageWidth - logoWidth - 10f; + float lowerLeftY = pageHeight - logoHeight - 10f; + float upperRightX = lowerLeftX + logoWidth; + float upperRightY = lowerLeftY + logoHeight; + + // Add the logo image to all pages + using (FileStream imgStream = File.OpenRead(logoPath)) + { + mend.AddImage(imgStream, allPages, + lowerLeftX, lowerLeftY, + upperRightX, upperRightY); + } + + // Save the modified PDF to the output folder + string outputPath = Path.Combine(outputFolder, + Path.GetFileNameWithoutExtension(pdfFile) + "_logo.pdf"); + mend.Save(outputPath); + } + + Console.WriteLine($"Processed: {Path.GetFileName(pdfFile)}"); + } + + Console.WriteLine("Batch processing completed."); + } +} diff --git a/facades-texts-and-images/batch-add-logo-to-pdf-pages.cs b/facades-texts-and-images/batch-add-logo-to-pdf-pages.cs deleted file mode 100644 index cb940e8b6..000000000 --- a/facades-texts-and-images/batch-add-logo-to-pdf-pages.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using System.IO; -using Aspose.Pdf; -using Aspose.Pdf.Facades; - -class BatchAddLogo -{ - static void Main(string[] args) - { - // Input folder containing PDFs - string inputFolder = @"C:\InputPdfs"; - // Output folder for processed PDFs - string outputFolder = @"C:\OutputPdfs"; - // Path to the company logo PNG - string logoPath = @"C:\Resources\logo.png"; - - // Ensure output folder exists - Directory.CreateDirectory(outputFolder); - - // Process each PDF file in the input folder - foreach (string pdfFile in Directory.GetFiles(inputFolder, "*.pdf")) - { - // Load the PDF to obtain page dimensions - using (Document doc = new Document(pdfFile)) - { - int pageCount = doc.Pages.Count; - - // Initialize PdfFileMend facade - using (PdfFileMend mender = new PdfFileMend()) - { - // Bind the source PDF - mender.BindPdf(pdfFile); - - // Define logo size and margin (in points) – use float because AddImage expects float - const float logoWidth = 100f; // adjust as needed - const float logoHeight = 50f; // adjust as needed - const float margin = 10f; // distance from top/right edges - - // Add the logo to each page at the top‑right corner - for (int i = 1; i <= pageCount; i++) - { - Page page = doc.Pages[i]; - // Convert page dimensions to float - float pageWidth = (float)page.PageInfo.Width; - float pageHeight = (float)page.PageInfo.Height; - - // Calculate lower‑left coordinates for the logo using float arithmetic - float llx = pageWidth - logoWidth - margin; - float lly = pageHeight - logoHeight - margin; - float urx = llx + logoWidth; - float ury = lly + logoHeight; - - // Open the logo image stream for each addition - using (FileStream imgStream = File.OpenRead(logoPath)) - { - // AddImage expects float coordinates - mender.AddImage(imgStream, i, llx, lly, urx, ury); - } - } - - // Determine output file path - string outputPath = Path.Combine( - outputFolder, - Path.GetFileNameWithoutExtension(pdfFile) + "_logo.pdf"); - - // Save the modified PDF - mender.Save(outputPath); - } - } - - Console.WriteLine($"Processed: {Path.GetFileName(pdfFile)}"); - } - - Console.WriteLine("Batch processing completed."); - } -} diff --git a/facades-texts-and-images/batch-extract-images-from-pdfs.cs b/facades-texts-and-images/batch-extract-images-from-pdfs.cs index 31eb4d834..4e827fdc3 100644 --- a/facades-texts-and-images/batch-extract-images-from-pdfs.cs +++ b/facades-texts-and-images/batch-extract-images-from-pdfs.cs @@ -1,86 +1,65 @@ using System; using System.IO; -using Aspose.Pdf.Facades; -using System.Runtime.Versioning; +using Aspose.Pdf.Facades; // PdfExtractor resides here +using System.Drawing.Imaging; // ImageFormat for specifying output format -class Program +class BatchImageExtractor { static void Main() { - // Folder containing the source PDFs - const string inputFolder = "InputPdfs"; - // Temporary folder for single‑page PDFs - const string tempFolder = "TempPages"; + // Folder containing PDF files to process + const string inputFolder = @"C:\InputPdfs"; // Folder where extracted images will be saved - const string outputFolder = "ExtractedImages"; + const string outputFolder = @"C:\ExtractedImages"; - // Ensure all required directories exist - Directory.CreateDirectory(inputFolder); - Directory.CreateDirectory(tempFolder); + // Ensure the output directory exists Directory.CreateDirectory(outputFolder); - // Process each PDF file in the input folder - foreach (string pdfPath in Directory.GetFiles(inputFolder, "*.pdf")) - { - string pdfBaseName = Path.GetFileNameWithoutExtension(pdfPath); - - // Split the PDF into single‑page PDFs. - // %NUM% in the template is replaced with the page number (1‑based). - string pageTemplate = Path.Combine(tempFolder, $"{pdfBaseName}_page%NUM%.pdf"); - var editor = new PdfFileEditor(); - editor.SplitToPages(pdfPath, pageTemplate); + // Get all PDF files in the input folder + string[] pdfFiles = Directory.GetFiles(inputFolder, "*.pdf"); - // Iterate over the generated single‑page PDFs. - foreach (string pagePdf in Directory.GetFiles(tempFolder, $"{pdfBaseName}_page*.pdf")) + foreach (string pdfPath in pdfFiles) + { + // Use PdfExtractor inside a using block for deterministic disposal + using (PdfExtractor extractor = new PdfExtractor()) { - int pageNumber = ExtractPageNumber(pagePdf); // 1‑based page index + // Bind the current PDF file + extractor.BindPdf(pdfPath); + + // Total pages in the document (Aspose.Pdf uses 1‑based indexing) + int pageCount = extractor.Document.Pages.Count; - // Extract all images from the current page PDF. - using (PdfExtractor extractor = new PdfExtractor()) + // Iterate through each page to keep track of the page number + for (int pageNum = 1; pageNum <= pageCount; pageNum++) { - extractor.BindPdf(pagePdf); + // Restrict extraction to a single page + extractor.StartPage = pageNum; + extractor.EndPage = pageNum; + + // Extract images from the specified page extractor.ExtractImage(); - int imageIndex = 1; + int imageIndex = 1; // Reset image counter for each page + + // Retrieve all images found on this page while (extractor.HasNextImage()) { - // Build the output file name: _page_img.png - string outFile = Path.Combine( - outputFolder, - $"{pdfBaseName}_page{pageNumber}_img{imageIndex}.png"); + // Build a file name that includes the original PDF name, + // page number, and image index (e.g., Sample_page3_img2.png) + string outputFileName = $"{Path.GetFileNameWithoutExtension(pdfPath)}_page{pageNum}_img{imageIndex}.png"; + string outputPath = Path.Combine(outputFolder, outputFileName); + + // Save the image as PNG (any ImageFormat supported by System.Drawing.Imaging can be used) + extractor.GetNextImage(outputPath, ImageFormat.Png); - // Get the image as a memory stream (platform‑agnostic) and write it to disk. - using (MemoryStream imgStream = new MemoryStream()) - { - extractor.GetNextImage(imgStream); - // Reset position before writing. - imgStream.Position = 0; - using (FileStream fs = new FileStream(outFile, FileMode.Create, FileAccess.Write)) - { - imgStream.CopyTo(fs); - } - } imageIndex++; } } - - // Clean up the temporary single‑page PDF. - File.Delete(pagePdf); } - } - } - // Helper to parse the page number from a file name like "doc_page3.pdf" - static int ExtractPageNumber(string filePath) - { - string fileName = Path.GetFileNameWithoutExtension(filePath); - int marker = fileName.LastIndexOf("_page", StringComparison.OrdinalIgnoreCase); - if (marker >= 0) - { - string numberPart = fileName.Substring(marker + 5); - if (int.TryParse(numberPart, out int page)) - return page; + Console.WriteLine($"Images extracted from: {Path.GetFileName(pdfPath)}"); } - return 0; // fallback if parsing fails + + Console.WriteLine("Batch extraction completed."); } -} +} \ No newline at end of file diff --git a/facades-texts-and-images/configure-word-wrapping-bywords-add-long-text.cs b/facades-texts-and-images/configure-word-wrapping-bywords-add-long-text.cs new file mode 100644 index 000000000..ad11deee5 --- /dev/null +++ b/facades-texts-and-images/configure-word-wrapping-bywords-add-long-text.cs @@ -0,0 +1,53 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; +using Aspose.Pdf.Text; + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; + const string outputPdf = "output.pdf"; + + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"File not found: {inputPdf}"); + return; + } + + // Load the existing PDF document + using (Document doc = new Document(inputPdf)) + { + // Initialize the PdfFileMend facade on the loaded document + PdfFileMend mend = new PdfFileMend(doc); + + // Enable word wrapping and set the algorithm to wrap by whole words + mend.IsWordWrap = true; + mend.WrapMode = WordWrapMode.ByWords; // Aspose.Pdf.Facades.WordWrapMode + + // Long text that exceeds the desired width + string longText = "The quick brown fox jumps over the lazy dog. " + + "This sentence is deliberately long to exceed the defined width and test word wrapping by words."; + + // Create FormattedText (color uses System.Drawing.Color) + FormattedText formatted = new FormattedText( + longText, + System.Drawing.Color.Black, + "Helvetica", + EncodingType.Winansi, + false, + 12); + + // Add the text to page 1 at position (100, 700) + // Word wrapping will be applied according to the settings above + mend.AddText(formatted, 1, 100, 700); + + // Save the modified PDF + doc.Save(outputPdf); + } + + Console.WriteLine($"Word‑wrapped PDF saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-texts-and-images/configure-word-wrapping-bywords.cs b/facades-texts-and-images/configure-word-wrapping-bywords.cs deleted file mode 100644 index 6cb36966c..000000000 --- a/facades-texts-and-images/configure-word-wrapping-bywords.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.IO; -using System.Drawing; // System.Drawing.Color required by FormattedText -using Aspose.Pdf; -using Aspose.Pdf.Facades; // PdfFileMend, FormattedText, EncodingType - -class Program -{ - static void Main() - { - const string outputPath = "wrapped_text.pdf"; - - // Create a new PDF document with a single blank page - using (Document doc = new Document()) - { - doc.Pages.Add(); // page index will be 1 (1‑based) - - // Initialize the PdfFileMend facade on the document - using (PdfFileMend mend = new PdfFileMend()) - { - mend.BindPdf(doc); // bind the facade to the document - mend.IsWordWrap = true; // enable word‑wrap handling - mend.WrapMode = WordWrapMode.ByWords; // set wrap algorithm to ByWords - - // Prepare the text to be added. The constructor requires System.Drawing.Color. - Aspose.Pdf.Facades.FormattedText ft = new Aspose.Pdf.Facades.FormattedText( - "This is a very long line of text that should automatically wrap by complete words within the defined rectangle width.", - System.Drawing.Color.Black, // text color (System.Drawing.Color) - "Helvetica", // font name - Aspose.Pdf.Facades.EncodingType.Winansi, // encoding - false, // embed font flag - 12f); // font size (float) - - // Add the text to page 1. - // Parameters: FormattedText, pageNumber, lowerLeftX, lowerLeftY, width, height - // Width defines the bounding box for wrapping; height can be 0 if not needed. - mend.AddText(ft, 1, 100f, 500f, 200f, 0f); - - // Save the modified document to the output file - mend.Save(outputPath); - } - } - - Console.WriteLine($"PDF saved to '{outputPath}'."); - } -} diff --git a/facades-texts-and-images/extract-images-from-pdf-pages-2-5.cs b/facades-texts-and-images/extract-images-from-pdf-pages-2-5.cs deleted file mode 100644 index 6e8af757d..000000000 --- a/facades-texts-and-images/extract-images-from-pdf-pages-2-5.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.IO; -using Aspose.Pdf.Facades; - -class Program -{ - static void Main() - { - const string inputPdf = "input.pdf"; - - // Verify the source PDF exists - if (!File.Exists(inputPdf)) - { - Console.Error.WriteLine($"File not found: {inputPdf}"); - return; - } - - // Create a unique temporary folder for the extracted images - string tempDir = Path.Combine(Path.GetTempPath(), - "ExtractedImages_" + Guid.NewGuid().ToString("N")); - Directory.CreateDirectory(tempDir); - Console.WriteLine($"Images will be saved to: {tempDir}"); - - // Extract images from pages 2 through 5 using PdfExtractor - using (PdfExtractor extractor = new PdfExtractor()) - { - extractor.BindPdf(inputPdf); // Load the PDF - extractor.StartPage = 2; // First page to process (1‑based) - extractor.EndPage = 5; // Last page to process - extractor.ExtractImage(); // Prepare image extraction - - int imageIndex = 1; - while (extractor.HasNextImage()) - { - // Save each image as a JPEG file in the temporary folder - string outputPath = Path.Combine(tempDir, $"image_{imageIndex}.jpg"); - extractor.GetNextImage(outputPath); - Console.WriteLine($"Saved image {imageIndex} → {outputPath}"); - imageIndex++; - } - } - } -} \ No newline at end of file diff --git a/facades-texts-and-images/extract-images-from-pdf-pages.cs b/facades-texts-and-images/extract-images-from-pdf-pages.cs new file mode 100644 index 000000000..84de529dc --- /dev/null +++ b/facades-texts-and-images/extract-images-from-pdf-pages.cs @@ -0,0 +1,47 @@ +using System; +using System.IO; +using System.Drawing.Imaging; // for ImageFormat +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; + + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input file not found: {inputPdf}"); + return; + } + + // Create a temporary folder for extracted images + string tempFolder = Path.Combine(Path.GetTempPath(), "AsposeExtractedImages"); + Directory.CreateDirectory(tempFolder); + + // Use PdfExtractor (facade) to extract images from pages 2‑5 + using (PdfExtractor extractor = new PdfExtractor()) + { + // Bind the source PDF + extractor.BindPdf(inputPdf); + + // Define the page range (Aspose.Pdf uses 1‑based indexing) + extractor.StartPage = 2; + extractor.EndPage = 5; + + // Prepare for image extraction + extractor.ExtractImage(); + + int imageIndex = 1; + while (extractor.HasNextImage()) + { + // Save each image as PNG in the temporary folder + string outputPath = Path.Combine(tempFolder, $"image-{imageIndex}.png"); + extractor.GetNextImage(outputPath, ImageFormat.Png); + imageIndex++; + } + } + + Console.WriteLine($"Images extracted to: {tempFolder}"); + } +} \ No newline at end of file diff --git a/facades-texts-and-images/extract-images-from-pdf-to-png.cs b/facades-texts-and-images/extract-images-from-pdf-to-png.cs index f3fc5d5ef..d6d81edab 100644 --- a/facades-texts-and-images/extract-images-from-pdf-to-png.cs +++ b/facades-texts-and-images/extract-images-from-pdf-to-png.cs @@ -1,51 +1,47 @@ using System; using System.IO; -using Aspose.Pdf.Facades; // PdfExtractor resides here -using System.Drawing.Imaging; // ImageFormat for PNG +using System.Drawing.Imaging; +using Aspose.Pdf.Facades; class Program { static void Main() { - const string inputPdf = "input.pdf"; - const string outputDir = "ExtractedImages"; + const string inputPdfPath = "input.pdf"; + const string outputFolder = "ExtractedImages"; - // Verify source PDF exists - if (!File.Exists(inputPdf)) + if (!File.Exists(inputPdfPath)) { - Console.Error.WriteLine($"File not found: {inputPdf}"); + Console.Error.WriteLine($"Input file not found: {inputPdfPath}"); return; } - // Ensure output folder exists - Directory.CreateDirectory(outputDir); + // Ensure the output directory exists + Directory.CreateDirectory(outputFolder); - // PdfExtractor implements IDisposable – use using for deterministic cleanup + // Use PdfExtractor (which implements IDisposable) inside a using block using (PdfExtractor extractor = new PdfExtractor()) { - // Bind the PDF file to the extractor - extractor.BindPdf(inputPdf); + // Bind the source PDF file + extractor.BindPdf(inputPdfPath); - // Prepare extractor to retrieve images + // Extract images from the PDF extractor.ExtractImage(); int imageIndex = 1; - // Iterate over all extracted images + // Iterate through all extracted images while (extractor.HasNextImage()) { - string outPath = Path.Combine(outputDir, $"image-{imageIndex}.png"); + // Build the output file name (PNG format) + string outputFile = Path.Combine(outputFolder, $"image-{imageIndex}.png"); - // Save the current image as PNG; GetNextImage returns true on success - bool saved = extractor.GetNextImage(outPath, ImageFormat.Png); - if (!saved) - { - Console.Error.WriteLine($"Failed to extract image #{imageIndex}"); - } + // Save the current image as PNG + extractor.GetNextImage(outputFile, ImageFormat.Png); imageIndex++; } } - Console.WriteLine("All images have been extracted."); + Console.WriteLine("Image extraction completed."); } } \ No newline at end of file diff --git a/facades-texts-and-images/index.json b/facades-texts-and-images/index.json index 0253aadfa..9950bb226 100644 --- a/facades-texts-and-images/index.json +++ b/facades-texts-and-images/index.json @@ -1,206 +1,200 @@ { "category": "facades-texts-and-images", - "nuget_version": "26.7.0", - "last_updated": "2026-07-18T01:14:53Z", + "nuget_version": "26.8.0", + "last_updated": "2026-08-20T08:06:00Z", "examples": { "add-png-image-to-pdf-page": { - "title": "Add PNG Image to PDF Page Using PdfFileMend", + "title": "Add PNG Image to Specific PDF Page using PdfFileMend", "filename": "add-png-image-to-pdf-page.cs", - "description": "Demonstrates how to bind an existing PDF with PdfFileMend, insert a PNG image onto page two at specific coordinates, and save the modified document.", + "description": "Demonstrates how to bind an existing PDF with PdfFileMend, insert a PNG image onto page two at defined coordinates, and save the modified document.", "tags": [ "pdf", "image", "Aspose.Pdf", "PdfFileMend", - "add-image" + "C#" ], "apis_used": [ "Aspose.Pdf.Facades.PdfFileMend", "Aspose.Pdf.Facades.PdfFileMend.BindPdf", "Aspose.Pdf.Facades.PdfFileMend.AddImage", "Aspose.Pdf.Facades.PdfFileMend.Save", - "Aspose.Pdf.Document", - "Aspose.Pdf.Document.Pages.Add", - "Aspose.Pdf.Document.Save" + "Aspose.Pdf.Facades.PdfFileMend.Close" ], "difficulty": "beginner", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "replace-jpeg-with-bmp-using-replaceimage": { - "title": "Replace JPEG with Higher‑Resolution BMP Using ReplaceImage", - "filename": "replace-jpeg-with-bmp-using-replaceimage.cs", - "description": "Demonstrates how to create a PDF with an embedded JPEG, generate a higher‑resolution BMP in memory, and replace the original image on the first page using Aspose.Pdf.Facades.PdfContentEditor.ReplaceImage.", + "replace-jpeg-with-bmp-first-page": { + "title": "Replace JPEG with High‑Resolution BMP on First PDF Page", + "filename": "replace-jpeg-with-bmp-first-page.cs", + "description": "Demonstrates how to replace the first image on page one of a PDF with a higher‑resolution BMP using Aspose.Pdf's PdfContentEditor.", "tags": [ + "replace-image", "pdf", - "image-replacement", "bmp", - "jpeg", - "aspose-pdf" + "aspose-pdf", + "content-editor" ], "apis_used": [ "Aspose.Pdf.Document", - "Aspose.Pdf.Page", - "Aspose.Pdf.Image", "Aspose.Pdf.Facades.PdfContentEditor", "Aspose.Pdf.Facades.PdfContentEditor.BindPdf", - "Aspose.Pdf.Facades.PdfContentEditor.ReplaceImage" + "Aspose.Pdf.Facades.PdfContentEditor.ReplaceImage", + "Aspose.Pdf.Document.Save" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, "overlay-semi-transparent-gif-on-pdf": { - "title": "Overlay Semi-Transparent GIF onto PDF Image", + "title": "Overlay Semi-Transparent GIF on PDF", "filename": "overlay-semi-transparent-gif-on-pdf.cs", - "description": "Demonstrates how to overlay a semi‑transparent GIF onto an existing PDF page that already contains a PNG, using CompositingParameters with BlendMode.Normal.", + "description": "Demonstrates how to place a semi‑transparent GIF over an existing PNG in a PDF using CompositingParameters with the PdfFileMend facade.", "tags": [ - "gif", "overlay", + "gif", "pdf", "compositing", - "facade" + "aspose-pdf" ], "apis_used": [ - "Aspose.Pdf.Facades.PdfFileMend", - "Aspose.Pdf.Facades.CompositingParameters", - "Aspose.Pdf.Facades.BlendMode", - "Aspose.Pdf.Facades.PdfFileMend.AddImage", - "Aspose.Pdf.Facades.PdfFileMend.BindPdf", - "Aspose.Pdf.Facades.PdfFileMend.Save" + "PdfFileMend", + "PdfFileMend.BindPdf", + "PdfFileMend.AddImage", + "CompositingParameters", + "BlendMode" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "add-word-wrapped-footer-to-pdf": { + "add-wrapped-footer-to-pdf-pages": { "title": "Add Word‑by‑Word Wrapped Footer to PDF Pages", - "filename": "add-word-wrapped-footer-to-pdf.cs", - "description": "Shows how to add a formatted text footer that automatically wraps word‑by‑word across the page width using Aspose.Pdf.Facades.", + "filename": "add-wrapped-footer-to-pdf-pages.cs", + "description": "Shows how to use Aspose.Pdf Facade API to add a formatted footer that wraps word‑by‑word across the page width on every PDF page.", "tags": [ "footer", "formatted-text", - "word-wrapping", + "pdf", "Aspose.Pdf", - "PdfFileStamp" + "word-wrap" ], "apis_used": [ - "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Document", + "Aspose.Pdf.PageInfo", "Aspose.Pdf.Facades.FormattedText", - "Aspose.Pdf.Facades.PdfFileStamp.BindPdf", - "Aspose.Pdf.Facades.PdfFileStamp.AddFooter", - "Aspose.Pdf.Facades.PdfFileStamp.Save" + "Aspose.Pdf.Facades.PdfFileMend", + "PdfFileMend.AddText", + "PdfFileMend.Save" ], - "difficulty": "beginner", - "generated_at": "2026-07-18T01:14:53Z", + "difficulty": "intermediate", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "add-promotional-text-multiple-pdf-pages": { - "title": "Add Promotional Text to Multiple PDF Pages", - "filename": "add-promotional-text-multiple-pdf-pages.cs", - "description": "Demonstrates inserting the same promotional text on pages 3, 5, and 7 of a PDF using PdfFileMend.AddText with an array of page numbers.", + "add-promotional-text-to-specific-pdf-pages": { + "title": "Add Promotional Text to Specific PDF Pages", + "filename": "add-promotional-text-to-specific-pdf-pages.cs", + "description": "Shows how to insert the same promotional message on pages 3, 5, and 7 of a PDF using Aspose.Pdf's Facade API with AddStamp.", "tags": [ "pdf", + "watermark", "text", - "add-text", - "multiple-pages", - "Aspose.Pdf" + "facade", + "stamp" ], "apis_used": [ - "Aspose.Pdf.Facades.PdfFileMend", - "Aspose.Pdf.Facades.PdfFileMend.BindPdf", - "Aspose.Pdf.Facades.PdfFileMend.AddText", - "Aspose.Pdf.Facades.PdfFileMend.Save", - "Aspose.Pdf.Text.FormattedText" + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Text.FormattedText", + "Aspose.Pdf.Text.EncodingType", + "Aspose.Pdf.Facades.Stamp.BindLogo", + "Aspose.Pdf.Facades.PdfFileStamp.AddStamp" ], - "difficulty": "beginner", - "generated_at": "2026-07-18T01:14:53Z", + "difficulty": "intermediate", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "add-multi-line-text-left-margin-page-3": { - "title": "Add Multi‑Line Text with Custom Line Spacing to Left Margin of Page 3", - "filename": "add-multi-line-text-left-margin-page-3.cs", - "description": "Demonstrates how to insert a multi‑line text block with custom line spacing into the left margin of the third page of a PDF using the Aspose.Pdf Facades API.", + "add-multi-line-text-block-page-3": { + "title": "Add Multi‑Line Text Block with Custom Line Spacing to Page 3", + "filename": "add-multi-line-text-block-page-3.cs", + "description": "Demonstrates how to use the PdfFileMend facade to bind an existing PDF, create a multi‑line TextParagraph with custom line spacing, and place it at the left margin of the third page.", "tags": [ "text", - "margin", - "line-spacing", "pdf", - "facades" + "facade", + "line-spacing", + "aspnet" ], "apis_used": [ "Aspose.Pdf.Facades.PdfFileMend", - "Aspose.Pdf.Facades.PdfFileMend.BindPdf", - "Aspose.Pdf.Facades.PdfFileMend.Save", "Aspose.Pdf.Document", "Aspose.Pdf.Page", "Aspose.Pdf.Text.TextParagraph", - "Aspose.Pdf.Text.TextBuilder", - "Aspose.Pdf.Text.TextFormattingOptions" + "Aspose.Pdf.Text.TextFormattingOptions", + "Aspose.Pdf.Facades.TextBuilder" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, "add-image-and-text-watermark-to-pdf": { - "title": "Add Image and Text Watermark to PDF Pages", + "title": "Add Image and Semi‑Transparent Text Watermark to PDF", "filename": "add-image-and-text-watermark-to-pdf.cs", - "description": "Demonstrates how to overlay a semi‑transparent image and centered text as a watermark on each page of a PDF using Aspose.Pdf.", + "description": "Demonstrates how to combine an image and semi‑transparent text into a single stamp and apply it as a watermark on all pages of a PDF using Aspose.Pdf.", "tags": [ "watermark", "image", "text", "pdf", - "aspose" + "Aspose.Pdf" ], "apis_used": [ - "Aspose.Pdf.Document", - "Aspose.Pdf.Page", - "Aspose.Pdf.ImageStamp", - "Aspose.Pdf.Text.TextFragment", - "Aspose.Pdf.Text.FontRepository", - "Aspose.Pdf.Drawing.Color", - "Aspose.Pdf.PageInfo", - "Aspose.Pdf.Document.Save" + "Aspose.Pdf.Facades.PdfFileStamp", + "Aspose.Pdf.Facades.Stamp", + "Aspose.Pdf.Text.FormattedText", + "Stamp.BindImage", + "Stamp.BindLogo", + "Stamp.SetOrigin", + "PdfFileStamp.AddStamp" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, "add-background-png-to-all-pdf-pages": { "title": "Add Background PNG to All PDF Pages", "filename": "add-background-png-to-all-pdf-pages.cs", - "description": "Demonstrates how to overlay a PNG image as a full‑page background on every page of a PDF using the PdfFileMend facade.", + "description": "Shows how to load a PDF, retrieve each page's dimensions, and overlay a PNG image as a background on every page using Aspose.Pdf.Facades.", "tags": [ "pdf", "background-image", - "addimage", - "aspose.pdf", + "add-image", + "Aspose.Pdf", "facade" ], "apis_used": [ - "Aspose.Pdf.Facades.PdfFileMend", + "Aspose.Pdf.Document", + "Aspose.Pdf.Page.Rect", "Aspose.Pdf.Facades.PdfFileMend.BindPdf", "Aspose.Pdf.Facades.PdfFileMend.AddImage", "Aspose.Pdf.Facades.PdfFileMend.Save", - "Aspose.Pdf.Facades.PdfFileMend.Close", - "Aspose.Pdf.Document.Pages", - "Aspose.Pdf.Page.Rect" + "Aspose.Pdf.Facades.PdfFileMend.Close" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "add-header-image-to-pdfs": { - "title": "Add Header Image to PDFs", - "filename": "add-header-image-to-pdfs.cs", - "description": "Shows how to attach a header image to each page of multiple PDF documents and save the modified files using Aspose.Pdf.Facades.", + "add-header-image-to-pdf-documents": { + "title": "Add Header Image to PDF Documents", + "filename": "add-header-image-to-pdf-documents.cs", + "description": "Shows how to insert a header image into one or more PDF files using Aspose.Pdf.Facades.PdfFileStamp in a console application.", "tags": [ "pdf", "header", "image", - "aspose", - "facade" + "Aspose.Pdf", + "command-line" ], "apis_used": [ "Aspose.Pdf.Facades.PdfFileStamp", @@ -210,22 +204,21 @@ "Aspose.Pdf.Facades.PdfFileStamp.Close" ], "difficulty": "beginner", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "batch-add-logo-to-pdf-pages": { - "title": "Batch Add Logo to PDF Pages", - "filename": "batch-add-logo-to-pdf-pages.cs", - "description": "Shows how to iterate through a folder of PDF files and overlay a PNG company logo at the top‑right corner of each page using Aspose.Pdf.", + "batch-add-company-logo-to-pdfs": { + "title": "Batch Add Company Logo to PDFs", + "filename": "batch-add-company-logo-to-pdfs.cs", + "description": "Shows how to process all PDF files in a folder and overlay a PNG company logo at the top‑right corner of each page using Aspose.Pdf.Facades.", "tags": [ "pdf", "logo", - "batch", + "batch-processing", "image", "Aspose.Pdf" ], "apis_used": [ - "Aspose.Pdf.Document", "Aspose.Pdf.Facades.PdfFileMend", "Aspose.Pdf.Facades.PdfFileMend.BindPdf", "Aspose.Pdf.Facades.PdfFileMend.AddImage", @@ -233,96 +226,85 @@ "Aspose.Pdf.Page" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "insert-png-signature-image-every-pdf-page": { + "insert-png-signature-image-on-every-pdf-page": { "title": "Insert PNG Signature Image on Every PDF Page", - "filename": "insert-png-signature-image-every-pdf-page.cs", - "description": "Shows how to use PdfFileMend to add a PNG signature image to the bottom‑left corner of each page in a PDF document.", + "filename": "insert-png-signature-image-on-every-pdf-page.cs", + "description": "Demonstrates how to use PdfFileMend to add a PNG signature image to the bottom‑left corner of each page in a PDF and save the modified document.", "tags": [ "pdf", - "signature", "image", + "signature", "add-image", - "Aspose.Pdf" + "facade" ], "apis_used": [ - "Aspose.Pdf.Document", "Aspose.Pdf.Facades.PdfFileMend", "Aspose.Pdf.Facades.PdfFileMend.BindPdf", "Aspose.Pdf.Facades.PdfFileMend.AddImage", - "Aspose.Pdf.Facades.PdfFileMend.Save" + "Aspose.Pdf.Facades.PdfFileMend.Save", + "Aspose.Pdf.Facades.PdfFileMend.Document" ], - "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "difficulty": "beginner", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "add-tiff-image-to-last-pdf-page": { - "title": "Add TIFF Image to Last Page of PDF with PdfFileMend", - "filename": "add-tiff-image-to-last-pdf-page.cs", - "description": "Demonstrates using PdfFileMend to bind an existing PDF, determine its last page, and embed a TIFF image onto that page without altering the existing content.", + "add-tiff-image-to-last-page-pdf": { + "title": "Add TIFF Image to Last Page of PDF using PdfFileMend", + "filename": "add-tiff-image-to-last-page-pdf.cs", + "description": "Demonstrates how to use Aspose.Pdf.Facades.PdfFileMend to embed a TIFF image onto the final page of an existing PDF without altering the original content.", "tags": [ - "PdfFileMend", - "AddImage", - "TIFF", - "last-page", - "Aspose.Pdf" + "pdf", + "tiff", + "image", + "pdffilemend", + "aspose-pdf" ], "apis_used": [ "Aspose.Pdf.Facades.PdfFileMend", "Aspose.Pdf.Facades.PdfFileMend.BindPdf", "Aspose.Pdf.Facades.PdfFileMend.AddImage", "Aspose.Pdf.Facades.PdfFileMend.Save", - "Aspose.Pdf.Facades.PdfFileMend.Close", "Aspose.Pdf.Document.Pages.Count" ], "difficulty": "beginner", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "add-image-to-all-pdf-pages-dynamic-position": { - "title": "Add Image to All PDF Pages with Dynamic Positioning", - "filename": "add-image-to-all-pdf-pages-dynamic-position.cs", - "description": "Demonstrates loading a PDF, calculating each page's dimensions, and placing an image at the bottom‑right corner of every page using the PdfFileMend facade.", + "add-image-to-each-pdf-page-dynamic-position": { + "title": "Add Image to Each PDF Page with Dynamic Positioning", + "filename": "add-image-to-each-pdf-page-dynamic-position.cs", + "description": "Loads a PDF, calculates each page's dimensions, and places a PNG image in the bottom‑right corner of every page using the PdfFileMend facade.", "tags": [ "pdf", "image", - "coordinates", + "positioning", "Aspose.Pdf", "facade" ], "apis_used": [ "Aspose.Pdf.Document", - "Aspose.Pdf.Facades.PdfFileMend", "Aspose.Pdf.Page", + "Aspose.Pdf.Facades.PdfFileMend", "Aspose.Pdf.Facades.PdfFileMend.AddImage", "Aspose.Pdf.Facades.PdfFileMend.Save" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "validate-image-format-before-calling-addimage-to-ensure-only-jpg-png-gif-bmp-or-tiff-files-are-used": { - "title": "Validate Image Format Before Calling Addimage To Ensure Only Jpg Png Gif Bmp Or Tiff Files Are Used", - "filename": "validate-image-format-before-calling-addimage-to-ensure-only-jpg-png-gif-bmp-or-tiff-files-are-used.cs", - "description": "", - "tags": [], - "apis_used": [], - "difficulty": "", - "generated_at": "2026-07-18T01:14:53Z", - "status": "verified" - }, - "add-image-to-pdf-with-pdffilemend": { - "title": "Add Image to PDF Using PdfFileMend with Try‑Finally", - "filename": "add-image-to-pdf-with-pdffilemend.cs", - "description": "Demonstrates how to bind a PDF, add an image stamp to a page, save the modified document, and guarantee resource cleanup with a try‑finally block that calls Close().", + "add-image-to-pdf-with-format-validation": { + "title": "Add Image to PDF with Format Validation", + "filename": "add-image-to-pdf-with-format-validation.cs", + "description": "Demonstrates how to validate an image's file format and then add the image to a PDF page using Aspose.Pdf.Facades.", "tags": [ "pdf", "image", - "aspose-pdf", - "pdf-modification", - "resource-management" + "validation", + "Aspose", + "add-image" ], "apis_used": [ "PdfFileMend", @@ -332,141 +314,147 @@ "PdfFileMend.Close" ], "difficulty": "beginner", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "add-images-to-pdf-with-error-handling": { - "title": "Add Images to PDF with Error Handling", - "filename": "add-images-to-pdf-with-error-handling.cs", - "description": "Demonstrates how to insert multiple images into a PDF using Aspose.Pdf's PdfFileMend class while catching and logging any exceptions that occur for individual image files.", + "add-image-to-pdf-using-pdffilemend": { + "title": "Add Image to PDF Using PdfFileMend with Try‑Finally", + "filename": "add-image-to-pdf-using-pdffilemend.cs", + "description": "Demonstrates how to bind a PDF, insert an image on a page, save the result, and guarantee that PdfFileMend is closed using a try‑finally block.", "tags": [ "pdf", "image", - "error-handling", "Aspose.Pdf", - "PdfFileMend" + "PdfFileMend", + "resource‑cleanup" ], "apis_used": [ "Aspose.Pdf.Facades.PdfFileMend", + "Aspose.Pdf.Facades.PdfFileMend.BindPdf", "Aspose.Pdf.Facades.PdfFileMend.AddImage", + "Aspose.Pdf.Facades.PdfFileMend.Save", "Aspose.Pdf.Facades.PdfFileMend.Close" ], - "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "difficulty": "beginner", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "add-image-and-text-audit-pdf": { - "title": "Add Image and Text to PDF with Audit Logging", - "filename": "add-image-and-text-audit-pdf.cs", - "description": "Demonstrates how to insert an image and a text annotation into a PDF using Aspose.Pdf facades while logging each operation with timestamps for audit purposes.", + "add-images-to-pdf-with-error-handling": { + "title": "Add Images to PDF with Error Handling", + "filename": "add-images-to-pdf-with-error-handling.cs", + "description": "Demonstrates how to insert multiple images into a PDF using Aspose.Pdf's PdfFileMend facade while handling missing files and AddImage failures gracefully.", "tags": [ "pdf", "image", - "text", - "audit", - "aspose" + "error-handling", + "Aspose.Pdf", + "facade" ], "apis_used": [ - "Aspose.Pdf.Document", - "Aspose.Pdf.Facades.PdfFileMend", - "Aspose.Pdf.Facades.PdfFileMend.AddImage", - "Aspose.Pdf.Facades.PdfContentEditor", - "Aspose.Pdf.Facades.PdfContentEditor.CreateText" + "PdfFileMend", + "PdfFileMend.AddImage", + "PdfFileMend.Close" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "configure-word-wrapping-bywords": { - "title": "Configure Word Wrapping ByWords and Add Wrapped Text", - "filename": "configure-word-wrapping-bywords.cs", - "description": "Demonstrates enabling word‑wrap, setting the wrap mode to ByWords, and adding a long paragraph that automatically wraps within a defined rectangle using the PdfFileMend facade.", + "add-image-and-text-to-pdf-with-audit-logging": { + "title": "Add Image and Text to PDF with Audit Logging", + "filename": "add-image-and-text-to-pdf-with-audit-logging.cs", + "description": "Loads a PDF, adds an image and a formatted text watermark to page 1, logs each AddImage and AddText operation with timestamp, page number and file name, then saves the modified document.", "tags": [ - "word-wrap", - "text-wrapping", "pdf", - "Aspose.Pdf", - "PdfFileMend" + "image", + "text", + "audit", + "facade" ], "apis_used": [ "Aspose.Pdf.Document", "Aspose.Pdf.Facades.PdfFileMend", + "Aspose.Pdf.Facades.PdfFileMend.AddImage", + "Aspose.Pdf.Facades.PdfFileMend.AddText", "Aspose.Pdf.Facades.FormattedText", - "PdfFileMend.BindPdf", - "PdfFileMend.AddText", - "PdfFileMend.Save" + "Aspose.Pdf.Facades.EncodingType" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "add-image-to-pdf-page": { - "title": "Add Image to Specific PDF Page", - "filename": "add-image-to-pdf-page.cs", - "description": "Shows how to insert an image onto a chosen PDF page at given rectangle coordinates using Aspose.Pdf's PdfFileMend facade.", + "configure-word-wrapping-bywords-add-long-text": { + "title": "Configure Word Wrapping ByWords and Add Long Text to PDF", + "filename": "configure-word-wrapping-bywords-add-long-text.cs", + "description": "The example shows how to enable word wrapping on a PDF using PdfFileMend, set the wrap mode to ByWords, and add a long paragraph that automatically wraps within the defined width.", "tags": [ - "image", - "pdf", - "Aspose", - "add-image", - "coordinates" + "word-wrapping", + "pdf-text", + "Aspose.Pdf", + "PdfFileMend", + "FormattedText" ], "apis_used": [ "Aspose.Pdf.Document", "Aspose.Pdf.Facades.PdfFileMend", - "Aspose.Pdf.Facades.PdfFileMend.AddImage", + "Aspose.Pdf.Facades.PdfFileMend.IsWordWrap", + "Aspose.Pdf.Facades.PdfFileMend.WrapMode", + "Aspose.Pdf.Facades.WordWrapMode", + "Aspose.Pdf.Text.FormattedText", + "Aspose.Pdf.Facades.PdfFileMend.AddText", "Aspose.Pdf.Document.Save" ], - "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "difficulty": "beginner", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "add-image-to-pdf-get-memorystream": { - "title": "Add Image to PDF and Return MemoryStream", - "filename": "add-image-to-pdf-get-memorystream.cs", - "description": "Shows how to bind an existing PDF with Aspose.Pdf.Facades.PdfFileMend, add an image to the first page, and return the modified document as a MemoryStream ready for an HTTP response.", + "add-image-to-pdf-page": { + "title": "Add Image to Specific PDF Page", + "filename": "add-image-to-pdf-page.cs", + "description": "Shows how to use Aspose.Pdf.Facades to insert an image onto a chosen page of a PDF at given rectangle coordinates via a reusable helper method.", "tags": [ "pdf", "image", - "memorystream", - "aspose", - "facade" + "add-image", + "aspose-pdf", + "facades" ], "apis_used": [ "Aspose.Pdf.Facades.PdfFileMend", "Aspose.Pdf.Facades.PdfFileMend.BindPdf", "Aspose.Pdf.Facades.PdfFileMend.AddImage", - "Aspose.Pdf.Facades.PdfFileMend.Save" + "Aspose.Pdf.Facades.PdfFileMend.Save", + "Aspose.Pdf.Facades.PdfFileMend.Close" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, "async-add-image-to-pdf": { - "title": "Asynchronously Add Image to PDF with PdfFileMend", + "title": "Asynchronously Add Image to PDF Using PdfFileMend", "filename": "async-add-image-to-pdf.cs", - "description": "Shows how to add an image to a specific page of a PDF file asynchronously by wrapping the synchronous PdfFileMend operations in Task.Run, including argument validation and cancellation support.", + "description": "Demonstrates how to modify a PDF on a background thread by adding an image to the first page with Aspose.Pdf's PdfFileMend, wrapped in Task.Run for non‑blocking execution.", "tags": [ - "pdf", "async", + "pdf", "image", - "Aspose.Pdf", - "PdfFileMend" + "Aspose", + "csharp" ], "apis_used": [ - "PdfFileMend", - "PdfFileMend.BindPdf", - "PdfFileMend.AddImage", - "PdfFileMend.Save" + "Aspose.Pdf.Facades.PdfFileMend", + "Aspose.Pdf.Facades.PdfFileMend.BindPdf", + "Aspose.Pdf.Facades.PdfFileMend.AddImage", + "Aspose.Pdf.Facades.PdfFileMend.Save", + "Aspose.Pdf.Facades.PdfFileMend.Close" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, "extract-images-from-pdf-to-png": { - "title": "Extract Images from PDF to PNG", + "title": "Extract Images from PDF to PNG using PdfExtractor", "filename": "extract-images-from-pdf-to-png.cs", - "description": "Shows how to use Aspose.Pdf.Facades.PdfExtractor to extract every image from a PDF document and save each one as an individual PNG file.", + "description": "Demonstrates how to use Aspose.Pdf's PdfExtractor to extract all images from a PDF document and save each as an individual PNG file.", "tags": [ "pdf", "image-extraction", @@ -475,29 +463,29 @@ "csharp" ], "apis_used": [ - "Aspose.Pdf.Facades.PdfExtractor", + "PdfExtractor", "PdfExtractor.BindPdf", "PdfExtractor.ExtractImage", "PdfExtractor.HasNextImage", "PdfExtractor.GetNextImage" ], "difficulty": "beginner", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "extract-images-from-pdf-pages-2-5": { - "title": "Extract Images from PDF Pages 2‑5", - "filename": "extract-images-from-pdf-pages-2-5.cs", - "description": "Shows how to extract all images from a specific page range in a PDF using Aspose.Pdf.Facades.PdfExtractor and save them to a temporary directory.", + "extract-images-from-pdf-pages": { + "title": "Extract Images from Specific PDF Pages", + "filename": "extract-images-from-pdf-pages.cs", + "description": "Shows how to use Aspose.Pdf.Facades.PdfExtractor to extract all images from pages 2‑5 of a PDF and save them as PNG files in a temporary directory.", "tags": [ "pdf", "image-extraction", - "aspose-pdf", - "page-range", - "temporary-directory" + "aspose", + "csharp", + "facade" ], "apis_used": [ - "Aspose.Pdf.Facades.PdfExtractor", + "PdfExtractor", "PdfExtractor.BindPdf", "PdfExtractor.StartPage", "PdfExtractor.EndPage", @@ -505,14 +493,14 @@ "PdfExtractor.HasNextImage", "PdfExtractor.GetNextImage" ], - "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "difficulty": "beginner", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, "batch-extract-images-from-pdfs": { - "title": "Batch Extract Images from PDFs with Page‑Based Naming", + "title": "Batch Extract Images from PDFs with Page and Index Naming", "filename": "batch-extract-images-from-pdfs.cs", - "description": "The example splits each PDF into single‑page files, extracts all images from each page, and saves them as PNG files named with the original PDF name, page number, and image index.", + "description": "Shows how to process multiple PDF files, extract images from each page using Aspose.Pdf.Facades.PdfExtractor, and save them with filenames that contain the original PDF name, page number, and image index.", "tags": [ "pdf", "image-extraction", @@ -521,103 +509,130 @@ "csharp" ], "apis_used": [ - "Aspose.Pdf.Facades.PdfFileEditor.SplitToPages", - "Aspose.Pdf.Facades.PdfExtractor.BindPdf", - "Aspose.Pdf.Facades.PdfExtractor.ExtractImage", - "Aspose.Pdf.Facades.PdfExtractor.HasNextImage", - "Aspose.Pdf.Facades.PdfExtractor.GetNextImage" + "Aspose.Pdf.Facades.PdfExtractor", + "PdfExtractor.BindPdf", + "PdfExtractor.StartPage", + "PdfExtractor.EndPage", + "PdfExtractor.ExtractImage", + "PdfExtractor.HasNextImage", + "PdfExtractor.GetNextImage", + "PdfExtractor.Document" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, "remove-image-from-pdf-page": { - "title": "Remove Image from PDF Page using Aspose.Pdf", + "title": "Remove Image from Specific PDF Page", "filename": "remove-image-from-pdf-page.cs", - "description": "Demonstrates how to delete a specific image identified by its object ID from a given page of a PDF document using Aspose.Pdf's PdfContentEditor.", + "description": "Demonstrates how to delete a particular image identified by its object ID from page four of a PDF using Aspose.Pdf's PdfContentEditor.", "tags": [ "pdf", - "image-removal", + "image", + "remove", "aspose", - "csharp", - "facade" + "csharp" ], "apis_used": [ - "Aspose.Pdf.Facades.PdfContentEditor", - "Aspose.Pdf.Facades.PdfContentEditor.BindPdf", - "Aspose.Pdf.Facades.PdfContentEditor.DeleteImage", - "Aspose.Pdf.Facades.PdfContentEditor.Save" + "PdfContentEditor", + "PdfContentEditor.BindPdf", + "PdfContentEditor.DeleteImage", + "PdfContentEditor.Save" ], "difficulty": "beginner", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, "remove-all-images-from-pdf": { - "title": "Remove All Images from a PDF", + "title": "Remove All Images from PDF", "filename": "remove-all-images-from-pdf.cs", - "description": "Shows how to load a PDF, delete every image on all pages using Aspose.Pdf.Facades, and save the modified document to a new file.", + "description": "Shows how to delete every image in a PDF using Aspose.Pdf's PdfContentEditor facade and save the modified document to a new file.", "tags": [ "pdf", "image-removal", - "aspose.pdf", + "Aspose.Pdf", "facade", "csharp" ], "apis_used": [ "Aspose.Pdf.Facades.PdfContentEditor", - "Aspose.Pdf.Facades.PdfContentEditor.BindPdf", - "Aspose.Pdf.Facades.PdfContentEditor.DeleteImage", - "Aspose.Pdf.Facades.PdfContentEditor.Save" + "PdfContentEditor.BindPdf", + "PdfContentEditor.DeleteImage", + "PdfContentEditor.Save" ], "difficulty": "beginner", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "replace-lowres-images-with-highres-png": { + "replace-low-res-images-with-high-res-pngs": { "title": "Replace Low-Resolution Images with High-Resolution PNGs in PDF", - "filename": "replace-lowres-images-with-highres-png.cs", - "description": "Shows how to iterate through PDF pages and replace each embedded image with a high‑resolution PNG using Aspose.Pdf's PdfContentEditor.", + "filename": "replace-low-res-images-with-high-res-pngs.cs", + "description": "Demonstrates how to iterate through each page of a PDF, detect embedded images, and replace low‑resolution images with corresponding high‑resolution PNG files using Aspose.Pdf facades.", "tags": [ "pdf", "image-replacement", "high-resolution", - "aspose.pdf", - "c#" + "Aspose.Pdf", + "facade" ], "apis_used": [ "Aspose.Pdf.Document", "Aspose.Pdf.Facades.PdfContentEditor", - "Aspose.Pdf.Facades.PdfContentEditor.BindPdf", - "Aspose.Pdf.Facades.PdfContentEditor.ReplaceImage", - "Aspose.Pdf.Facades.PdfContentEditor.Save" + "Aspose.Pdf.Facades.PdfExtractor", + "PdfContentEditor.BindPdf", + "PdfContentEditor.ReplaceImage", + "PdfContentEditor.Save", + "PdfExtractor.ExtractImage", + "PdfExtractor.HasNextImage", + "PdfExtractor.GetNextImage" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" }, - "verify-free-text-annotation-coordinates": { - "title": "Verify Free Text Annotation Coordinates with PdfContentEditor", - "filename": "verify-free-text-annotation-coordinates.cs", - "description": "Shows how to add a free‑text annotation to a PDF using PdfContentEditor and unit‑test that its rectangle matches the expected X and Y coordinates.", + "add-text-at-coordinates-verify-position": { + "title": "Add Text at Specific Coordinates and Verify Position", + "filename": "add-text-at-coordinates-verify-position.cs", + "description": "Creates a blank PDF, adds a text fragment at defined X/Y coordinates using TextBuilder, saves and reloads the file, then uses TextFragmentAbsorber to confirm the text appears at the expected position.", "tags": [ - "pdf", - "annotation", - "unittest", + "text", "coordinates", + "pdf", + "unit-test", "aspose-pdf" ], "apis_used": [ - "Aspose.Pdf.Facades.PdfContentEditor", "Aspose.Pdf.Document", - "Aspose.Pdf.Facades.PdfContentEditor.BindPdf", - "Aspose.Pdf.Facades.PdfContentEditor.CreateFreeText", - "Aspose.Pdf.Facades.PdfContentEditor.Save", - "Aspose.Pdf.Annotations.FreeTextAnnotation", - "Aspose.Pdf.Annotations.Annotation", - "Aspose.Pdf.Rectangle" + "Aspose.Pdf.Page", + "Aspose.Pdf.Text.TextFragment", + "Aspose.Pdf.Text.Position", + "Aspose.Pdf.Facades.TextBuilder", + "Aspose.Pdf.Text.TextFragmentAbsorber" + ], + "difficulty": "intermediate", + "generated_at": "2026-08-20T08:06:00Z", + "status": "verified" + }, + "add-image-verify-pdf-byte-size": { + "title": "Add Image to PDF and Verify Byte Size Increase", + "filename": "add-image-verify-pdf-byte-size.cs", + "description": "Creates a minimal PDF, binds it with PdfFileMend, adds a PNG image, saves the modified document, and asserts that the resulting PDF byte size is larger than the original.", + "tags": [ + "pdf", + "image", + "size", + "unit-test", + "aspose-pdf" + ], + "apis_used": [ + "Aspose.Pdf.Document", + "Aspose.Pdf.Facades.PdfFileMend", + "Aspose.Pdf.Facades.PdfFileMend.BindPdf", + "Aspose.Pdf.Facades.PdfFileMend.AddImage", + "Aspose.Pdf.Facades.PdfFileMend.Save" ], "difficulty": "intermediate", - "generated_at": "2026-07-18T01:14:53Z", + "generated_at": "2026-08-20T08:06:00Z", "status": "verified" } } diff --git a/facades-texts-and-images/insert-png-signature-image-every-pdf-page.cs b/facades-texts-and-images/insert-png-signature-image-every-pdf-page.cs deleted file mode 100644 index 8ec055125..000000000 --- a/facades-texts-and-images/insert-png-signature-image-every-pdf-page.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.IO; -using Aspose.Pdf; -using Aspose.Pdf.Facades; - -class Program -{ - static void Main() - { - const string inputPdf = "input.pdf"; - const string outputPdf = "signed_output.pdf"; - const string signaturePng = "signature.png"; - - if (!File.Exists(inputPdf)) - { - Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); - return; - } - if (!File.Exists(signaturePng)) - { - Console.Error.WriteLine($"Signature image not found: {signaturePng}"); - return; - } - - // Load the PDF to obtain the page count (uses the standard Document lifecycle rule) - using (Document doc = new Document(inputPdf)) - { - int pageCount = doc.Pages.Count; - - // Build an array of all page numbers (Aspose.Pdf uses 1‑based indexing) - int[] allPages = new int[pageCount]; - for (int i = 0; i < pageCount; i++) - allPages[i] = i + 1; - - // Create the PdfFileMend facade and bind the source PDF - PdfFileMend mend = new PdfFileMend(); - mend.BindPdf(inputPdf); - - // Define the rectangle for the signature image at the bottom‑left corner. - // lowerLeftX/Y = 0 places the image at the origin of the page. - // upperRightX/Y define the image size (e.g., 100 pt width, 50 pt height). - float lowerLeftX = 0f; - float lowerLeftY = 0f; - float upperRightX = 100f; // width of the signature - float upperRightY = 50f; // height of the signature - - // Add the PNG image to every page in a single call. - mend.AddImage(signaturePng, allPages, lowerLeftX, lowerLeftY, upperRightX, upperRightY); - - // Save the modified PDF. - mend.Save(outputPdf); - mend.Close(); // optional; releases resources - } - - Console.WriteLine($"Signature image added to every page → '{outputPdf}'"); - } -} \ No newline at end of file diff --git a/facades-texts-and-images/insert-png-signature-image-on-every-pdf-page.cs b/facades-texts-and-images/insert-png-signature-image-on-every-pdf-page.cs new file mode 100644 index 000000000..f357a63d3 --- /dev/null +++ b/facades-texts-and-images/insert-png-signature-image-on-every-pdf-page.cs @@ -0,0 +1,51 @@ +using System; +using System.IO; +using Aspose.Pdf.Facades; + +class Program +{ + static void Main() + { + const string inputPdf = "input.pdf"; + const string outputPdf = "output.pdf"; + const string signatureImage = "signature.png"; + + // Verify that the source PDF and the PNG image exist. + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); + return; + } + if (!File.Exists(signatureImage)) + { + Console.Error.WriteLine($"Signature image not found: {signatureImage}"); + return; + } + + // PdfFileMend implements IDisposable, so wrap it in a using block. + using (PdfFileMend mend = new PdfFileMend()) + { + // Load the PDF file into the facade. + mend.BindPdf(inputPdf); + + // Aspose.Pdf uses 1‑based page indexing. + int pageCount = mend.Document.Pages.Count; + + // Add the PNG to every page. + // Coordinates are in default PDF points (1/72 inch). + // Here we place the image at the bottom‑left corner (0,0) with a size of 100×100 points. + for (int page = 1; page <= pageCount; page++) + { + using (FileStream imgStream = File.OpenRead(signatureImage)) + { + mend.AddImage(imgStream, page, 0f, 0f, 100f, 100f); + } + } + + // Persist the changes to a new file. + mend.Save(outputPdf); + } + + Console.WriteLine($"Signature image added to all pages. Output saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-texts-and-images/overlay-semi-transparent-gif-on-pdf.cs b/facades-texts-and-images/overlay-semi-transparent-gif-on-pdf.cs index 047fd5f65..acab085ca 100644 --- a/facades-texts-and-images/overlay-semi-transparent-gif-on-pdf.cs +++ b/facades-texts-and-images/overlay-semi-transparent-gif-on-pdf.cs @@ -7,43 +7,51 @@ class Program { static void Main() { - const string inputPdf = "input.pdf"; // PDF that already contains a PNG image - const string outputPdf = "output.pdf"; // Resulting PDF with GIF overlay - const string gifPath = "overlay.gif"; // Semi‑transparent GIF to overlay - - // Validate input files - if (!File.Exists(inputPdf)) + // Input PDF that already contains the PNG image. + const string inputPdfPath = "input.pdf"; + // GIF image to overlay (semi‑transparent). + const string overlayGifPath = "overlay.gif"; + // Output PDF with the overlay applied. + const string outputPdfPath = "output.pdf"; + + // Verify required files exist. + if (!File.Exists(inputPdfPath)) { - Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); + Console.Error.WriteLine($"Input PDF not found: {inputPdfPath}"); return; } - if (!File.Exists(gifPath)) + if (!File.Exists(overlayGifPath)) { - Console.Error.WriteLine($"Overlay GIF not found: {gifPath}"); + Console.Error.WriteLine($"Overlay GIF not found: {overlayGifPath}"); return; } - // Create the PdfFileMend facade (no obsolete constructor) - PdfFileMend mend = new PdfFileMend(); - - // Bind the source PDF document - mend.BindPdf(inputPdf); - - // Prepare compositing parameters. - // BlendMode.Normal respects the GIF's own alpha channel (semi‑transparent). - CompositingParameters compParams = new CompositingParameters(BlendMode.Normal); - - // Add the GIF image to page 1. - // Coordinates are in points (1/72 inch). Adjust as needed to match the PNG area. - // lowerLeftX, lowerLeftY, upperRightX, upperRightY - mend.AddImage(gifPath, 1, 50f, 500f, 250f, 700f, compParams); - - // Save the modified PDF - mend.Save(outputPdf); - - // Release resources - mend.Close(); + // Use PdfFileMend facade to modify the PDF. + using (PdfFileMend mend = new PdfFileMend()) + { + // Load the existing PDF. + mend.BindPdf(inputPdfPath); + + // Define the rectangle where the GIF will be placed. + // Coordinates are in default user space units (points). + float lowerLeftX = 50f; // X of lower‑left corner + float lowerLeftY = 500f; // Y of lower‑left corner + float upperRightX = 250f; // X of upper‑right corner + float upperRightY = 700f; // Y of upper‑right corner + + // Create compositing parameters to achieve a semi‑transparent effect. + // BlendMode.Multiply blends the overlay with the underlying PNG. + CompositingParameters compParams = new CompositingParameters(BlendMode.Multiply); + + // Add the GIF image on page 1 using the compositing parameters. + // This overlays the GIF onto the existing PNG at the same coordinates. + mend.AddImage(overlayGifPath, 1, lowerLeftX, lowerLeftY, upperRightX, upperRightY, compParams); + + // Save the modified PDF. + mend.Save(outputPdfPath); + mend.Close(); + } - Console.WriteLine($"Overlay applied and saved to '{outputPdf}'."); + Console.WriteLine($"Overlay completed. Output saved to '{outputPdfPath}'."); } } \ No newline at end of file diff --git a/facades-texts-and-images/remove-all-images-from-pdf.cs b/facades-texts-and-images/remove-all-images-from-pdf.cs index eef4ce3f2..168d8acf6 100644 --- a/facades-texts-and-images/remove-all-images-from-pdf.cs +++ b/facades-texts-and-images/remove-all-images-from-pdf.cs @@ -1,52 +1,48 @@ using System; +using System.IO; using Aspose.Pdf.Facades; -public static class PdfImageRemover +class PdfImageRemover { /// - /// Removes all images from the specified PDF file and saves the result to a new file. + /// Removes all images from the specified PDF and saves the result to a new file. /// - /// Path to the source PDF. - /// Path where the image‑free PDF will be saved. - public static void RemoveAllImages(string inputPdfPath, string outputPdfPath) + /// Path to the input PDF file. + /// Path where the output PDF without images will be saved. + public static void RemoveAllImages(string sourcePdf, string destinationPdf) { - // Validate input arguments. - if (string.IsNullOrWhiteSpace(inputPdfPath)) - throw new ArgumentException("Input PDF path must be provided.", nameof(inputPdfPath)); + // Validate input file existence + if (!File.Exists(sourcePdf)) + throw new FileNotFoundException($"Input PDF not found: {sourcePdf}"); - if (string.IsNullOrWhiteSpace(outputPdfPath)) - throw new ArgumentException("Output PDF path must be provided.", nameof(outputPdfPath)); + // PdfContentEditor implements IDisposable, so use a using block for deterministic cleanup + using (PdfContentEditor editor = new PdfContentEditor()) + { + // Load the PDF document into the facade + editor.BindPdf(sourcePdf); + + // Delete every image from the document + editor.DeleteImage(); - // Load the PDF, delete all images, and save the result. - PdfContentEditor editor = new PdfContentEditor(); - editor.BindPdf(inputPdfPath); // Load the PDF. - editor.DeleteImage(); // Delete all images from every page. - editor.Save(outputPdfPath); // Persist the modified document. + // Persist the modified document to the specified output path + editor.Save(destinationPdf); + } } -} -public class Program -{ - /// - /// Entry point required for a console‑style build. - /// Accepts two arguments: input PDF path and output PDF path. - /// - public static void Main(string[] args) + // Example usage + static void Main() { - if (args.Length != 2) - { - Console.WriteLine("Usage: PdfImageRemover "); - return; - } + const string inputPath = "input.pdf"; + const string outputPath = "output_without_images.pdf"; try { - PdfImageRemover.RemoveAllImages(args[0], args[1]); - Console.WriteLine("All images removed successfully."); + RemoveAllImages(inputPath, outputPath); + Console.WriteLine($"All images removed. Saved to '{outputPath}'."); } catch (Exception ex) { Console.Error.WriteLine($"Error: {ex.Message}"); } } -} +} \ No newline at end of file diff --git a/facades-texts-and-images/remove-image-from-pdf-page.cs b/facades-texts-and-images/remove-image-from-pdf-page.cs index d5fc82a50..4b76af700 100644 --- a/facades-texts-and-images/remove-image-from-pdf-page.cs +++ b/facades-texts-and-images/remove-image-from-pdf-page.cs @@ -6,10 +6,10 @@ class Program { static void Main() { - const string inputPath = "input.pdf"; + const string inputPath = "input.pdf"; const string outputPath = "output.pdf"; - const int pageNumber = 4; // target page (1‑based indexing) - const int imageId = 1; // index of the image to remove on that page + const int pageNumber = 4; // target page (1‑based) + const int imageObjectId = 2; // replace with the actual image index to remove if (!File.Exists(inputPath)) { @@ -17,12 +17,16 @@ static void Main() return; } - // Load the PDF, delete the specified image, and save the result. + // PdfContentEditor does not implement IDisposable, so we manage it manually PdfContentEditor editor = new PdfContentEditor(); editor.BindPdf(inputPath); - editor.DeleteImage(pageNumber, new int[] { imageId }); + + // Remove the specified image from page four + editor.DeleteImage(pageNumber, new int[] { imageObjectId }); + + // Save the modified PDF editor.Save(outputPath); - Console.WriteLine($"Removed image {imageId} from page {pageNumber} and saved to '{outputPath}'."); + Console.WriteLine($"Removed image ID {imageObjectId} from page {pageNumber} and saved to '{outputPath}'."); } } \ No newline at end of file diff --git a/facades-texts-and-images/replace-jpeg-with-bmp-first-page.cs b/facades-texts-and-images/replace-jpeg-with-bmp-first-page.cs new file mode 100644 index 000000000..5728b10e5 --- /dev/null +++ b/facades-texts-and-images/replace-jpeg-with-bmp-first-page.cs @@ -0,0 +1,65 @@ +using System; +using System.IO; +using Aspose.Pdf; +using Aspose.Pdf.Facades; + +class ReplaceImageExample +{ + static void Main() + { + // Paths for the source PDF, the high‑resolution BMP source, and the output PDF. + const string inputPdfPath = "input.pdf"; + const string bmpSourcePath = "highres.bmp"; + const string outputPdfPath = "output.pdf"; + + // Verify that the required files exist. + if (!File.Exists(inputPdfPath)) + { + Console.Error.WriteLine($"Input PDF not found: {inputPdfPath}"); + return; + } + if (!File.Exists(bmpSourcePath)) + { + Console.Error.WriteLine($"BMP source not found: {bmpSourcePath}"); + return; + } + + // Create a temporary file to hold the BMP data because PdfContentEditor.ReplaceImage + // expects a file path (it does not accept a Stream directly). + string tempBmpPath = Path.GetTempFileName(); + try + { + // Copy the BMP stream to the temporary file. + using (FileStream srcStream = File.OpenRead(bmpSourcePath)) + using (FileStream tmpStream = File.OpenWrite(tempBmpPath)) + { + srcStream.CopyTo(tmpStream); + } + + // Load the PDF document inside a using block for deterministic disposal. + using (Document pdfDoc = new Document(inputPdfPath)) + { + // Initialize the content editor and bind it to the loaded document. + PdfContentEditor editor = new PdfContentEditor(); + editor.BindPdf(pdfDoc); + + // Replace the first image (index = 1) on the first page (pageNumber = 1) + // with the high‑resolution BMP stored in the temporary file. + editor.ReplaceImage(pageNumber: 1, index: 1, imageFile: tempBmpPath); + + // Save the modified PDF. + pdfDoc.Save(outputPdfPath); + } + + Console.WriteLine($"Image replaced successfully. Output saved to '{outputPdfPath}'."); + } + finally + { + // Clean up the temporary BMP file. + if (File.Exists(tempBmpPath)) + { + try { File.Delete(tempBmpPath); } catch { /* ignore cleanup errors */ } + } + } + } +} \ No newline at end of file diff --git a/facades-texts-and-images/replace-jpeg-with-bmp-using-replaceimage.cs b/facades-texts-and-images/replace-jpeg-with-bmp-using-replaceimage.cs deleted file mode 100644 index 7711d2e24..000000000 --- a/facades-texts-and-images/replace-jpeg-with-bmp-using-replaceimage.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.IO; -using System.Drawing; -using Aspose.Pdf; -using Aspose.Pdf.Facades; - -class Program -{ - static void Main() - { - // --------------------------------------------------------------------- - // 1. Create a source PDF that contains a JPEG image on the first page. - // This makes the example self‑contained – no external "input.pdf" is - // required in the sandbox. - // --------------------------------------------------------------------- - const string inputPdfPath = "input.pdf"; // temporary file for demo only - const string outputPdfPath = "output.pdf"; - - // Create a small JPEG image in memory (simulating the original low‑res image). - using (var lowResBmp = new Bitmap(50, 50)) - using (var lowResGraphics = Graphics.FromImage(lowResBmp)) - using (var lowResJpegStream = new MemoryStream()) - { - lowResGraphics.Clear(System.Drawing.Color.LightBlue); - lowResBmp.Save(lowResJpegStream, System.Drawing.Imaging.ImageFormat.Jpeg); - lowResJpegStream.Position = 0; - - // Build the PDF and embed the JPEG image. - using (var pdfDoc = new Document()) - { - Page page = pdfDoc.Pages.Add(); - // Aspose.Pdf.Image does not have a constructor that accepts a Stream. - // Use the parameterless constructor and assign the ImageStream property. - var jpegImage = new Aspose.Pdf.Image(); - jpegImage.ImageStream = lowResJpegStream; - // Position the image (optional). - jpegImage.FixWidth = 100; - jpegImage.FixHeight = 100; - page.Paragraphs.Add(jpegImage); - pdfDoc.Save(inputPdfPath); - } - } - - // --------------------------------------------------------------------- - // 2. Prepare a higher‑resolution BMP image as a stream. - // --------------------------------------------------------------------- - MemoryStream highResBmpStream; - using (var highResBmp = new Bitmap(200, 200)) - using (var gfx = Graphics.FromImage(highResBmp)) - { - gfx.Clear(System.Drawing.Color.OrangeRed); - // Draw something to make the image recognisable. - gfx.DrawEllipse(System.Drawing.Pens.White, 20, 20, 160, 160); - highResBmpStream = new MemoryStream(); - highResBmp.Save(highResBmpStream, System.Drawing.Imaging.ImageFormat.Bmp); - highResBmpStream.Position = 0; // reset for reading - } - - // --------------------------------------------------------------------- - // 3. Load the PDF, bind it to PdfContentEditor and replace the image. - // --------------------------------------------------------------------- - // PdfContentEditor.ReplaceImage overload that accepts a Stream is not - // available in the version used for this sandbox, therefore we write the - // BMP to a temporary file and pass the file path. - string tempBmpPath = Path.GetTempFileName(); - File.WriteAllBytes(tempBmpPath, highResBmpStream.ToArray()); - - using (Document pdfDoc = new Document(inputPdfPath)) - using (PdfContentEditor editor = new PdfContentEditor()) - { - editor.BindPdf(pdfDoc); - // Replace the first image (index = 1) on page 1 with the BMP file. - editor.ReplaceImage(pageNumber: 1, index: 1, tempBmpPath); - pdfDoc.Save(outputPdfPath); - } - - // Clean up temporary files. - if (File.Exists(inputPdfPath)) - File.Delete(inputPdfPath); - if (File.Exists(tempBmpPath)) - File.Delete(tempBmpPath); - - Console.WriteLine($"Image replaced and saved to '{outputPdfPath}'."); - } -} diff --git a/facades-texts-and-images/replace-low-res-images-with-high-res-pngs.cs b/facades-texts-and-images/replace-low-res-images-with-high-res-pngs.cs new file mode 100644 index 000000000..c56fad43a --- /dev/null +++ b/facades-texts-and-images/replace-low-res-images-with-high-res-pngs.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"; + const string outputPdf = "output.pdf"; + const string highResFolder = "HighResImages"; + + if (!File.Exists(inputPdf)) + { + Console.Error.WriteLine($"Input PDF not found: {inputPdf}"); + return; + } + + // Load the PDF for page count information + using (Document doc = new Document(inputPdf)) + { + // Facade for editing PDF content (image replacement) + using (PdfContentEditor editor = new PdfContentEditor()) + { + editor.BindPdf(inputPdf); + + // Iterate through each page (1‑based indexing) + for (int pageNum = 1; pageNum <= doc.Pages.Count; pageNum++) + { + // Use PdfExtractor to determine how many images are on the current page + using (PdfExtractor extractor = new PdfExtractor()) + { + extractor.BindPdf(inputPdf); + extractor.StartPage = pageNum; + extractor.EndPage = pageNum; + extractor.ExtractImage(); + + int imageIndex = 1; + while (extractor.HasNextImage()) + { + // Expected high‑resolution PNG file name pattern: + // page{page}_img{index}.png + string highResPath = Path.Combine( + highResFolder, + $"page{pageNum}_img{imageIndex}.png"); + + if (File.Exists(highResPath)) + { + // Replace the low‑resolution image with the high‑resolution PNG + editor.ReplaceImage(pageNum, imageIndex, highResPath); + } + + // Advance the extractor to the next image (output discarded) + string tempFile = Path.GetTempFileName(); + extractor.GetNextImage(tempFile); + File.Delete(tempFile); + + imageIndex++; + } + } + } + + // Save the modified PDF + editor.Save(outputPdf); + } + } + + Console.WriteLine($"High‑resolution image replacement completed. Output saved to '{outputPdf}'."); + } +} \ No newline at end of file diff --git a/facades-texts-and-images/replace-lowres-images-with-highres-png.cs b/facades-texts-and-images/replace-lowres-images-with-highres-png.cs deleted file mode 100644 index 632b18172..000000000 --- a/facades-texts-and-images/replace-lowres-images-with-highres-png.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.IO; -using Aspose.Pdf; -using Aspose.Pdf.Facades; - -class Program -{ - static void Main() - { - const string inputPdf = "input.pdf"; - const string outputPdf = "output.pdf"; - const string highResImage = "highres.png"; - - if (!File.Exists(inputPdf)) - { - Console.Error.WriteLine($"Input file not found: {inputPdf}"); - return; - } - - if (!File.Exists(highResImage)) - { - Console.Error.WriteLine($"High‑resolution image not found: {highResImage}"); - return; - } - - // Load the PDF document (using rule for disposal) - using (Document doc = new Document(inputPdf)) - { - // Bind the document to the PdfContentEditor facade - PdfContentEditor editor = new PdfContentEditor(); - editor.BindPdf(doc); - - // Iterate over all pages (1‑based indexing) - for (int pageNum = 1; pageNum <= doc.Pages.Count; pageNum++) - { - // Get the number of images on the current page - int imageCount = doc.Pages[pageNum].Resources.Images.Count; - - // Replace each image with the high‑resolution PNG - for (int imgIdx = 1; imgIdx <= imageCount; imgIdx++) - { - editor.ReplaceImage(pageNum, imgIdx, highResImage); - } - } - - // Save the modified PDF (using rule for saving) - editor.Save(outputPdf); - } - - Console.WriteLine($"PDF saved with high‑resolution images to '{outputPdf}'."); - } -} \ No newline at end of file diff --git a/facades-texts-and-images/validate-image-format-before-calling-addimage-to-ensure-only-jpg-png-gif-bmp-or-tiff-files-are-used.cs b/facades-texts-and-images/validate-image-format-before-calling-addimage-to-ensure-only-jpg-png-gif-bmp-or-tiff-files-are-used.cs deleted file mode 100644 index f05218fd1..000000000 --- a/facades-texts-and-images/validate-image-format-before-calling-addimage-to-ensure-only-jpg-png-gif-bmp-or-tiff-files-are-used.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.IO; -using Aspose.Pdf.Facades; - -class Program -{ - static void Main() - { - const string inputPdf = "input.pdf"; - const string imagePath = "image.png"; - const string outputPdf = "output.pdf"; - - // Verify source files exist - if (!File.Exists(inputPdf)) - { - Console.Error.WriteLine($"PDF not found: {inputPdf}"); - return; - } - if (!File.Exists(imagePath)) - { - Console.Error.WriteLine($"Image not found: {imagePath}"); - return; - } - - // Validate image format (allow only JPG, PNG, GIF, BMP, TIFF) - string ext = Path.GetExtension(imagePath).ToLowerInvariant(); - string[] allowed = { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tif", ".tiff" }; - bool isValid = Array.Exists(allowed, e => e == ext); - if (!isValid) - { - Console.Error.WriteLine($"Unsupported image format: {ext}"); - return; - } - - // Use PdfFileMend facade to add the image - using (PdfFileMend mend = new PdfFileMend()) - { - // Bind the existing PDF document - mend.BindPdf(inputPdf); - - // Open the image stream and add it to page 1 - using (FileStream imgStream = File.OpenRead(imagePath)) - { - // Coordinates: lower-left (50,700), upper-right (200,850) - bool added = mend.AddImage(imgStream, 1, 50f, 700f, 200f, 850f); - if (!added) - { - Console.Error.WriteLine("Failed to add image to the PDF."); - } - } - - // Save the modified PDF - mend.Save(outputPdf); - } - - Console.WriteLine($"Image added and saved to '{outputPdf}'."); - } -} \ No newline at end of file diff --git a/facades-texts-and-images/verify-free-text-annotation-coordinates.cs b/facades-texts-and-images/verify-free-text-annotation-coordinates.cs deleted file mode 100644 index a693ca689..000000000 --- a/facades-texts-and-images/verify-free-text-annotation-coordinates.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System; -using System.Drawing; -using System.IO; -using Aspose.Pdf; -using Aspose.Pdf.Annotations; -using Aspose.Pdf.Facades; -using NUnit.Framework; - -// Minimal NUnit stubs – only the members used by the tests are provided. -// If the real NUnit package is referenced these definitions are ignored by the compiler. -namespace NUnit.Framework -{ - [AttributeUsage(AttributeTargets.Class)] - public sealed class TestFixtureAttribute : Attribute { } - - [AttributeUsage(AttributeTargets.Method)] - public sealed class TestAttribute : Attribute { } - - public static class Assert - { - public static void AreEqual(T expected, T actual, string? message = null) - { - if (!object.Equals(expected, actual)) - { - throw new Exception(message ?? $"Assert.AreEqual failed. Expected:<{expected}>. Actual:<{actual}>."); - } - } - - public static void IsInstanceOf(object obj, string? message = null) - { - if (!(obj is T)) - { - throw new Exception(message ?? $"Assert.IsInstanceOf failed. Expected type:<{typeof(T)}> but was:<{obj?.GetType()}>."); - } - } - } -} - -namespace AsposePdfFacadesTests -{ - [TestFixture] - public class PdfContentEditorTests - { - // Helper to create a simple one‑page PDF in memory - private static Document CreateBlankPdf() - { - // Document constructor creates an empty PDF; add a page to have something to annotate - Document doc = new Document(); - doc.Pages.Add(); - return doc; - } - - [Test] - public void AddTextCoordinates_ShouldPlaceFreeTextAtExpectedLocation() - { - // Expected rectangle coordinates (points). - // System.Drawing.Rectangle uses (x, y, width, height) where (x, y) is the upper‑left corner. - // Aspose.Pdf expects a rectangle defined by lower‑left (llx,lly) and upper‑right (urx,ury). - // For the purpose of this test we compare the values after conversion. - int rectX = 100; // lower‑left X - int rectY = 200; // lower‑left Y - int rectWidth = 300; // width - int rectHeight = 50; // height - - // System.Drawing.Rectangle for CreateFreeText (origin is top‑left, so we keep the same values) - System.Drawing.Rectangle drawingRect = new System.Drawing.Rectangle(rectX, rectY, rectWidth, rectHeight); - const string annotationText = "UnitTest Text"; - - // Paths for temporary files - string tempPdfPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".pdf"); - string resultPdfPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".pdf"); - - try - { - // ----------------------------------------------------------------- - // 1. Create a blank PDF and save it (source for editing) - // ----------------------------------------------------------------- - using (Document sourceDoc = CreateBlankPdf()) - { - sourceDoc.Save(tempPdfPath); - } - - // ----------------------------------------------------------------- - // 2. Use PdfContentEditor (Facade) to add free‑text annotation - // ----------------------------------------------------------------- - using (PdfContentEditor editor = new PdfContentEditor()) - { - // Bind to the source PDF file - editor.BindPdf(tempPdfPath); - - // Create free‑text annotation on page 1 at the specified rectangle - editor.CreateFreeText(drawingRect, annotationText, 1); - - // Save the modified PDF - editor.Save(resultPdfPath); - } - - // ----------------------------------------------------------------- - // 3. Load the resulting PDF and verify the annotation's rectangle - // ----------------------------------------------------------------- - using (Document resultDoc = new Document(resultPdfPath)) - { - // Ensure the annotation exists - Assert.AreEqual(1, resultDoc.Pages[1].Annotations.Count, "Expected one annotation on the page."); - - // The annotation created by CreateFreeText is a FreeTextAnnotation - Annotation ann = resultDoc.Pages[1].Annotations[1]; - Assert.IsInstanceOf(ann, "Annotation should be a FreeTextAnnotation."); - - FreeTextAnnotation freeText = (FreeTextAnnotation)ann; - - // The rectangle returned by Aspose.Pdf is an Aspose.Pdf.Rectangle - Aspose.Pdf.Rectangle pdfRect = freeText.Rect; - - // Verify lower‑left coordinates - Assert.AreEqual(rectX, (int)pdfRect.LLX, "Lower‑left X coordinate mismatch."); - Assert.AreEqual(rectY, (int)pdfRect.LLY, "Lower‑left Y coordinate mismatch."); - - // Verify upper‑right coordinates (computed from width/height) - int expectedURX = rectX + rectWidth; - int expectedURY = rectY + rectHeight; - Assert.AreEqual(expectedURX, (int)pdfRect.URX, "Upper‑right X coordinate mismatch."); - Assert.AreEqual(expectedURY, (int)pdfRect.URY, "Upper‑right Y coordinate mismatch."); - - // Optional: verify the annotation's contents - Assert.AreEqual(annotationText, freeText.Contents, "Annotation text mismatch."); - } - } - finally - { - // Clean up temporary files - if (File.Exists(tempPdfPath)) File.Delete(tempPdfPath); - if (File.Exists(resultPdfPath)) File.Delete(resultPdfPath); - } - } - } - - // Dummy entry point to satisfy the compiler when the project is built as an executable. - public class Program - { - public static void Main(string[] args) - { - // No operation – tests are executed via the test runner. - } - } -} From 44c83ffad9ed0dc77f813bdf5eb6df595c4981d5 Mon Sep 17 00:00:00 2001 From: agent-aspose-pdf-examples Date: Tue, 8 Sep 2026 06:20:44 -0500 Subject: [PATCH 2/2] Add URL-stability stubs for 17 regenerated paths Regeneration renamed these examples, which would delete live URLs on main. Each old path now holds a stub pointing at its current location (11 direct matches, 6 to the category folder). AI-assisted development --- facades-texts-and-images/add-header-image-to-pdfs.cs | 12 ++++++++++++ .../add-image-and-text-audit-pdf.cs | 12 ++++++++++++ .../add-image-to-all-pdf-pages-dynamic-position.cs | 12 ++++++++++++ .../add-image-to-pdf-get-memorystream.cs | 12 ++++++++++++ .../add-image-to-pdf-with-pdffilemend.cs | 12 ++++++++++++ .../add-multi-line-text-left-margin-page-3.cs | 12 ++++++++++++ .../add-promotional-text-multiple-pdf-pages.cs | 12 ++++++++++++ .../add-tiff-image-to-last-pdf-page.cs | 12 ++++++++++++ .../add-word-wrapped-footer-to-pdf.cs | 12 ++++++++++++ .../batch-add-logo-to-pdf-pages.cs | 12 ++++++++++++ .../configure-word-wrapping-bywords.cs | 12 ++++++++++++ .../extract-images-from-pdf-pages-2-5.cs | 12 ++++++++++++ .../insert-png-signature-image-every-pdf-page.cs | 12 ++++++++++++ .../replace-jpeg-with-bmp-using-replaceimage.cs | 12 ++++++++++++ .../replace-lowres-images-with-highres-png.cs | 12 ++++++++++++ ...re-only-jpg-png-gif-bmp-or-tiff-files-are-used.cs | 12 ++++++++++++ .../verify-free-text-annotation-coordinates.cs | 12 ++++++++++++ 17 files changed, 204 insertions(+) create mode 100644 facades-texts-and-images/add-header-image-to-pdfs.cs create mode 100644 facades-texts-and-images/add-image-and-text-audit-pdf.cs create mode 100644 facades-texts-and-images/add-image-to-all-pdf-pages-dynamic-position.cs create mode 100644 facades-texts-and-images/add-image-to-pdf-get-memorystream.cs create mode 100644 facades-texts-and-images/add-image-to-pdf-with-pdffilemend.cs create mode 100644 facades-texts-and-images/add-multi-line-text-left-margin-page-3.cs create mode 100644 facades-texts-and-images/add-promotional-text-multiple-pdf-pages.cs create mode 100644 facades-texts-and-images/add-tiff-image-to-last-pdf-page.cs create mode 100644 facades-texts-and-images/add-word-wrapped-footer-to-pdf.cs create mode 100644 facades-texts-and-images/batch-add-logo-to-pdf-pages.cs create mode 100644 facades-texts-and-images/configure-word-wrapping-bywords.cs create mode 100644 facades-texts-and-images/extract-images-from-pdf-pages-2-5.cs create mode 100644 facades-texts-and-images/insert-png-signature-image-every-pdf-page.cs create mode 100644 facades-texts-and-images/replace-jpeg-with-bmp-using-replaceimage.cs create mode 100644 facades-texts-and-images/replace-lowres-images-with-highres-png.cs create mode 100644 facades-texts-and-images/validate-image-format-before-calling-addimage-to-ensure-only-jpg-png-gif-bmp-or-tiff-files-are-used.cs create mode 100644 facades-texts-and-images/verify-free-text-annotation-coordinates.cs diff --git a/facades-texts-and-images/add-header-image-to-pdfs.cs b/facades-texts-and-images/add-header-image-to-pdfs.cs new file mode 100644 index 000000000..f9dcf25b2 --- /dev/null +++ b/facades-texts-and-images/add-header-image-to-pdfs.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// add header image to pdfs +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/blob/main/facades-texts-and-images/add-header-image-to-pdf-documents.cs +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/add-image-and-text-audit-pdf.cs b/facades-texts-and-images/add-image-and-text-audit-pdf.cs new file mode 100644 index 000000000..e5170bcb4 --- /dev/null +++ b/facades-texts-and-images/add-image-and-text-audit-pdf.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// add image and text audit pdf +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/tree/main/facades-texts-and-images +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/add-image-to-all-pdf-pages-dynamic-position.cs b/facades-texts-and-images/add-image-to-all-pdf-pages-dynamic-position.cs new file mode 100644 index 000000000..3c7409f1f --- /dev/null +++ b/facades-texts-and-images/add-image-to-all-pdf-pages-dynamic-position.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// add image to all pdf pages dynamic position +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/blob/main/facades-texts-and-images/add-image-to-each-pdf-page-dynamic-position.cs +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/add-image-to-pdf-get-memorystream.cs b/facades-texts-and-images/add-image-to-pdf-get-memorystream.cs new file mode 100644 index 000000000..effa1783e --- /dev/null +++ b/facades-texts-and-images/add-image-to-pdf-get-memorystream.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// add image to pdf get memorystream +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/tree/main/facades-texts-and-images +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/add-image-to-pdf-with-pdffilemend.cs b/facades-texts-and-images/add-image-to-pdf-with-pdffilemend.cs new file mode 100644 index 000000000..402877120 --- /dev/null +++ b/facades-texts-and-images/add-image-to-pdf-with-pdffilemend.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// add image to pdf with pdffilemend +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/blob/main/facades-texts-and-images/add-image-to-pdf-using-pdffilemend.cs +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/add-multi-line-text-left-margin-page-3.cs b/facades-texts-and-images/add-multi-line-text-left-margin-page-3.cs new file mode 100644 index 000000000..44825d0df --- /dev/null +++ b/facades-texts-and-images/add-multi-line-text-left-margin-page-3.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// add multi line text left margin page 3 +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/blob/main/facades-texts-and-images/add-multi-line-text-block-page-3.cs +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/add-promotional-text-multiple-pdf-pages.cs b/facades-texts-and-images/add-promotional-text-multiple-pdf-pages.cs new file mode 100644 index 000000000..9b1484e05 --- /dev/null +++ b/facades-texts-and-images/add-promotional-text-multiple-pdf-pages.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// add promotional text multiple pdf pages +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/blob/main/facades-texts-and-images/add-promotional-text-to-specific-pdf-pages.cs +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/add-tiff-image-to-last-pdf-page.cs b/facades-texts-and-images/add-tiff-image-to-last-pdf-page.cs new file mode 100644 index 000000000..0b2be9017 --- /dev/null +++ b/facades-texts-and-images/add-tiff-image-to-last-pdf-page.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// add tiff image to last pdf page +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/blob/main/facades-texts-and-images/add-tiff-image-to-last-page-pdf.cs +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/add-word-wrapped-footer-to-pdf.cs b/facades-texts-and-images/add-word-wrapped-footer-to-pdf.cs new file mode 100644 index 000000000..65cda0ef5 --- /dev/null +++ b/facades-texts-and-images/add-word-wrapped-footer-to-pdf.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// add word wrapped footer to pdf +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/blob/main/facades-texts-and-images/add-wrapped-footer-to-pdf-pages.cs +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/batch-add-logo-to-pdf-pages.cs b/facades-texts-and-images/batch-add-logo-to-pdf-pages.cs new file mode 100644 index 000000000..3e11631ca --- /dev/null +++ b/facades-texts-and-images/batch-add-logo-to-pdf-pages.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// batch add logo to pdf pages +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/tree/main/facades-texts-and-images +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/configure-word-wrapping-bywords.cs b/facades-texts-and-images/configure-word-wrapping-bywords.cs new file mode 100644 index 000000000..030cbc709 --- /dev/null +++ b/facades-texts-and-images/configure-word-wrapping-bywords.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// configure word wrapping bywords +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/blob/main/facades-texts-and-images/configure-word-wrapping-bywords-add-long-text.cs +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/extract-images-from-pdf-pages-2-5.cs b/facades-texts-and-images/extract-images-from-pdf-pages-2-5.cs new file mode 100644 index 000000000..031d5063b --- /dev/null +++ b/facades-texts-and-images/extract-images-from-pdf-pages-2-5.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// extract images from pdf pages 2 5 +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/blob/main/facades-texts-and-images/extract-images-from-pdf-pages.cs +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/insert-png-signature-image-every-pdf-page.cs b/facades-texts-and-images/insert-png-signature-image-every-pdf-page.cs new file mode 100644 index 000000000..a327917f3 --- /dev/null +++ b/facades-texts-and-images/insert-png-signature-image-every-pdf-page.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// insert png signature image every pdf page +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/blob/main/facades-texts-and-images/insert-png-signature-image-on-every-pdf-page.cs +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/replace-jpeg-with-bmp-using-replaceimage.cs b/facades-texts-and-images/replace-jpeg-with-bmp-using-replaceimage.cs new file mode 100644 index 000000000..faa20cd10 --- /dev/null +++ b/facades-texts-and-images/replace-jpeg-with-bmp-using-replaceimage.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// replace jpeg with bmp using replaceimage +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/tree/main/facades-texts-and-images +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/replace-lowres-images-with-highres-png.cs b/facades-texts-and-images/replace-lowres-images-with-highres-png.cs new file mode 100644 index 000000000..5c52c68d9 --- /dev/null +++ b/facades-texts-and-images/replace-lowres-images-with-highres-png.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// replace lowres images with highres png +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/blob/main/facades-texts-and-images/replace-low-res-images-with-high-res-pngs.cs +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/validate-image-format-before-calling-addimage-to-ensure-only-jpg-png-gif-bmp-or-tiff-files-are-used.cs b/facades-texts-and-images/validate-image-format-before-calling-addimage-to-ensure-only-jpg-png-gif-bmp-or-tiff-files-are-used.cs new file mode 100644 index 000000000..aca8a8b3e --- /dev/null +++ b/facades-texts-and-images/validate-image-format-before-calling-addimage-to-ensure-only-jpg-png-gif-bmp-or-tiff-files-are-used.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// validate image format before calling addimage to ensure only jpg png gif bmp or tiff files are used +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/tree/main/facades-texts-and-images +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } } diff --git a/facades-texts-and-images/verify-free-text-annotation-coordinates.cs b/facades-texts-and-images/verify-free-text-annotation-coordinates.cs new file mode 100644 index 000000000..e829831dd --- /dev/null +++ b/facades-texts-and-images/verify-free-text-annotation-coordinates.cs @@ -0,0 +1,12 @@ +// URL-STABILITY STUB +// +// verify free text annotation coordinates +// +// This example has been consolidated or moved. Current location: +// https://github.com/aspose-pdf/agentic-net-examples/tree/main/facades-texts-and-images +// +// This stub keeps the original URL live for existing bookmarks, +// search-engine indexes, and blog-post links. See the canonical +// location above for the current, maintained implementation. + +class Program { static void Main() { } }