[NTG-context] outputting components in their own PDFs

2021-03-02 Thread Alan Bowen
Denis—

Many thanks for your explanation. It works very well in my separating
components (chapters) and is going to save me a lot of time.

Thanks too to Hans.

And my apologies for missing the earlier discussion: my internet access and
email has been very flakey of late and I know that I have lost messages. In
fact, I found Denis’s reply and the earlier exchange by going to the list
Archive.

All best, Alan
___
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
___


Re: [NTG-context] outputting components in their own PDFs

2021-03-01 Thread denis.maier
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  Im Auftrag von Alan Bowen
Gesendet: Montag, 1. März 2021 22:38
An: mailing list for ConTeXt users 
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
___
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
___


[NTG-context] outputting components in their own PDFs

2021-03-01 Thread Alan Bowen
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
___
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
___