PDFs

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
elturner2000
Posts: 2
Joined: 2014-03-19T07:27:19-07:00
Authentication code: 6789

PDFs

Post by elturner2000 »

I have a simple task that I have been unable to accomplish though I have spent weeks on it.
I have a shipping label: name address barcode etc.
It comes in the form of a pdf in 8x11 size.
The label itself is 400x600 at the top left corner of the "page".
The label is perfect size but I need to "trim" away the white space so I can print it on the label printer.
"trim" works perfectly except the quality of the image is about 80% of the original.
I print the original on a full size printer and its perfectly clear - I "trim" to a new image appears onscreen to be almost the same but when I print it its 80%

I've tried converting it to a jpg and cropping, but I lose quality there as well. If fact anytime I use any "convert" command I lose quality. I read hundreds of posts and tried thousands of command combinations and it still won't work.

I can take the image and manually crop it with Preview ( I'm on a Mac) and it is crisp as can be.

Is this not something the product is designed for ?

I usually can get through these kind of things in a matter of days with shear persistence and a willingness to try one more thing. I can't in this case and I am ready to give up. I am thoroughly humbled.

Can you give me any advice or direction?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: PDFs

Post by snibgo »

Don't use jpeg. It is lossy compression, especially for areas of flat colour. Png would be better.
elturner2000 wrote:... same but when I print it its 80%
80% of what? 80% of the size? If so, it's just a density (ie dots per inch) problem.

Are you using "-density" before the conversion? This is generally needed for good quality conversions from pdf.

Please:
- say what versions of IM and Ghostscript you are using;
- say exactly what commands you have tried;
- put a sample pdf where we can download it, eg dropbox.com, and paste the url here.
snibgo's IM pages: im.snibgo.com
mrmattnc
Posts: 22
Joined: 2014-02-04T11:23:37-07:00
Authentication code: 6789

Re: PDFs

Post by mrmattnc »

Snibgo is on point as usual. The only thing I might try would be -units PixelsPerInch.

Other problems I have had in the past were with color conversion. The threshold command can force it back down to just black and white. You would need this if the output prints with a grayish background (like you would see on a copy of a copy on a copier) wasting print materials, though some printer firmwares handle this.

I have seen notes from fred that suggest this particular command needs to come first. For example :
convert -units PixelsPerInch -density 300 <image> <output>
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PDFs

Post by fmw42 »

It comes in the form of a pdf in 8x11 size.
The label itself is 400x600 at the top left corner of the "page".
Does the 400x600 pixel label fill the 8x11 page? Is the issue that it does not? Does 400x600 mean that you have a raster image inside of a PDF file?

As snibgo suggested, we really need to have more information. But note that PDF is a vector format and IM is not the best tool to go from vector PDF to vector PDF. IM will rasterize the vector file. see http://www.imagemagick.org/Usage/formats/#vector

Since PDF is a vector file, it carries no size. Printers may assume some default density for the image. But properly, when you process a pdf, such a to trim, you will convert it to raster and IM probably assumes 72 dpi. So you really need to specify a density when you read the pdf, so that it will be converted to the raster image at whatever resolution you want. That is typically done as mrmattnc has suggested by specifying the density (and units) before reading in the PDF (or vector) file in the command line.

The other issue with using PDFs is that they could hold a raster image. That is they are vector shells holding a raster image. In this case the vector shell has no resolution (apart from what you tell it via -density), but the raster inside may have some specific size. That may complicate things above.

What you need to do is specify some density when you trim (say 72), see what size output you get for the raster image and then adjust the density to compensate for the output size to get what you really desire. Do not save to jpg if you desire to do further processing as it is a lossy process. Better to save as PNG or possibly TIFF.

Code: Select all

convert -density XX -units pixelsperinch image.pdf -trim +repage result.png
Start with XX=72 and get the size of result.png, then adjust the density XX to achieve the pixel size you want for your label. XX=72*(desired dimension)/(dimension when using 72))

_____

Note that at one time there was a situation where the units needed to be specified first. But I do not recall the circumstances and this has probably been fixed. I believe that IM will assume pixelsperinch as the default if you leave it off. Also PNG does not support pixelsperinch. It only uses pixelspercm. But IM will convert the density accordingly as needed. So the density you read from the png file will not be the number you specified in pixelsperinch, but will be converted to the equivalent pixelspercm.
elturner2000
Posts: 2
Joined: 2014-03-19T07:27:19-07:00
Authentication code: 6789

Re: PDFs

Post by elturner2000 »

Thank you all for your helpful replies - My apologies for the delay in my response - I just returned to the forum.

I gave up on ImageMagic last week.

I to a turn at ghost script and had it working in a couple of hours.

Thanks again!

Sunny
Post Reply