GithubHelp home page GithubHelp logo

pdfy's Introduction

PDFy

WIP, some small utils for dealing with pdfs in f# using PDFKit

Example

to read all annotations, filter hotspots named Title1 and print

cocoaInit()

(openDocument >> getAnnotationsFromDocument) "test.pdf"
|> List.filter(PDFAnnotation.isHotspot) 
|> List.filter(PDFAnnotation.hotspotRegex (new Regex("^Title1$")))
|> List.iter (fun x -> printfn "Found: Page: %i with %s on test.pdf." (x.index) (x.hotspot))

to rename a set of hotspots

(openDocument >> searchForAnnotations searchterm) "test.pdf"
|> List.map(fun annotation -> 
    annotation.hotspot <- replacewith
    printfn "Replaced: %s with %s on page %i of test.pdf" searchterm replacewith annotation.index
    annotation.document)
|> List.head
|> saveDocument output

Scripts

inside the PDFy directory there is four scripts, pdfgrep.fsx, pdfreplace.fsx, pdftojson.fsx and pdffromjson.fsx

pdftojson.fsx and pdffromjson.fsx serialize the annotations on a pdf, and are able to create new pdf's from the exported json.

pdfgrep accepts a filename and regex and returns the results per page of hits, ie

PDFy/pdfgrep.fsx ~/Desktop/wah.pdf ".*"
Found: Page: 0 with OtherStoryImage1 on /Users/ashleyis/Desktop/wah.pdf
Found: Page: 0 with OtherStoryImage2 on /Users/ashleyis/Desktop/wah.pdf
Found: Page: 0 with OtherStoryImage3 on /Users/ashleyis/Desktop/wah.pdf
Found: Page: 0 with OtherStoryImage4 on /Users/ashleyis/Desktop/wah.pdf
Found: Page: 0 with OtherStoryImage5 on /Users/ashleyis/Desktop/wah.pdf
...

pdfreplace accepts a input filename, output filename, a search term and the replacement string and returns the results of replaced items, ie

PDFy/pdfreplace.fsx ~/Desktop/wah.pdf test.pdf OtherStoryTitle1 OtherStoryBigTitle1
Replaced: OtherStoryTitle1 with OtherStoryBigTitle1 on page 0 of /Users/ashleyis/Desktop/wah.pdf

pdfy's People

Contributors

aktowns avatar

Stargazers

Brad Pillow avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

pdfy's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.