Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Artifacts in PDF are graphics objects or other elements that are not part of the actual content of the document. They are usually used for decoration, layout, or background purposes. Examples of artifacts include page headers, footers, separators, or images that do not convey any meaning.
The purpose of artifacts in PDF is to allow the distinction between content and non-content elements. This is important for accessibility, as screen readers and other assistive technologies can ignore artifacts and focus on the relevant content. Artifacts can also improve the performance and quality of PDF documents, as they can be omitted from printing, searching, or copying.
To create an element as an artifact in PDF, you need to use the Artifact class. It contains following useful properties:
The following classes may also be useful for work with artifacts:
A watermark created with Adobe Acrobat is called an artifact (as described in 14.8.2.2 Real Content and Artifacts of the PDF specification).
In order to get all Watermarks on a particular page, the Page class has the Artifacts property.
The following code snippet shows how to get all watermarks on the first page of a PDF file.
Note: This code also works with Aspose.PDF.Drawing library.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ExtractWatermarkFromPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "sample-w.pdf"))
{
// Get the watermarks from the first page artifacts
var watermarks = document.Pages[1].Artifacts
.Where(artifact =>
artifact.Type == Aspose.Pdf.Artifact.ArtifactType.Pagination
&& artifact.Subtype == Aspose.Pdf.Artifact.ArtifactSubtype.Watermark);
// Iterate through the found watermark artifacts and print details
foreach (Aspose.Pdf.WatermarkArtifact item in watermarks.Cast<Aspose.Pdf.WatermarkArtifact>())
{
Console.WriteLine($"{item.Text} {item.Rectangle}");
}
}
}
Background images can be used to add a watermark, or other subtle design, to documents. In Aspose.PDF for .NET, each PDF document is a collection of pages and each page contains a collection of artifacts. The BackgroundArtifact class can be used to add a background image to a page object.
The following code snippet shows how to add a background image to PDF pages using the BackgroundArtifact object.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddBackgroundImageToPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "sample.pdf"))
{
// Create a new BackgroundArtifact and set the background image
var background = new Aspose.Pdf.BackgroundArtifact()
{
BackgroundImage = File.OpenRead(dataDir + "background.jpg")
};
// Add the background image to the first page's artifacts
document.Pages[1].Artifacts.Add(background);
// Save PDF document with the added background
document.Save(dataDir + "SampleArtifactsBackground_out.pdf");
}
}
If you want, for some reason, to use a solid color background, please change the previous code in the following manner:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddBackgroundColorToPDF()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "sample.pdf"))
{
// Create a new BackgroundArtifact and set the background color
var background = new Aspose.Pdf.BackgroundArtifact()
{
BackgroundColor = Aspose.Pdf.Color.DarkKhaki
};
// Add the background color to the first page's artifacts
document.Pages[1].Artifacts.Add(background);
// Save PDF document
document.Save(dataDir + "SampleArtifactsBackground_out.pdf");
}
}
To calculate the total count of artifacts of a particular type (for example, the total number of watermarks), use the following code:
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void CountPDFArtifacts()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "sample.pdf"))
{
// Get pagination artifacts from the first page
var paginationArtifacts = document.Pages[1].Artifacts
.Where(artifact => artifact.Type == Aspose.Pdf.Artifact.ArtifactType.Pagination);
// Count and display the number of each artifact type
Console.WriteLine("Watermarks: {0}",
paginationArtifacts.Count(a => a.Subtype == Aspose.Pdf.Artifact.ArtifactSubtype.Watermark));
Console.WriteLine("Backgrounds: {0}",
paginationArtifacts.Count(a => a.Subtype == Aspose.Pdf.Artifact.ArtifactSubtype.Background));
Console.WriteLine("Headers: {0}",
paginationArtifacts.Count(a => a.Subtype == Aspose.Pdf.Artifact.ArtifactSubtype.Header));
Console.WriteLine("Footers: {0}",
paginationArtifacts.Count(a => a.Subtype == Aspose.Pdf.Artifact.ArtifactSubtype.Footer));
}
}
To add a Bates numbering artifact to a document, call the AddBatesNumbering(BatesNArtifact batesNArtifact)
extension method on the PageCollection
, passing the BatesNArtifact
object as a parameter:
Or, you can pass a collection of PaginationArtifacts
:
Alternatively, you can add a Bates numbering artifact using an action delegate:
To delete Bates numbering, use the following code:
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.