Skip to content

Ordered Output of Split Pages #25

Open
@TheOwl57

Description

@TheOwl57

Awesome module which I have used to sort through large PDF files at incredible speeds.

First time posting anything on GitHub, so I hope this is acceptable.

Only issue I have is when splitting documents with a large amount of pages, the naming convention of the [CustomeSplitter] Class names the file based on the page number. This can make it hard to then correctly read through split files in order.

Suggest expanding the file name to include leading zeros. I have successfully been able to modify the [CustomSplitter] Class to do this with the below code:

class CustomSplitter : iText.Kernel.Utils.PdfSplitter {
    [int] $_order
    [string] $_destinationFolder
    [string] $_outputName

    CustomSplitter([iText.Kernel.Pdf.PdfDocument] $pdfDocument, [string] $destinationFolder, [string] $OutputName) : base($pdfDocument) {
        $this._destinationFolder = $destinationFolder
        $this._order = 1
        $this._outputName = $OutputName
    }

    [iText.Kernel.Pdf.PdfWriter] GetNextPdfWriter([iText.Kernel.Utils.PageRange] $documentPageRange) {
        $Name = -join ($this._outputName, $this._order.ToString("D4"), ".pdf")
        $Path = [IO.Path]::Combine($this._destinationFolder, $Name)
        $this._order++
        return [iText.Kernel.Pdf.PdfWriter]::new($Path)
    }
}

"$this._order = 1" as a start for page 1.
"$this._order.ToString("D4")" will handle files that are up to 9999 pages long, so shouldn't push the limits too often.
"$this._order++" to increment to the next page number.

Ideally if I had time, I would expand this to look at the file prior to splitting to get the total amount of pages and adjust how many leading zeros are required so that the naming convention was dynamic based on the content at the time.

Tested this to work with both 0.0.10 and 0.0.17.

Thanks again for the module.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions