public object AnnotationContainer { get; set; }
An optional Object that must point to a valid instance of AnnContainer class containing the objects to use when annotating a page in PDF documents. Default value is null (Nothing in VB).
The AnnotationContainer property is optional and is used only when the document being created is PDF. To create a PDF document with annotations, perform the following steps:
For more information, refer to PdfDocumentOptions.
Note that AnnContainer is used only when the document being created is PDF.also saving annotated document is not supported when DocumentType is PdfDocumentType.PdfA.
using Leadtools;using Leadtools.Codecs;using Leadtools.Document.Writer;using Leadtools.Ocr;public void DocumentEmfPageExample(){// Output PDF file namevar pdfFileName = Path.Combine(LEAD_VARS.ImagesDir, "Example.pdf");// Document properties, each page is 8.5 by 11 inches at 300 DPI. Typical dimensionsvar resolution = 300;var pageWidth = (int)(8.5 * resolution);var pageHeight = (int)(11 * resolution);// Create the document writervar docWriter = new DocumentWriter();docWriter.BeginDocument(pdfFileName, DocumentFormat.Pdf);for (var pageNumber = 1; pageNumber <= 2; pageNumber++){var page = new DocumentWriterEmfPage();page.EmfHandle = GetPageEmf(pageNumber, pageWidth, pageHeight, resolution);docWriter.AddPage(page);if (page.EmfHandle != IntPtr.Zero)DeleteEnhMetaFile(page.EmfHandle);}docWriter.EndDocument();// To show the PDF file// System.Diagnostics.Process.Start(pdfFileName);}private static IntPtr GetPageEmf(int pageNumber, int pageWidth, int pageHeight, int resolution){// Get the screen DCusing (var graphicsScreen = Graphics.FromHwndInternal(IntPtr.Zero)){var hdcScreen = graphicsScreen.GetHdc();// Calculate the EMF rectangle in 1/100 mmvar frameRect = new RectangleF(0,0,((float)pageWidth * 2540 + resolution / 2) / resolution,((float)pageHeight * 2540 + resolution / 2) / resolution);// Create the EMF, GDI compatibleusing (var metaFile = new Metafile(hdcScreen, frameRect, MetafileFrameUnit.GdiCompatible, EmfType.EmfOnly, null)){// No need for this anymoregraphicsScreen.ReleaseHdc(hdcScreen);// Now create the graphics to draw in from the metafileusing (var graphics = Graphics.FromImage(metaFile)){// Get the EMF DPIMetafileHeader header = metaFile.GetMetafileHeader();var emfDpiX = header.DpiX;var emfDpiY = header.DpiY;// We must convert each value we want from pixels to EMF coordinates, so use a scalegraphics.ScaleTransform(emfDpiX / resolution, emfDpiY / resolution);// To draw font, we must use this scale value to convert from point sizevar fontScale = (float)resolution / Math.Max(graphics.DpiX, graphics.DpiY);// Ready, now we can draw...// Fill it with whitevar rc = new RectangleF(0, 0, pageWidth, pageHeight);graphics.FillRectangle(Brushes.White, rc);// Put a framerc = new RectangleF(1, 1, pageWidth - 2, pageHeight - 2);graphics.DrawRectangle(Pens.DarkGreen, rc.X, rc.Y, rc.Width, rc.Height);// Draw some textvar text = "This is page " + pageNumber.ToString();float pointSize = 20 * fontScale;// fonts need to converted to scaled back, so ...using (var font = new Font("Arial", pointSize, FontStyle.Regular))graphics.DrawString(text, font, Brushes.Black, 0, 0);// Add some vector objects, red linerc = new Rectangle(50, 50, pageWidth - 100, pageHeight - 100);graphics.DrawLine(Pens.Red, rc.Left, rc.Top, rc.Right, rc.Bottom);// blue rect somewhererc = new Rectangle(100, 100, 150, 100);graphics.FillRectangle(Brushes.Blue, rc);}return metaFile.GetHenhmetafile();}}}// GDI interop[DllImport("gdi32.dll")]private static extern int DeleteEnhMetaFile(IntPtr hemf);static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";}