void debug_pages(vector<page *> &pages)
{
- if (!debug_mode)
+ if (!debug_level)
return;
for (auto pg: pages)
{
debug("# Executing %s", c->def->name);
debug_indent += 4;
- pages = c->exec->process(pages);
+ try
+ {
+ pages = c->exec->process(pages);
+ }
+ catch (exception &e)
+ {
+ die("Error in %s: %s", c->def->name, e.what());
+ }
debug_indent -= 4;
debug_pages(pages);
}
return pages;
}
+static void make_info_dict()
+{
+ // Create info dictionary if it did not exist yet
+ QPDFObjectHandle trailer = out_pdf.getTrailer();
+ QPDFObjectHandle info = trailer.getKey("/Info");
+ if (info.isNull())
+ {
+ info = QPDFObjectHandle::newDictionary();
+ trailer.replaceKey("/Info", info);
+ }
+ else
+ assert(info.isDictionary());
+
+ info.replaceKey("/Producer", unicode_string("PaperJam"));
+
+ // Copy entries from the source file's info dictionary
+ QPDFObjectHandle orig_trailer = in_pdf.getTrailer();
+ QPDFObjectHandle orig_info = orig_trailer.getKey("/Info");
+ if (!orig_info.isNull())
+ {
+ const string to_copy[] = { "/Title", "/Author", "/Subject", "/Keywords", "/Creator", "/CreationDate" };
+ for (string key: to_copy)
+ info.replaceOrRemoveKey(key, orig_info.getKey(key));
+ }
+}
+
void process(list<cmd *> &cmds)
{
+ debug("### Reading input");
in_pdf.processFile(in_name);
in_pdf.pushInheritedAttributesToPage();
out_pdf.emptyPDF();
if (recalc_bbox)
do_recalc_bbox(pages, in_name);
+ debug("### Running commands");
pages = run_command_list(cmds, pages);
+ debug("### Writing output");
for (auto pg: pages)
{
out_context out;
}
// Produce info dictionary
- QPDFObjectHandle trailer = out_pdf.getTrailer();
- QPDFObjectHandle info = trailer.getKey("/Info");
- if (info.isNull())
- {
- info = QPDFObjectHandle::newDictionary();
- trailer.replaceKey("/Info", info);
- }
- else
- assert(info.isDictionary());
- // FIXME: More meta-data
- info.replaceKey("/Producer", unicode_string("PaperJam"));
+ make_info_dict();
// Write the output file
QPDFWriter writer(out_pdf, out_name);
writer.write();
+ debug("### Done");
}
/*** Re-calculation of bboxes ***/