From: <denis.maier@ub.unibe.ch>
To: <ntg-context@ntg.nl>
Subject: Re: outputting components in their own PDFs
Date: Mon, 1 Mar 2021 22:07:39 +0000 [thread overview]
Message-ID: <cbd20e8c0b6f4fbba10438ddabed142b@ub.unibe.ch> (raw)
In-Reply-To: <CAFMOkGUPYe+k7pozmjBXsnR5K8tfkuhPdhobLwCnyV-TvJXbQw@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 3378 bytes --]
What exactly do you need? You can just process each component on its own. With a makefile or shell script, batch file, that should be easy enough.
Or, do you need to have correct cross references, page numbers, etc.? I was asking a similar question two days ago, and Hans showed me how to add information to the log file:
\writestatus{!!!!!}{SPLIT HERE: \the\realpageno}
You should be then able to extract the split points from the log file and extract the components from the complete PDF.
Or, if you know that you will need to split your document at certain structure elements (chapters, sections or so), it's even simpler.
The lua script below will split your PDF at each chapter. It uses pdftk for splitting, but it should be easy to adapt this to context's own mechanism mentioned by Hans in the other thread.
Denis
============
-- mit welchen Dateien arbeiten wir?
local base = assert(arg[1], "Keine Datei angegeben")
local pdf = base .. ".pdf"
local tuc = base .. ".tuc"
-- import .tuc-file /extension lua
local utilitydata = dofile(tuc)
local breakpoints = {}
local last_page = utilitydata.structures.counters.collected["realpage"][1][1]
print ("Letzte Seite: " .. last_page)
-- iterate over .tuc => get breakpoints
for index, content in pairs(utilitydata.structures.lists.collected) do
if (content["titledata"]["label"] == "chapter")
then
table.insert(breakpoints,content["references"]["realpage"])
end
end
-- welches sind die Breakpoints?
print("Wir haben folgende Breakpoints:")
for index, content in pairs(breakpoints) do
print (content)
end
-- wie viele Breakpoint haben wir?
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
local breakpoints_length = tablelength(breakpoints)
print ("Wir haben " .. breakpoints_length .. " Breakpoints.")
-- Extraktionsbereiche festlegen
local extractions = {}
for index, breakpoint in pairs(breakpoints) do
region = {}
local startregion = breakpoint
local nextstartregion = breakpoints[index + 1]
local stopregion;
if (nextstartregion == nil)
then
stopregion = last_page
else
stopregion = nextstartregion - 1
end
region["start"] = startregion
region["stop"] = stopregion
table.insert(extractions,region)
end
print ("Wir extrahieren ...")
for index, region in pairs(extractions) do
print("von " .. region["start"] .. " bis " .. region["stop"])
local outputfile = "article" .. index .. ".pdf"
local extract_command = "pdftk " .. pdf .. " cat " .. region["start"] .. "-" .. region["stop"] .. " output " .. outputfile
os.execute(extract_command)
end
============
Von: ntg-context <ntg-context-bounces@ntg.nl> Im Auftrag von Alan Bowen
Gesendet: Montag, 1. März 2021 22:38
An: mailing list for ConTeXt users <ntg-context@ntg.nl>
Betreff: [NTG-context] outputting components in their own PDFs
I have a project-component setup and need to produce a single PDF file containing all the components as well as a PDF file for each component. The single file is easy. Is there a way to automate the generation of the PDF files for the individual components?
Alan
[-- Attachment #1.2: Type: text/html, Size: 15469 bytes --]
[-- Attachment #2: Type: text/plain, Size: 493 bytes --]
___________________________________________________________________________________
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
___________________________________________________________________________________
next prev parent reply other threads:[~2021-03-01 22:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-01 21:38 Alan Bowen
2021-03-01 22:07 ` denis.maier [this message]
2021-03-02 15:06 Alan Bowen
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=cbd20e8c0b6f4fbba10438ddabed142b@ub.unibe.ch \
--to=denis.maier@ub.unibe.ch \
--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).