Is there a way to intercept the PDF rendering?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Is there a way to intercept the PDF rendering?

mattwynne
Hello,

I am trying to produce two copies of a training course workbook: One for delegates and one for the trainer. The trainer one should have additional "secret sauce" notes in it, but I want the page numbers to be consistent across both.

My plan is to add some padding in to the delegate workbook - "this page intentionally left blank" or "write your own notes here" to keep the page numbers the same in both copies. I'll use `ifdef` conditionals to render one or the other.

What I'd like to do is add some kind of check to the CI build for the book so that if this padding, which will have to be done by hand, isn't right, the build will fail. I'd basically like to be able to compare the ToC from each copy and check that the main headings are on the same pages in both workbooks.

Is there a place I can hook into the PDF rendering cycle to do this? Or do I need to write something to read the PDF again afterwards, outside of asciidoctor?
Reply | Threaded
Open this post in threaded view
|

Re: Is there a way to intercept the PDF rendering?

1marc1
Matt,

I am assuming you are using asciidoctor-pdf.

You are not saying how often these "secret sauce" notes change or how large they are. If they don't change often and fit on a single page, why not do something like this:

// Use :trainer_copy: to create a copy for the trainer.
// Use :trainer_copy!: to create a copy for the delegates.
:trainer_copy:

== Introduction
This is the introduction to the training course.
blah blah

<<<

ifdef::trainer_copy[]
Here are the secret sauce notes.

<<<

endif::[]

ifndef::trainer_copy[]
Space for delegates to write their notes.

<<<

endif::[]

If it needs to fit on multiple pages, you may need to use additional page breaks.

That way, you will end up with the same number of pages and the same ToC.

Marc.
Reply | Threaded
Open this post in threaded view
|

Re: Is there a way to intercept the PDF rendering?

mattwynne
Hi Mark,

Yes, I'm using asciidoctor-pdf

Thanks, that's exactly what my plan is. The workbook is under heavy development at the moment, and I'd like to have an automated check that keeps the ToCs consistent between both as we go along.

If there was a way to catch the ToC while it's in a data model, before it's turned into PDF content via prawn, I could say save it off as YAML and diff the two during the build pipeline.

I was just wondering if there was a way to hook into that PDF rendering cycle. I had a bit of a splunk around in the code but couldn't see anywhere obvious.
Reply | Threaded
Open this post in threaded view
|

Re: Is there a way to intercept the PDF rendering?

mojavelinux
Administrator
Asciidoctor PDF is quite complex and intertwined with Prawn, so there's no official way to tap into the lifecycle aside from monkeypatching the converter. You can find a summary of how Matt Raible did this on his blog: https://raibledesigns.com/rd/entry/re_customizing_an_asciidoctor_pdf

If we were to rewrite Asciidoctor PDF as a Prawn view, this might get a bit simpler. See https://github.com/asciidoctor/asciidoctor-pdf/issues/53

Cheers,

-Dan

On Thu, Nov 8, 2018 at 5:25 AM mattwynne [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi Mark,

Yes, I'm using asciidoctor-pdf

Thanks, that's exactly what my plan is. The workbook is under heavy development at the moment, and I'd like to have an automated check that keeps the ToCs consistent between both as we go along.

If there was a way to catch the ToC while it's in a data model, before it's turned into PDF content via prawn, I could say save it off as YAML and diff the two during the build pipeline.

I was just wondering if there was a way to hook into that PDF rendering cycle. I had a bit of a splunk around in the code but couldn't see anywhere obvious.


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Is-there-a-way-to-intercept-the-PDF-rendering-tp6583p6585.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML


--
Dan Allen | @mojavelinux | https://twitter.com/mojavelinux