From: Pablo Rodriguez <oinos@gmx.es>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: filtering pages from /PrintPageRange
Date: Fri, 17 Apr 2020 00:13:16 +0200 [thread overview]
Message-ID: <25b0401b-15e8-0970-1e4b-5fb8614ccb54@gmx.es> (raw)
Dear list,
this is a new experience deep inside LuaMetaTeX (for me).
I need to compose a new document from selected pages (which are marked
automatically and stored in /PrintPageRange) in a PDF document
containing 1000 pages.
It has to be one of the worst coding snippets ever written, but it
works. It reads the array from /PrintPageRange, deploying it in
context.filterpages.
\startluacode
function document.printrange_from_file(filename)
range_array =
pdfe.open(filename).Catalog.ViewerPreferences.PrintPageRange
for i=1,#range_array do
file_page = range_array[i]
if file_pagerange == nil then
file_pagerange = file_page
else
file_pagerange = file_pagerange .. " " .. file_page
end
end
for str in file_pagerange:gmatch("([^%s]+)") do
add_one = str + 1
if right_range == nil then
right_range = add_one
else
right_range = right_range .. " " .. add_one
end
end
spaces_in_pagerange = right_range:find(' ')
local _, spaces_in_pagerange = right_range:gsub(" ", "")
for actualspace=1,spaces_in_pagerange do
if (actualspace % 2 == 0) then
right_range = right_range:gsub(' ',',', 1)
else
right_range = right_range:gsub(' ',':', 1)
end
end
context.filterpages( { filename }, { right_range },
{ width = Opt } )
end
\stopluacode
\def\filterfrompagerange[#1]{%
\ctxlua{document.printrange_from_file("#1")}}
\setuplayout[page]
\setupinteractionscreen[option={portrait, paper}]
\starttext
\filterfrompagerange[huge-book.pdf]
\stoptext
I copied and adapted all from Stackoverflow snippets.
It is useful for me, since it file will be changing, page marking is
automatic and filtering marked pages will be automatic too.
But I wonder whether this may be useful to others. I wonder whether it
makes sense to add it to the wiki.
Let me know what you think about
--
http://www.ousia.tk
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
reply other threads:[~2020-04-16 22:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=25b0401b-15e8-0970-1e4b-5fb8614ccb54@gmx.es \
--to=oinos@gmx.es \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).