return;
for (auto pg: pages)
- debug("Page #%d: w=%.3f h=%.3f", pg->index, pg->width, pg->height);
+ debug("Page #%d: media[%.3f %.3f] bbox[%.3f %.3f %.3f %.3f]",
+ pg->index,
+ pg->width, pg->height,
+ pg->bbox.x_min, pg->bbox.y_min, pg->bbox.x_max, pg->bbox.y_max);
}
vector<page *> run_command_list(list<cmd *> &cmds, vector<page *> &pages)
return pages;
}
+static void find_bboxes(vector<page *> &pages, const char *in_name)
+{
+ vector<BBox> bboxes = gs_bboxes(in_name);
+ if (pages.size() != bboxes.size())
+ die("Ghostscript failed to produce the right number of bboxes");
+
+ for (size_t i=0; i<pages.size(); i++)
+ pages[i]->bbox = bboxes[i];
+}
+
static void process(list<cmd *> &cmds, const char *in_name, const char *out_name)
{
in_pdf.processFile(in_name);
for (auto inpg: in_pages)
pages.push_back(new in_page(inpg, ++cnt));
+ find_bboxes(pages, in_name);
+
pages = run_command_list(cmds, pages);
for (auto pg: pages)
QPDFObjectHandle out_page = out_pdf.makeIndirectObject(QPDFObjectHandle::newDictionary());
out_page.replaceKey("/Type", QPDFObjectHandle::newName("/Page"));
out_page.replaceKey("/MediaBox", BBox(pg->width, pg->height).to_array());
- out_page.replaceKey("/CropBox", pg->bbox.to_array());
+ // FIXME:
+ // out_page.replaceKey("/CropBox", pg->bbox.to_array());
out_page.replaceKey("/Contents", contents);
out_page.replaceKey("/Resources", out.resources);
out_pdf.addPage(out_page, false);
int main(int argc, char **argv)
{
+ if (argc <= 1 || argc > 1 && !strcmp(argv[1], "--help"))
+ {
+ help();
+ return 0;
+ }
+
if (argc != 4)
{
fprintf(stderr, "Usage: paperjam <commands> <input> <output>\n");