Code Monkey home page Code Monkey logo

Comments (5)

ccxvii avatar ccxvii commented on June 9, 2024

Here's an example of how to rotate a page with our existing API:

const fs = require("fs")
const mupdf = require("mupdf")

var doc = mupdf.Document.openDocument(fs.readFileSync("input.pdf"), "application/pdf")
var page = doc.loadPage(0)

// Get the PDF object corresponding to the page
var page_obj = page.getObject()

// Look up the existing page rotation (inheritable from the page tree, see PDF reference for details)
var rotate = page_obj.getInheritable("Rotate")
if (!rotate)
    rotate = 0

// Update the Rotate value
page_obj.put("Rotate", rotate + 90)

// Save the changes to a new file.
fs.writeFileSync("output.pdf", doc.saveToBuffer("incremental").asUint8Array())

from mupdf.js.

jamie-lemon avatar jamie-lemon commented on June 9, 2024

I get this - why can't we bundle the 4 lines which do the work into mupdf.js as a method? So I just do e.g. page.rotate(90)

from mupdf.js.

jamie-lemon avatar jamie-lemon commented on June 9, 2024

@ccxvii When I try your code sample I get: TypeError: page.getObject is not a function

from mupdf.js.

jamie-lemon avatar jamie-lemon commented on June 9, 2024

Oh wait - I'm just appreciating the other recent commits - I'll have to package up a local mupdf node package

from mupdf.js.

jamie-lemon avatar jamie-lemon commented on June 9, 2024

@ccxvii Opening this again as in the sample code I think the rotate variable is a pointer and not a rotation value as such.
i.e.

// Look up the existing page rotation (inheritable from the page tree, see PDF reference for details)
    let rotate = page_obj.getInheritable("Rotate")
    console.log("rotate="+rotate) // rotate=11845304
    if (!rotate)
        rotate = 0

    // Update the Rotate value
    page_obj.put("Rotate", rotate + 90)

from mupdf.js.

Related Issues (20)

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.