Hello,
I’m trying so check for TrimMarkAnnotations after they have been added to Page.
But after adding they are converted into “Unknown” type
Aspose PDF version 25.1
AnnotationType checkAnnotation() {
Document doc = new Document();
doc.getPages().add();
Page page = doc.getPages().get_Item(1);
page.getAnnotations().add(new TrimMarkAnnotation(page, TopLeft));
return page.getAnnotations().get_Item(1).getAnnotationType();
}
@dfinsolutions
Below is a sample code snippet to add Trim/Bleed/Registration Mark Annotations in a PDF document:
// 1. Add margins on each side of the page, so that marks will be visible
var editor = new Facades.PdfFileEditor();
editor.AddMargins(dataDir + "trimmarkannotation.pdf", "temp.pdf", new[] { 1 }, 36, 36, 36, 36);
using (var document = new Document("temp.pdf"))
{
var page = document.Pages[1];
var mediaBox = page.MediaBox;
// 2. Set Page.TrimBox and Page.BleedBox not to include margins. The printer marks are placed between the MediaBox and these boxes
page.TrimBox = new Rectangle(36, 36, mediaBox.URX - 36, mediaBox.URY - 36);
// The BleedBox is usually slightly larger than the TrimBox
page.BleedBox = new Rectangle(34, 34, mediaBox.URX - 34, mediaBox.URY - 34);
// 3. Add trim mark in the corners of the TrimBox
page.Annotations.Add(new TrimMarkAnnotation(page, PrinterMarkCornerPosition.TopLeft));
page.Annotations.Add(new TrimMarkAnnotation(page, PrinterMarkCornerPosition.TopRight));
page.Annotations.Add(new TrimMarkAnnotation(page, PrinterMarkCornerPosition.BottomLeft));
page.Annotations.Add(new TrimMarkAnnotation(page, PrinterMarkCornerPosition.BottomRight));
// 4. Add bleed marks in the corners of the bleed box
page.Annotations.Add(new BleedMarkAnnotation(page, PrinterMarkCornerPosition.TopLeft));
page.Annotations.Add(new BleedMarkAnnotation(page, PrinterMarkCornerPosition.TopRight));
page.Annotations.Add(new BleedMarkAnnotation(page, PrinterMarkCornerPosition.BottomLeft));
page.Annotations.Add(new BleedMarkAnnotation(page, PrinterMarkCornerPosition.BottomRight));
// 5. Add color registration targets on all sides of the page
page.Annotations.Add(new RegistrationMarkAnnotation(page, PrinterMarkSidePosition.Top));
page.Annotations.Add(new RegistrationMarkAnnotation(page, PrinterMarkSidePosition.Bottom));
page.Annotations.Add(new RegistrationMarkAnnotation(page, PrinterMarkSidePosition.Left));
page.Annotations.Add(new RegistrationMarkAnnotation(page, PrinterMarkSidePosition.Right));
// 6. Add the page information annotation in the bottom of the page, below the TrimBox
var annotRectangle = new Rectangle(page.TrimBox.LLX, mediaBox.LLY, page.TrimBox.URX, page.TrimBox.LLY);
page.Annotations.Add(new PageInformationAnnotation(page, annotRectangle));
document.Save(dataDir + "output.pdf");
}
output.pdf (9.0 KB)
trimmarkannotation.pdf (1.8 KB)