<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Am 11.12.2017 um 15:56 schrieb David
      Shourabi Porcel:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAFjD7YN-tDmdWsUXsC=7r0Lxy1y9h=Sqq+M1FiRkwbWOgjfxmA@mail.gmail.com">
      <pre wrap="">Hi!

If it's possible to carry out the postprocessing you need from within
LuaTeX instead of with ghostscript, the callback finish_pdffile might
be an option. </pre>
    </blockquote>
    <br>
    finish_pdffile is called very early.<br>
    <br>
    Unfortunately even the stop_run callback is executed before the
    complete pdf has been written and closed:<br>
    <br>
    <blockquote><tt>\directlua {</tt><br>
      <tt>  function my_stop_run()</tt><br>
      <tt>    os.execute("stat lyInLatex.pdf")</tt><br>
      <tt>  end</tt><br>
      <tt>  luatexbase.add_to_callback('stop_run', my_stop_run, 'TEST')</tt><br>
      <tt>}</tt><br>
    </blockquote>
    A "stat lyInLatex.pdf" after luatex finished shows that 40 bytes are
    not written at the time of callback execution.<br>
    <br>
    Let's have a look at the source code:<br>
    <blockquote><tt>void finish_pdf_file(PDF pdf, int luatexversion,
        str_number luatexrevision)</tt><br>
      <tt>{</tt><br>
      <tt>[...]</tt><br>
      <tt>   if (total_pages == 0) {</tt><br>
      <tt>      [...]</tt><br>
      <tt>    } else {</tt><br>
      <tt>        if (pdf->draftmode == 0) {</tt><br>
      <tt>           [...]</tt><br>
      <tt>        } else {</tt><br>
      <tt>            if (callback_id > 0) {</tt><br>
      <tt>                run_callback(callback_id, "->");</tt><br>
      <tt>            }</tt><br>
      <tt>        }</tt><br>
      <tt>        libpdffinish(pdf);</tt><br>
      <tt>        if (pdf->draftmode == 0)</tt><br>
      <tt>            close_file(pdf->file);</tt><br>
      <tt>            <b>%</b></tt><b><br>
      </b><b><tt>            % I think that pdf_closed callback called
          at this place would be a good idea!</tt></b><b> <br>
      </b><b><tt>            %</tt></b><br>
      <tt>        else</tt><br>
      <tt>            normal_warning("pdf backend","draftmode enabled,
        not changing output pdf");</tt><br>
      <tt>    }</tt><br>
    </blockquote>
    Knut<br>
  </body>
</html>