VintaSoft Imaging .NET SDK v9.1 for .NET
Vintasoft.Imaging.Pdf.Tree Namespace / PdfTreeNodeBase Class / GetLinearizedSubtree Method / GetLinearizedSubtree(IActionProgressController,PredicateAnalyzer<PdfTreeNodeBase>) Method
The progress controller.
Predicate that defines tree nodes that must be contained by linearized subtree.
Example



In This Topic
    GetLinearizedSubtree(IActionProgressController,PredicateAnalyzer<PdfTreeNodeBase>) Method
    In This Topic
    Returns linearized subtree that starts from current node and contains only nodes that allowed by predicate.
    Syntax

    Parameters

    progressController
    The progress controller.
    predicate
    Predicate that defines tree nodes that must be contained by linearized subtree.

    Return Value

    Linearized subtree.
    Remarks
    If predicate is not given, method returns all subnodes.
    Example
    Here is an example that shows how to get all PdfResource nodes with ZIP compression:
    ''' <summary> 
    ''' A predicate that checks taget compression type.
    ''' </summary>
    Public Class ResourceCompressionAnalyzer
    	Inherits Vintasoft.Imaging.Processing.Analyzers.PredicateAnalyzer(Of Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase)
                
    	''' <summary>
    	''' Compression types, which should be analyzed.
    	''' </summary>
    	Private _compressions As Vintasoft.Imaging.Pdf.PdfCompression()
                
                
                
    	''' <summary>
    	''' Initializes a new instance of the <see cref="ResourceCompressionAnalyzer"/> class.
    	''' </summary>
    	''' <param name="compressions">Compression types, which should be analyzed.</param>
    	Public Sub New(compressions As Vintasoft.Imaging.Pdf.PdfCompression())
    		MyBase.New("PDF resource compression analyzer")
    		_compressions = compressions
    	End Sub
                
                
                
    	''' <summary>
    	''' Returns all nodes that are <see cref="Vintasoft.Imaging.Pdf.Tree.PdfResource"/>
    	''' with ZIP compression.
    	''' </summary>
    	''' <param name="document">A PDF document.</param>
    	''' <returns>
    	''' All <see cref="Vintasoft.Imaging.Pdf.Tree.PdfResource"/>
    	''' with ZIP compression.
    	''' </returns>
    	Public Function GetPdfResourcesWithZipCompression(document As Vintasoft.Imaging.Pdf.PdfDocument) As Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase()
    		Dim compressions As Vintasoft.Imaging.Pdf.PdfCompression() = New Vintasoft.Imaging.Pdf.PdfCompression() {Vintasoft.Imaging.Pdf.PdfCompression.Zip}
                
    		Return document.Catalog.GetLinearizedSubtree(New ResourceCompressionAnalyzer(compressions))
    	End Function
                
                
    	''' <summary>
    	''' Analyzes the specified target.
    	''' </summary>
    	''' <param name="target">The target object.</param>
    	''' <returns>
    	''' Logical result of analysis.
    	''' </returns>
    	Protected Overrides Function Analyze(target As Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase) As Boolean
    		' if target is PdfResource
    		If TypeOf target Is Vintasoft.Imaging.Pdf.Tree.PdfResource Then
    			' get PDF resource compression
    			Dim pdfResourceCompression As Vintasoft.Imaging.Pdf.PdfCompression = DirectCast(target, Vintasoft.Imaging.Pdf.Tree.PdfResource).Compression
                
    			' for each compression type, which should be analyzed
    			For Each compression As Vintasoft.Imaging.Pdf.PdfCompression In _compressions
    				' if PDF resource uses compression
    				If pdfResourceCompression = compression Then
    					Return True
    				End If
    			Next
    		End If
    		Return False
    	End Function
    End Class
    /// <summary> 
    /// A predicate that checks taget compression type.
    /// </summary>
    public class ResourceCompressionAnalyzer : Vintasoft.Imaging.Processing.Analyzers.PredicateAnalyzer<Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase>
    {
                
        /// <summary>
        /// Compression types, which should be analyzed.
        /// </summary>
        Vintasoft.Imaging.Pdf.PdfCompression[] _compressions;
                
                
                
        /// <summary>
        /// Initializes a new instance of the <see cref="ResourceCompressionAnalyzer"/> class.
        /// </summary>
        /// <param name="compressions">Compression types, which should be analyzed.</param>
        public ResourceCompressionAnalyzer(Vintasoft.Imaging.Pdf.PdfCompression[] compressions)
            : base("PDF resource compression analyzer")
        {
            _compressions = compressions;
        }
                
                
                
        /// <summary>
        /// Returns all nodes that are <see cref="Vintasoft.Imaging.Pdf.Tree.PdfResource"/>
        /// with ZIP compression.
        /// </summary>
        /// <param name="document">A PDF document.</param>
        /// <returns>
        /// All <see cref="Vintasoft.Imaging.Pdf.Tree.PdfResource"/>
        /// with ZIP compression.
        /// </returns>
        public Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase[] GetPdfResourcesWithZipCompression(Vintasoft.Imaging.Pdf.PdfDocument document)
        {
            Vintasoft.Imaging.Pdf.PdfCompression[] compressions = new Vintasoft.Imaging.Pdf.PdfCompression[] {
                Vintasoft.Imaging.Pdf.PdfCompression.Zip 
            };
                
            return document.Catalog.GetLinearizedSubtree(
                new ResourceCompressionAnalyzer(compressions));
        }
                
                
        /// <summary>
        /// Analyzes the specified target.
        /// </summary>
        /// <param name="target">The target object.</param>
        /// <returns>
        /// Logical result of analysis.
        /// </returns>
        protected override bool Analyze(Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase target)
        {
            // if target is PdfResource
            if (target is Vintasoft.Imaging.Pdf.Tree.PdfResource)
            {
                // get PDF resource compression
                Vintasoft.Imaging.Pdf.PdfCompression pdfResourceCompression =
                    ((Vintasoft.Imaging.Pdf.Tree.PdfResource)target).Compression;
                
                // for each compression type, which should be analyzed
                foreach (Vintasoft.Imaging.Pdf.PdfCompression compression in _compressions)
                {
                    // if PDF resource uses compression
                    if (pdfResourceCompression == compression)
                        return true;
                }
            }
            return false;
        }
    }
    Requirements

    Target Platforms: .NET 5 Preview 7; .NET Core 3.1; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also