''' <summary>
''' Creates PDF document with the optional content.
''' </summary>
''' <param name="pdfFilename">The PDF filename.</param>
Public Shared Sub CreateDocumentWithOptionalContent(pdfFilename As String)
' create new PDF document
Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename, Vintasoft.Imaging.Pdf.PdfFormat.Pdf_16)
' add empty page (A4 size)
Dim page As Vintasoft.Imaging.Pdf.Tree.PdfPage = document.Pages.Add(Vintasoft.Imaging.PaperSizeKind.A4)
' create two optional content groups
Dim layer1 As New Vintasoft.Imaging.Pdf.Tree.OptionalContent.PdfOptionalContentGroup(document, "Layer1")
Dim layer2 As New Vintasoft.Imaging.Pdf.Tree.OptionalContent.PdfOptionalContentGroup(document, "Layer2")
' add optional content groups to OptionalContentProperties
document.OptionalContentProperties = New Vintasoft.Imaging.Pdf.Tree.OptionalContent.PdfOptionalContentProperties(document)
document.OptionalContentProperties.OptionalContentGroups.Add(layer1)
document.OptionalContentProperties.OptionalContentGroups.Add(layer2)
' get PdfGraphics for PDF page
Using g As Vintasoft.Imaging.Pdf.Drawing.PdfGraphics = page.GetGraphics()
Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
Dim brush As New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Black)
Dim brush1 As New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Green)
Dim brush2 As New Vintasoft.Imaging.Pdf.Drawing.PdfBrush(System.Drawing.Color.Red)
' draw not optional content
g.DrawString("Not optional content", font, 20, brush, New System.Drawing.PointF(50, 650))
' draw optional content "Layer1"
g.BeginOptionalContent(layer1)
g.DrawString(String.Format("Optional content '{0}'", layer1.Name), font, 25, brush1, New System.Drawing.PointF(50, 550))
g.EndOptionalContent()
' draw not optional content
g.DrawString("Not optional content", font, 30, brush, New System.Drawing.PointF(50, 450))
' draw optional content "Layer2"
g.BeginOptionalContent(layer2)
g.DrawString(String.Format("Optional content '{0}'", layer2.Name), font, 35, brush2, New System.Drawing.PointF(50, 350))
g.EndOptionalContent()
' draw not optional content
g.DrawString("Not optional content", font, 40, brush, New System.Drawing.PointF(50, 250))
End Using
' create optional content configurations
Dim configuration1 As New Vintasoft.Imaging.Pdf.Tree.OptionalContent.PdfOptionalContentConfiguration(document, "Layer1 and Layer2")
configuration1.SetGroupVisibility(layer1, True)
configuration1.SetGroupVisibility(layer2, True)
Dim configuration2 As New Vintasoft.Imaging.Pdf.Tree.OptionalContent.PdfOptionalContentConfiguration(document, "Layer1")
configuration2.SetGroupVisibility(layer1, True)
configuration2.SetGroupVisibility(layer2, False)
Dim configuration3 As New Vintasoft.Imaging.Pdf.Tree.OptionalContent.PdfOptionalContentConfiguration(document, "Layer2")
configuration3.SetGroupVisibility(layer1, False)
configuration3.SetGroupVisibility(layer2, True)
Dim configuration4 As New Vintasoft.Imaging.Pdf.Tree.OptionalContent.PdfOptionalContentConfiguration(document, "No Layers")
configuration4.SetGroupVisibility(layer1, False)
configuration4.SetGroupVisibility(layer2, False)
' create list of optional content configuration
document.OptionalContentProperties.Configurations = New Vintasoft.Imaging.Pdf.Tree.OptionalContent.PdfOptionalContentConfigurationList(document)
' add configurations to list
document.OptionalContentProperties.Configurations.Add(configuration1)
document.OptionalContentProperties.Configurations.Add(configuration2)
document.OptionalContentProperties.Configurations.Add(configuration3)
document.OptionalContentProperties.Configurations.Add(configuration4)
' set default configuration
document.OptionalContentProperties.DefaultConfiguration = configuration1
' set presentation order
configuration1.PresentationOrder = New Vintasoft.Imaging.Pdf.Tree.OptionalContent.PdfOptionalContentPresentationOrder(document, layer1, layer2)
' optional content panel is visible
document.DocumentViewMode = Vintasoft.Imaging.Pdf.PdfDocumentViewMode.UseOC
' save changes in PDF document
document.SaveChanges()
End Using
End Sub