ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* filtering pages from /PrintPageRange
@ 2020-04-16 22:13 Pablo Rodriguez
  0 siblings, 0 replies; only message in thread
From: Pablo Rodriguez @ 2020-04-16 22:13 UTC (permalink / raw)
  To: mailing list for ConTeXt users

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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-04-16 22:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-16 22:13 filtering pages from /PrintPageRange Pablo Rodriguez

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).