0.3.1 • Published 11 months ago

pdf-reorganizer v0.3.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
11 months ago

pdf-reorganizer

pdf-reorganizer

pdf-reorganizer is a web component to help rearrange and split PDFs. It does not modify PDF documents itself, but creates a processing instruction that can be implemented independent of PDF processing APIs or programming languages. pdf-reorganizer is heavily inspired by PDF-Arranger and is based on PDF.js.

Reorganization supports:

  • Splits
  • Removals
  • Movements
  • Rotations

Integration

Install the package:

npm i pdf-reorganizer

Import the package in your code:

<html>
  <head>
    <script type="module">
      import 'pdf-reorganizer';
    </script>
  </head>
  <body>
    <pdf-reorganizer url="example.pdf"></pdf-reorganizer>
  </body>
</html>

Usage

Key Bindings

In Reorganizer Viewport:

KeyModifierCommand
rightMove cursor to next page
leftMove cursor to previous page
topMove cursor to page above in viewport
downMove cursor to page below in viewport
rightCtrlRotate page on cursor position 90deg clockwise
leftCtrlRotate page on cursor position 90deg counter clockwise
rightCtrl+ShiftRotate selected pages 90deg clockwise
leftCtrl+ShiftRotate selected pages 90deg counter clockwise
rightAltChoose preceding target to move selected pages (requires confirmation)
leftAltChoose following target to move selected pages (requires confirmation)
DeleteRemove page on cursor position (If no cursor exists, remove all selected)
DeleteShiftRemove all selected pages
SpaceAdd page on cursor to the selection or remove from it
sCtrlAdd split before page on cursor (If no cursor exists, add split before selected pages)
s/SCtrl+ShiftAdd split before selected pages
+CtrlOpen magnified view on cursor
aCtrlSelect all pages
dCtrlUnselect all pages
i/ICtrl+ShiftInverse select all pages
cCtrlAdd comment to the page on cursor or edit
EnterConfirm moving selected pages

In magnified view:

KeyModifierCommand
rightMove viewport right
leftMove viewport left
topMove viewport up
downMove viewport down
rightCtrlMove viewport to the right
leftCtrlMove viewport to the left
topCtrlMove viewport to up
downCtrlMove viewport to bottom
EscapeLeave magnifier view

Processing instructions

After reorganizing all pages into new documents, the processed custom event is dispatched. This event can be listened on and contains a docs list and a src list in its detail object.

{
  "src" : [
    "mysimple.pdf"
  ],
  "docs" : [
    [1, 2],
    [3, { "p":5, "r":90 }],
    [{
      "p":6,
      "c":"This is a comment"
    }]
  ]
}

The docs array contains a list of documents resulting from the reorganization of the source documents (listed in src). Each document is represented by a list of page numbers.

If pages were modified or annotated, they are represented as a map with the following keys supported:

p: Mandatory. The page number.

r: Optional. The page was rotated (clockwise by 90, 180 or 270 degrees).

c: Optional. A comment on the page.

s: Optional. The index to the source document in the src list. Defaults to 0.

Customization

Configuration

The following parameters can be defined as part of the pdf-reorganizer element.

AttributeDescription
urlThe url of the PDF document. Can alos be represented as a Int array. Mandatory.
filenameThe file name for source attribution. Uses the URL base name if not given.
zoomfactorThe scale for the magnifier view. Defaults to 6.
scrollstepThe number of pixels to scroll by arrow keys in magnifier view. Defaults to 14.

Styling

The following CSS variables can be overwritten and are resepected by the web component. It's best to overwrite them in a pdf-reorganizer selector rule.

pdf-reorganizer {

  /* Main color for fonts and borders */
  --pdfro-main-color: #555;
  
  /* Colors for selected pages */
  --pdfro-selected-color: #fff;
  --pdfro-selected-bg-color: #07d;
  
  /* Colors for the split marker */
  --pdfro-split-marker-border-color: #696;
  --pdfro-split-marker-bg-color: #6b6;
  --pdfro-split-marker-counter-color: #fff;

  /* Color of the load spinner */
  --pdfro-loader-color: blue;

  /* Color of removed pages */
  --pdfro-removed-bg-color: #777;

  /* Color of highlighted pages for mouseover */
  --pdfro-hover-bg-color: #aaa;
  
  /* Color of dragged pages and drag-markers */
  --pdfro-dragged-color: #7bf;

  /* Colors for navigation menu */
  --pdfro-nav-bg-color: #fff;
  --pdfro-nav-color: var(--pdfro-main-color);
}

Planned Features

  • Copy instead of moving
  • Add files per drag and drop (if embedded in a service)
  • Add select mode on long press (mousedown and touchstart)

Known issues

  • When height and width of a page are switches after rotation, the magnified view has an empty offset at the bottom of a page.
  • hdpi doesn't properly work across browsers.

License

This software bundles Material Symbols from Google, published under the Apache License 2.0.

0.3.1

11 months ago

0.3.0

12 months ago

0.2.0

12 months ago

0.1.4

12 months ago

0.1.3

12 months ago