VintaSoft Imaging .NET SDK 14.0: Documentation for .NET developer
Vintasoft.Imaging.Pdf.Processing Namespace / RemoveMarkedContentCommand Class
Members Object Syntax Example Hierarchy Requirements SeeAlso
In This Topic
    RemoveMarkedContentCommand Class
    In This Topic
    Removes marked or optional content from PDF document, PDF page or form XObject resource.
    Object Model
    PdfMarkedContentProperty RemoveMarkedContentCommand
    Syntax
    Example

    Here is an example that shows how to remove optional content groups with specified names from PDF document:

    
    ''' <summary>
    ''' Removes optional content groups with specified names from PDF document.
    ''' </summary>
    ''' <param name="inFilename">The input PDF filename.</param>
    ''' <param name="outFilename">The output PDF filename.</param>
    ''' <param name="groupNames">The names of optional content groups to remove.</param>
    Public Shared Sub RemoveOptionalContent(inFilename As String, outFilename As String, ParamArray groupNames As String())
        ' open input PDF document
        Using document As New Vintasoft.Imaging.Pdf.PdfDocument(inFilename)
            ' a list of optional content groups, which should be removed
            Dim contentGroupsToRemove As New System.Collections.Generic.List(Of Vintasoft.Imaging.Pdf.Tree.PdfMarkedContentProperty)()
            ' if PDF document has optional content groups
            If document.OptionalContentProperties IsNot Nothing AndAlso document.OptionalContentProperties.OptionalContentGroups IsNot Nothing Then
                ' for each optional content group
                For Each group As Vintasoft.Imaging.Pdf.Tree.OptionalContent.PdfOptionalContentGroup In document.OptionalContentProperties.OptionalContentGroups
                    ' if optional content group must be removed
                    If System.Array.IndexOf(groupNames, group.Name) >= 0 Then
                        ' add optional content group to the remove list
                        contentGroupsToRemove.Add(group)
                    End If
                Next
            End If
    
            ' create command for removing marked content from PDF document
            Dim removeMarkedContentCommand As New Vintasoft.Imaging.Pdf.Processing.RemoveMarkedContentCommand()
            ' specify optional content groups, which should be removed
            removeMarkedContentCommand.RemovingMarkedContent = contentGroupsToRemove.ToArray()
            ' remove optional content groups from PDF document
            removeMarkedContentCommand.Execute(document)
    
            ' save changed PDF document to the output file
            document.Pack(outFilename)
        End Using
    End Sub
    
    
    
    /// <summary>
    /// Removes optional content groups with specified names from PDF document.
    /// </summary>
    /// <param name="inFilename">The input PDF filename.</param>
    /// <param name="outFilename">The output PDF filename.</param>
    /// <param name="groupNames">The names of optional content groups to remove.</param>
    public static void RemoveOptionalContent(string inFilename, string outFilename, params string[] groupNames)
    {
        // open input PDF document
        using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument(inFilename))
        {
            // a list of optional content groups, which should be removed
            System.Collections.Generic.List<Vintasoft.Imaging.Pdf.Tree.PdfMarkedContentProperty> contentGroupsToRemove =
                new System.Collections.Generic.List<Vintasoft.Imaging.Pdf.Tree.PdfMarkedContentProperty>();
            // if PDF document has optional content groups
            if (document.OptionalContentProperties != null && document.OptionalContentProperties.OptionalContentGroups != null)
            {
                // for each optional content group
                foreach (Vintasoft.Imaging.Pdf.Tree.OptionalContent.PdfOptionalContentGroup group in document.OptionalContentProperties.OptionalContentGroups)
                {
                    // if optional content group must be removed
                    if (System.Array.IndexOf(groupNames, group.Name) >= 0)
                        // add optional content group to the remove list
                        contentGroupsToRemove.Add(group);
                }
            }
    
            // create command for removing marked content from PDF document
            Vintasoft.Imaging.Pdf.Processing.RemoveMarkedContentCommand removeMarkedContentCommand =
                new Vintasoft.Imaging.Pdf.Processing.RemoveMarkedContentCommand();
            // specify optional content groups, which should be removed
            removeMarkedContentCommand.RemovingMarkedContent = contentGroupsToRemove.ToArray();
            // remove optional content groups from PDF document
            removeMarkedContentCommand.Execute(document);
    
            // save changed PDF document to the output file
            document.Pack(outFilename);
        }
    }
    
    

    Inheritance Hierarchy

    System.Object
       Vintasoft.Imaging.Processing.ProcessingCommand<Vintasoft.Imaging.Pdf.PdfDocument>
          Vintasoft.Imaging.Pdf.Processing.RemoveMarkedContentCommand

    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