VintaSoft Imaging .NET SDK 15.0: Документация для .NET разработчика
Vintasoft.Imaging.Pdf.Processing Namespace / RemoveMarkedContentCommand Class
Члены типа Объект Синтаксис Example Иерархия Требования Смотрите также
В этом разделе
    Класс RemoveMarkedContentCommand
    В этом разделе
    Удаляет отмеченное или необязательное содержимое из PDF документа, PDF страницы или ресурса XObject формы.
    Объектная модель
    PdfMarkedContentProperty RemoveMarkedContentCommand
    Синтаксис
    Пример

    Вот пример, показывающий, как удалить необязательные группы содержимого с указанными именами из PDF документа:

    
    ''' <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);
        }
    }
    
    

    Иерархия наследования

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

    Требования

    Целевые платформы: .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также