This is a tool that rearranges PDFs using only client side JS.
- Importing
PDFDocument
frompdf-lib
for PDF manipulation. - Importing
pdfjsLib
andpdfWorker
frompdfjs-dist
for PDF rendering. - Importing
create
fromzustand
for state management. - Using
shadcn-ui
for components
-
PDFPage
: Defines a single page in a PDF.id
: Unique identifier for the page.imageData
: Base64-encoded image data.originalPageNumber
: The page number in the original PDF.
-
PDFList
: Defines a list ofPDFPage
objects.id
: Unique identifier for the list.pages
: Array ofPDFPage
.
-
ImportStore
: Zustand state shape.- State variables:
pdfLists
,pdfBase64
,pdfBuffer
,isLoadingThumbnail
,isDoingExtraction
. - Actions: Functions for state manipulation like
setOriginalList
,setPdfLists
, etc.
- State variables:
- Initializes with default state.
- Provides various methods for state manipulation and PDF operations.
-
setOriginalList
:- Takes a base64 PDF string.
- Creates a PDF list with thumbnails for each page.
-
setPdfLists
: Sets thepdfLists
state. -
downloadAllPdfs
anddownloadSinglePdf
:- Downloads selected PDFs.
- Utilizes
createPdfFromList
for the actual PDF creation.
-
addBlankPDF
: Adds a new empty PDF list. -
clearAll
: Clears all state to initial state. -
resetToOriginal
: Resets to the original list based onpdfBase64
. -
changeNameOfList
: Changes the name (id) of a given list. -
splitEveryPageIntoOwnPdf
: Splits each page of the original PDF into its own new PDF. -
removeSingleList
: Removes a single list by its ID.
createPdfFromList
: Creates a new PDF based on a givenPDFList
and original PDF document.pause
: Utility to pause execution.
- The code primarily revolves around PDF manipulation using PDF.js for rendering and pdf-lib for operations like splitting, downloading, etc.
- It uses Zustand for managing the state of PDF lists and associated data.
This project was copied from another one built with the T3 stack. Changes below were needed to get to a simple client only application.
- Remove prisma - no database
- Remove
postinstall
script that ran prisma - Clear out extra pages in
app
- keep just the root - Remove extra comps - keep
- ui
- common
- Table
- nav
- Remove trpc and auth from the
pages/api
- do not need for client only - Delete most lib related stuff - keep
- Non finance helpers
- utils
- Delete the
server
folder and all of its code