BeginMarkedContent(String) Method (PdfGraphics)
In This Topic
Begins a marked-content sequence in the content stream.
Syntax
'Declaration
Public Overloads Sub BeginMarkedContent( _
ByVal As System.String _
)
public void BeginMarkedContent(
System.String
)
public: void BeginMarkedContent(
System.String
)
public:
void BeginMarkedContent(
System.String
)
Parameters
- tag
- A name object indicating the role or significance of the sequence.
Example
Here is an example that shows how to create a tagged PDF with marked text clip:
''' <summary>
''' Creates a tagged PDF document with marked text clip.
''' </summary>
Public Shared Sub CreateTaggedPdfWithClippedText()
' create new PDF document
Using document As New Vintasoft.Imaging.Pdf.PdfDocument()
' add new page to the PDF document
document.Pages.Add(New System.Drawing.SizeF(250, 250))
' create marked information object
Dim markInfo As New Vintasoft.Imaging.Pdf.Tree.PdfMarkInformation(document)
markInfo.IsMarked = True
' add marked information object to the PDF document
document.MarkedInformation = markInfo
' get graphics object associated with page
Using graphics As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = document.Pages(0).GetGraphics()
' begin the marked content
graphics.BeginMarkedContent("ClipText")
' save the graphics state
graphics.SaveGraphicsState()
' update the clip region
graphics.IntersectClip(New System.Drawing.RectangleF(0, 50, 100, 100))
' get the PDF font
Dim pdfFont As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
' draw a text string
graphics.DrawString("Text string", pdfFont, 30, New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Green), New System.Drawing.PointF(25, 100))
' restore graphics state
graphics.RestoreGraphicsState()
' end the marked content
graphics.EndMarkedContent()
End Using
' save document
document.SaveChanges("D:\testTaggedPdf.pdf")
End Using
End Sub
/// <summary>
/// Creates a tagged PDF document with marked text clip.
/// </summary>
public static void CreateTaggedPdfWithClippedText()
{
// create new PDF document
using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument())
{
// add new page to the PDF document
document.Pages.Add(new System.Drawing.SizeF(250, 250));
// create marked information object
Vintasoft.Imaging.Pdf.Tree.PdfMarkInformation markInfo =
new Vintasoft.Imaging.Pdf.Tree.PdfMarkInformation(document);
markInfo.IsMarked = true;
// add marked information object to the PDF document
document.MarkedInformation = markInfo;
// get graphics object associated with page
using (Vintasoft.Imaging.Pdf.Drawing.PdfGraphics graphics = document.Pages[0].GetGraphics())
{
// begin the marked content
graphics.BeginMarkedContent("ClipText");
// save the graphics state
graphics.SaveGraphicsState();
// update the clip region
graphics.IntersectClip(new System.Drawing.RectangleF(0, 50, 100, 100));
// get the PDF font
Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont pdfFont = document.FontManager.GetStandardFont(
Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
// draw a text string
graphics.DrawString(
"Text string",
pdfFont,
30,
new Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Green),
new System.Drawing.PointF(25, 100));
// restore graphics state
graphics.RestoreGraphicsState();
// end the marked content
graphics.EndMarkedContent();
}
// save document
document.SaveChanges(@"D:\testTaggedPdf.pdf");
}
}
Requirements
Target Platforms: .NET9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
See Also