[]
        
(Showing Draft Content)

PDF Organizer

DsPdfViewer provides PDF Organizer toolbar button that allows a user to reorder and reorganize the pages in a PDF document using individual page numbers or page ranges. This button also allows a user to merge pages from two different PDFs and split a PDF into multiple different PDFs.

The PDF Organizer toolbar button is present in the following toolbar layouts:

  • Page Tools


  • Annotation Editor


  • Form Editor


When the user clicks the PDF Organizer toolbar button, the following dialog appears:


The following table lists the features provided by the PDF Organizer toolbar button.

Features

Icons

Description

Add Page Ranges


Allows a user to add a single page ranges, all pages range, odd pages range, even pages range, each page size/orientation range, an empty page range, or a custom range from the active PDF document.

Merge External PDF


Allows a user to add a single page or page ranges from external PDF document to the end of an active PDF document.

Clear


Allows a user to clear all the ranges.

Download


Allows a user to download the organized PDF document to the computer’s local file system.

Done


Allows a user to apply changes and close the PDF Organizer dialog.


Note: After applying the changes to the active PDF document, it is not possible to revert back to the previous state.

The viewer will load the modified PDF document with the new page structure.

Cancel


Allows a user to close the PDF Organizer dialog and cancel any changes made to the structure of the PDF document.

Split Range


Allows a user to split a page range into single pages.

Remove Range


Allows a user to remove a page or a page range from the PDF Organizer dialog.

Clone Range


Allows a user to clone the page or page range.

Rotate Range


Allows a user to rotate a page or a page range by 90 degrees from the PDF Organizer dialog.

Information


Displays a user the information about a page or a page range.

Input Field


Allows a user to specify the start and end page numbers for a specific page range. Pressing “Enter” accepts the new value.

Pressing “Escape” resets the range value to the previous one.

!type=note

Note: The PDF Organizer also allows a user to reorder a single page or a page range by clicking on the page preview and dragging and dropping the page or range.

The following table lists the Add Page Ranges dropdown menu options:


Add Page Ranges Dropdown Menu Options

Description

Resulting Range

Single pages

Allows a user to create a range for each page and provides maximum flexibility to manipulate individual pages.


All pages

Allows a user to create one range for all pages and also allows manipulating all pages together as a single unit.


Odd pages

Allows a user to create a range that includes all odd pages.


Even pages

Allows a user to create a range that includes all even pages.


Page size

Allows a user to create a range for each page size and orientation.


Empty page

Allows a user to create a range with a new empty page.


Custom

Allows a user to create custom ranges from page numbers based on the input.


!type=note

Note: The key for PDF Organizer button is pdf-organizer which can be used to customize the toolbar.

Reorder PDF Document

PDF Organizer allows a user to reorder and reorganize a PDF document by modifying the page number or page range in the input field or by dragging and dropping a page or page range into the required place.


DsPdfViewer also allows a user to reorder a PDF document using code. Refer to the following example code to reorder a PDF document:

await viewer.save("test_changed_order.pdf", { pages: "3, 2, 1, 0" });

Split PDF Document

PDF Organizer allows a user to split a PDF document into different PDF documents by modifying the page number or page range in the input field.


DsPdfViewer also allows a user to split a PDF document by page numbers or size using code. Refer to the following example code to split a PDF document by page numbers:

await viewer.save("part1.pdf", { pages: "0-3" });
await viewer.save("part2.pdf", { pages: "4-8" });
await viewer.save("part3.pdf", { pages: "9-11" });

Refer to the following example code to split a PDF document by size:

async function splitPdfBySize(partSizeKb)
{
    const fileSizeBytes = await viewer.fileSize, fileSizeKb = fileSizeBytes / 1024,
          partCount = Math.floor(fileSizeKb / partSizeKb), pageCount = viewer.pageCount;
    if (pageCount > partCount)
    {
        let nextPageIndex = 0;
        for (let i = 0; i < partCount; i++)
        {
            const startIndex = nextPageIndex ? (nextPageIndex + 1) : 0;
            nextPageIndex = i === partCount - 1 ? pageCount - 1 : startIndex + Math.floor(pageCount / partCount);
            await viewer.save(`part -${ i + 1}.pdf`, { pages: `${ startIndex} -${ nextPageIndex}` });
        }
    }   
    else {
          await viewer.save("all-in-one.pdf");
         }
}
// Split the PDF by approximately 300 KB.
await splitPdfBySize(300);

Merge PDF Documents

PDF Organizer allows a user to merge an external PDF document with the PDF document opened in the DsPdfViewer. The user can reorder the pages or select the number of pages to be added to the new PDF document.


DsPdfViewer also allows a user to merge PDF documents using code. Refer to the following example code to merge PDF documents:

// Merge the first page from an external PDF document to the end of the active PDF document.
const fileId = "uniquefileid1";
viewer.storage.setItem(fileId, new Uint8Array(fileReader.result));
await viewer.save("test_part10.pdf", { pages: `0 -${ viewer.pageCount - 1}, [file:${ fileId}]0` });

!type=note

Note: SupportApi should be configured in order to edit a PDF document using PDF Organizer button, and SupportApi is only available with the Professional License of DsPdfViewer. For more information, see Configure Server-Based PDF Editor.