Skip to content

[suggestion] lua script #38

@atticus-sullivan

Description

@atticus-sullivan

As I read about the issues with python (and perl didn't work for me as well, so I'm also using the python script), I'm wondering whether it might make sense to either supply an additional script written in lua (or even replace the python script with it). The big advantage here would be that texlua (the lua interpreter used by luatex) comes by default with every common texlive distribution (don't know about MiKTeX or other distributions).

As far as I'm aware the only purpose of the pdfrw library is to extract specific pages to individual files (and remove them from the pdf file). Am I right about this?
in this case, I believe (still trying to figure it out, so I'm not 100% on it) this can be done completely with the libraries which come with luatex (namely pdfe, see https://mirrors.ibiblio.org/CTAN/systems/doc/luatex/luatex.pdf on page 292). This would completely avoid the need of installing any additional dependency and would ease the use/setup of memoize.

Is this a way that you think is worth further exploring? (or am I wasting my time and this won't be included anyway (would be also fine, no worries))

So far this is what I've got

local pdf = pdfe.open("./main.pdf")
print("pdf", pdf)

local page = pdfe.getpage(pdf, 1)
print("page", page, #page)
for i=1,#page,1 do
	print(i, pdfe.getfromdictionary(page, i))
end

local box = pdfe.getbox(page, "MediaBox")
print("box", box)
for k,v in pairs(box) do
	print(k,v)
end

creating a new document from one page currently doesn't work out for me, but I'm investigating

local contents, dict = pdfe.getstream(page, "Contents")
print("contents", contents, dict)
print("length", dict.Length)
print("filter", dict.Filter)
print(pdfe.openstream(page.Contents))
local str, n = pdfe.readwholestream(page.Contents)
pdfe.closestream(page.Contents)
-- print(str, n)
local doc = pdfe.new(str, n)
print(doc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions