Click or drag to resize

PdfAnnotationDataConverterConvertAnnotationDataToPdf Method

Overload List
  NameDescription
Public methodStatic memberCode exampleConvertAnnotationDataToPdf(AnnotationDataCollection, AnnotationUnit, Dpi, PdfDocumentSigner, PdfUnknownAnnotationHandler)
Converts a multiple pages of annotations for PdfDocumentSigner.
Examples
In the following example, annotations are converted for use in the PdfDocumentSigner.
ConvertAnnotationsForPdfDocumentSignerExample
var rectData = new RectangleData()
{
    Size = new SizeF(123, 345),
    Location = new PointF(123, 321),
    Fill = new AnnotationBrush(Color.FromArgb(255, 64, 128, 255)),
    Outline = new AnnotationPen(Color.FromArgb(255, 128, 128, 128))
};
var polyData = new PolygonData()
{
    Size = new SizeF(100, 200),
    Location = new PointF(10, 11),
    Fill = new AnnotationBrush(Color.FromArgb(255, 64, 128, 255)),
    Outline = new AnnotationPen(Color.FromArgb(255, 128, 128, 128))
};
polyData.Points.AddRange(new[] { new PointF(1, 1), new PointF(50, 50), new PointF(1, 50) });


var collection = new AnnotationDataCollection() { new LayerData() { Items = { rectData, polyData } } };
var dpis = new[] { new Dpi(96, 96, ResolutionUnit.DotsPerInch) };
var signer = new PdfDocumentSigner(pdfStream, null);

var pagesOfAnnots =
    PdfAnnotationDataConverter.ConvertAnnotationDataToPdf(collection, AnnotationUnit.Pixel, dpis,
        signer);

for (var i = 0; i < pagesOfAnnots.Count; i++)
    foreach (var annotation in pagesOfAnnots[i])
        signer.PagesOfAnnotations[i].Add(annotation);

signer.AppendChangesFinal(true);
Public methodStatic memberCode exampleConvertAnnotationDataToPdf(LayerData, AnnotationUnit, Dpi, PdfGeneratedPage, GlobalResources, PdfUnknownAnnotationHandler)
Converts a page of annotations to PDF annotations.
Examples
In the following example, annotations are converted for use in the PdfGeneratedPage.
ConvertAnnotationsForPdfGeneratedPageExample
var rectData = new RectangleData()
{
    Size = new SizeF(123, 345),
    Location = new PointF(123, 321),
    Fill = new AnnotationBrush(Color.FromArgb(255, 64, 128, 255)),
    Outline = new AnnotationPen(Color.FromArgb(255, 128, 128, 128))
};
var polyData = new PolygonData()
{
    Size = new SizeF(100, 200),
    Location = new PointF(10, 11),
    Fill = new AnnotationBrush(Color.FromArgb(255, 64, 128, 255)),
    Outline = new AnnotationPen(Color.FromArgb(255, 128, 128, 128))
};
polyData.Points.AddRange(new[] { new PointF(1, 1), new PointF(50, 50), new PointF(1, 50) });


var layer = new LayerData() { Items = { rectData, polyData } };
var dpi = new Dpi(96, 96, ResolutionUnit.DotsPerInch);
var doc = new PdfGeneratedDocument(source);
var page = doc.Pages[0] as PdfGeneratedPage;

if (page != null)
{
    var annotations =
        PdfAnnotationDataConverter.ConvertAnnotationDataToPdf(layer, AnnotationUnit.Pixel, dpi, page,
            doc.Resources);
    page.Annotations.AddRange(annotations);
}

doc.Save(pdfStream);
Public methodStatic memberCode exampleConvertAnnotationDataToPdf(LayerData, AnnotationUnit, Dpi, RectangleF, PdfPageRotation, GlobalResources, PdfUnknownAnnotationHandler)
Converts a page of annotations to PDF annotations.
Examples
ConvertAnnotationsToPdfAnnotationsExample
var rectData = new RectangleData()
{
    Size = new SizeF(123, 345),
    Location = new PointF(123, 321),
    Fill = new AnnotationBrush(Color.FromArgb(255, 64, 128, 255)),
    Outline = new AnnotationPen(Color.FromArgb(255, 128, 128, 128))
};
var polyData = new PolygonData()
{
    Size = new SizeF(100, 200),
    Location = new PointF(10, 11),
    Fill = new AnnotationBrush(Color.FromArgb(255, 64, 128, 255)),
    Outline = new AnnotationPen(Color.FromArgb(255, 128, 128, 128))
};
polyData.Points.AddRange(new[] { new PointF(1, 1), new PointF(50, 50), new PointF(1, 50) });


var layer = new LayerData() { Items = { rectData, polyData } };
var dpi = new Dpi(96, 96, ResolutionUnit.DotsPerInch);
var doc = new PdfGeneratedDocument(source);
var page = doc.Pages[0] as PdfGeneratedPage;

if (page != null)
{
    var cropBox = page.CropBox.IsEmpty() ? page.MediaBox.ToRectangleF() : page.CropBox.ToRectangleF();
    var rotation = page.Rotation;
    var annotations = PdfAnnotationDataConverter.ConvertAnnotationDataToPdf(layer, AnnotationUnit.Pixel,
        dpi, cropBox, rotation, doc.Resources);
    page.Annotations.AddRange(annotations);
}

doc.Save(pdfStream);
Top
See Also