User:Ssstephen/imposition: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
 
Line 3: Line 3:
The aim:
The aim:
Take two source PDFs, one is a multi page document with 70 x 95mm playing cards (front only) and another is an arbitrary sized single page PDF with the artwork for the common back of all the cards. I would like to convert these into a single PDF which is 4-up on an A4 sheet, with crop marks (both documents currently have no crop marks or bleed).  
Take two source PDFs, one is a multi page document with 70 x 95mm playing cards (front only) and another is an arbitrary sized single page PDF with the artwork for the common back of all the cards. I would like to convert these into a single PDF which is 4-up on an A4 sheet, with crop marks (both documents currently have no crop marks or bleed).  
Edit: This worked, the short answer is:
<code style="background-color:lightgreen">$ pdfimpose cards cards-1.pdf --signature 2x2 --imargin 2cm --omargin 2cm --mark crop --back background-resized.pdf </code>


Breaking the process into steps:
Breaking the process into steps:
=Make the front pages=  
=Make the front pages=  
==Break the document into individual pages==
==Break the document into individual pages==
Edit: This ended up not being a necessary step.
As per Simon's page, pdftk did a good job of this:
As per Simon's page, pdftk did a good job of this:
<pre>
<pre>
Line 54: Line 59:
Tried this and it's not great. Magick seems to convert to raster (boooooo). The real magick is in staying vector. [https://www.isisbooks.com/Energy-Flows-in-Magick-s/407.htm This site] seems to have some useful information on that, as well as some related information about visualisation and colour. Anyways I think I will change tactic and try using [https://github.com/rrthomas/pdfjam pdfjam] next time (or pypdf or maybe pdftk can do this?). For now it is the right size so I will use it for testing.
Tried this and it's not great. Magick seems to convert to raster (boooooo). The real magick is in staying vector. [https://www.isisbooks.com/Energy-Flows-in-Magick-s/407.htm This site] seems to have some useful information on that, as well as some related information about visualisation and colour. Anyways I think I will change tactic and try using [https://github.com/rrthomas/pdfjam pdfjam] next time (or pypdf or maybe pdftk can do this?). For now it is the right size so I will use it for testing.


Side note can PDF sizes have decimal points? These sizes are 0.1 and 0.2 mm off which aint great.
Update: GhostScript turned out to be the best way to do this for me. -dDEVICEWIDTHPOINTS and -dDEVICEHEIGHTPOINTS can be set to any value. The original artwork seems to be centred (not scaled) on the page. I think the -dFIXEDMEDIA option has something to do with it too, more info [https://ghostscript.com/docs/9.54.0/Use.htm#Paper_size here].
 
<pre>gs -sDEVICE=pdfwrite -dDEVICEWIDTHPOINTS=216 -dDEVICEHEIGHTPOINTS=252 -dFIXEDMEDIA -dPDFFitPage -dCompatibilityLevel=1.4 -o out.pdf background.pdf</pre>
 
Side note can PDF sizes have decimal points? These sizes are 0.1 and 0.2 mm off which aint great as guillotine and other print station machines use mm.


==Run the same imposition as above==
==Run the same imposition as above==

Latest revision as of 20:16, 30 October 2022

I just want to print playing cards as an imposed PDF with crop marks why is this so hard. I liked Simon's page where he wrote his process of trying to do something similar, so here is an attempt at a step by step.

The aim: Take two source PDFs, one is a multi page document with 70 x 95mm playing cards (front only) and another is an arbitrary sized single page PDF with the artwork for the common back of all the cards. I would like to convert these into a single PDF which is 4-up on an A4 sheet, with crop marks (both documents currently have no crop marks or bleed).

Edit: This worked, the short answer is:

$ pdfimpose cards cards-1.pdf --signature 2x2 --imargin 2cm --omargin 2cm --mark crop --back background-resized.pdf

Breaking the process into steps:

Make the front pages

Break the document into individual pages

Edit: This ended up not being a necessary step. As per Simon's page, pdftk did a good job of this:

 #burst the source PDF, keep the name of the source plus page number (-%d)
 $ pdftk source.pdf burst output source-%d.pdf

Impose 4up on a page using pdfimpose

But first I need to install pdfimpose on breadcube, which at the moment is getting stuck building a wheel for PyMuPDF, when I $ pip install pdfimpose I get an error ending like this:

    running install
    running build
    running build_py
    running build_ext
    building 'fitz._fitz' extension
    swigging fitz/fitz.i to fitz/fitz_wrap.c
    swig -python -o fitz/fitz_wrap.c fitz/fitz.i
    error: command 'swig' failed: No such file or directory
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-gvmhv_of/pymupdf_2a274ee5eb254f46956890df6daa0bc0/setup.py'"'"'; __file__='"'"'/tmp/pip-install-gvmhv_of/pymupdf_2a274ee5eb254f46956890df6daa0bc0/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-vyct1c_5/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/log/.local/include/python3.9/pymupdf Check the logs for full command output.

So I guess I need to install SWIG first.

When it does work what will I need? Crop marks can be added using mark=[‘crop’]. pdfimpose seems to work using schemas, there is already one called cards which is 4-up.

Ok pdfimpose installed woo! I tried $ pdfimpose cards cards-1.pdf and now I have an imposed document. But a) it has toomany-up and b) it needs crop marks.

pdfimpose cards cards-1.pdf --mark crop --back background-resized.pdf

Really close but it looks like the page size is changed based on the margin size (surely a sheet size can be set?) But for now as long as the printer will print actual size this works pretty well:

$ pdfimpose cards cards-1.pdf --signature 2x2 --imargin 2cm --omargin 2cm --mark crop --back background-resized.pdf

There is a small error, WARNING:root:Pages of source files have different size. This is unsupported and will lead to unexpected results. As far as I can tell the back page is lined up in the top left corner, per each page (so after cutting still aligned top left). This seems ok to me.

Make the back pages

Resize the document to 70 x 95mm

Image magick can probably do this like below:

#to resize to specific pixel dimensions such as 216x252
$ mogrify -resize 216x252! background-resized.pdf

Tried this and it's not great. Magick seems to convert to raster (boooooo). The real magick is in staying vector. This site seems to have some useful information on that, as well as some related information about visualisation and colour. Anyways I think I will change tactic and try using pdfjam next time (or pypdf or maybe pdftk can do this?). For now it is the right size so I will use it for testing.

Update: GhostScript turned out to be the best way to do this for me. -dDEVICEWIDTHPOINTS and -dDEVICEHEIGHTPOINTS can be set to any value. The original artwork seems to be centred (not scaled) on the page. I think the -dFIXEDMEDIA option has something to do with it too, more info here.

gs -sDEVICE=pdfwrite -dDEVICEWIDTHPOINTS=216 -dDEVICEHEIGHTPOINTS=252 -dFIXEDMEDIA -dPDFFitPage -dCompatibilityLevel=1.4 -o out.pdf background.pdf

Side note can PDF sizes have decimal points? These sizes are 0.1 and 0.2 mm off which aint great as guillotine and other print station machines use mm.

Run the same imposition as above

When we get that working. Also the pdfimpose cards schema has an option for back?

Assemble imposed PDFs into a single file

Or not. But could be nice to collate them so the printer can print one doc double sided. Work and turn or tumble? I think the printer in WDKa has the leading edge at the left. Can this be controlled in pdfimpose? From pdfimpose site: "When printing an imposed PDF, it shall be printed two-sided, the binding edge on the left or right."

Here's a short document that explains some imposition basics nicely.