How to convert PDF to PNG (and filter out the text)..
I want to render images and vector graphics (vector text included) without plain text
Below only the image is extracted.. not the whole page of the PDF
gs -sDEVICE=eps2write -dFILTERTEXT -dFirstPage=1 -dLastPage=1 -o out.eps 091.pdf
convert -density 300 -background white -alpha off out.eps -resize 2480x3508! OUT.png
from EPS
PDF
The FILTERTEST switch (as I'm pretty sure is documented) only works on text, not on image which contain a pattern of pixels which look like text, or on vector linework which looks like text.
Wihtout seeing your EPS I can't tell if the text you are complaining about is text or not, but my guess would be not.
By the way, if you want a PNG then there's no reason to convert the EPS to PDF, just render the EPS directly to a PNG file.
Related
I have a PDF that I want to print and a small region of each page has a thick rainbow at the left border. It is on each page. In order to save color ressources I would like to convert only this region to grayscale - or remove it completely with a white rectangle. I have looked into imagemagick but could not find a suitable solution to keep all the other color on the pages.
I have also thought of exporting each page to a separate PDF, apply a rectangle filter to each pdf and then combine it again. But I would prefer a simpler approach as the quality of the graphs seem to decrease each time I convert a pdf.
You do not have to extract each page to do that in ImageMagick. You can process it all in one command. Here is an example.
Create PDF:
convert lena.jpg mandril3.jpg zelda1.jpg test.pdf
Create white image:
convert -size 100x100 xc:white white.png
Apply white image to every page of PDF:
convert test.pdf null: white.png -geometry +50+50 -layers composite result.pdf
I am trying to convert .pdf files to .jpg using image-magic
convert -limit -limit map 300 -flatten -density 300 -quality 100 -crop '400x400+20+20' dummy.pdf[0] test.jpg
but the problem i am facing is when i convert the file, it cropping the area but marking all the other area as white.
for example if i am converting a pdf with 1000x1000 size and cropping it to a 100x100 size, the output am getting is an image with 1000x1000 size with 100x100 area croped from the pdf and rest is white space.
sample.pdf
i cannot use trim, since my pdf may or may not have white border and trim will remove it
Your syntax is not in the proper order for Imagemagick. Most of the settings and operators need to come after reading the input PDF. Using Imagemagick 6.9.10.71 Q16 Mac OSX Sierra:
convert -limit map 300 -density 300 dummy.pdf[0] -background white -flatten -crop '400x400+20+20' -quality 100 test.jpg
How do I convert only page 2 of a pdf file to a jpg image file, using GraphicsMagick command line prompt?
What option can I use in the gm.exe convert command?
gm.exe convert testing.pdf testing.jpg
Add the page number (starting from zero) in square brackets after the PDF filename:
gm.exe convert testing.pdf[1] testing.jpg
By the way, you can use the same indexing technique for accessing specific frames of a GIF animation, or layers of multi-layer/directory TIFFs.
use the blow command, will get high quality png with white background.
magick convert -density 300 -quality 100% -background white -alpha remove -alpha off ./646.04.pdf ./x.png
I've various PDF files from differents origins.. charged from users in a website..
I want reduce size of those more than 700Ko
So, I've make a script for select all files bigger than 700Ko;
For each PDF ( because there's images too ) I make :
exec('convert -density 300 -trim "'.$file.'" -resize 1000 -quality 85 -colorspace RGB -background white "'.$destination.$rand.$save_to.'" &', $output, $return_var);
The & at the end is for make : page-1.png, page-2.png ...
All is OK at this nivel ( I use .png because with .jpg I've some black background.. :( )
After, I try to make a new PDF with this:
exec('convert '.$img.' +page -quality 100 -gravity center '.$dirname.'/page1.pdf');
where $img is a list of image .png
Here, I've a problem .. most of image are not centered in the page..
How to make each page with a 100% size with the image, without border??
So, I've find a solution for my problem ..
I use Ghostscript .. better, faster and without problem.;
my code:
exec('gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -sOutputFile='.$rand.' '.$file.' ',$output, $return_var);
All PDF are smaller and don't lose quality !
More informations : http://milan.kupcevic.net/ghostscript-ps-pdf/
I'm using convert version ImageMagick 6.6.2-6 2011-03-16, and I'd like to use it to generate an A4 pdf from an image, where the image will be non-scaled and centered.
I'm running the following (as a modification of Overlaying Images with ImageMagick):
# generate a 100x100 JPG with just red color
convert -size 100x100 xc:red red.jpg
# generate PDF from JPG
convert -page A4 xc:white red.jpg -gravity center -composite -format pdf out.pdf
... but, basically nothing shows? Same thing happens for a png image...
Note that
Just 'convert -page A4 red.jpg out.pdf' works - but the image is not centered; (-gravity center causes image not to show)
If the image is png, 'convert -page A4 -gravity center red.png out.pdf' does indeed work fine
... however, I'd like convert to embed the contents of the JPEG stream directly - hence, I wouldn't like to convert the JPG to PNG first.
So, would it be possible to use convert to center a JPG image in an A4 PDF page directly?
Many thanks in advance for any answers,
Cheers!
EDIT2: #John Keyes answer works for the example above; where the image is "smaller" than the PDF size -- however if the image is bigger, e.g.:
$ convert -size 1228x1706 -background \#f44 -rotate 45 gradient:\#f00-\#fff red.jpg
$ identify red.jpg
red.jpg JPEG 2075x2075 2075x2075+0+0 8-bit DirectClass 120KB 0.000u 0:00.000
... then it will fail. However, it turns out: "if you change -extent to 50x50, then play with -gravity, you'll see changes" - except, the question is: which extent do you change, that of the image - or that of the final PDF?
Well, it turns out - it is the extent of the final PDF... To find that size as convert sees it, check the page: Magick::Geometry - however, note that the "Postscript page size specifications" like "A4+43+43>" unfortunately, cause convert to crash in this context... But at least the respective numbers for the size (595x842) can be copied from the page; and finally this works:
convert -page A4 -gravity center -resize 595x842 -extent 595x842 red.jpg out.pdf
... and actually, the -extent part is not really needed - the -resize part is the important one to have the large image show..
However, the problem here is that the image included seems to be resampled - however, I'd just like to show it scaled so it fits the page, but would otherwise like the original JPG stream to be inserted in the file.. So I guess the question is still partially open :)
EDIT: Related:
ImageMagick Gravity parameter - Stack Overflow
ImageMagick and Geometry Issue - resizing with > - Stack Overflow
command line - Resizing and croping images to an aspect ratio of 6x4 with width of 1024 pixels - Unix and Linux - Stack Exchange
conversion - using imagemagick or ghostscript (or something) to scale PDF to fit page? - Stack Overflow
The following works perfectly for me:
convert -page A4 red.jpg -gravity center -format pdf out.pdf
and if you change the order of the "files" it works too:
convert -page A4 red.jpg xc:white -gravity center -composite -format pdf out.pdf
I think the red.jpg is centered but the white is drawn on top of it.
Well, this is outside of imagemagick, but here is a solution in Latex, using tikz package (using How to define a figure size so that it consumes the rest of a page? #14514), which seems to reliably place images on page, and preserve them fully:
% note: need to run pdflatex twice!! First time generates blank pages!
% convert -size 1228x1706 -background \#f44 -rotate 45 gradient:\#f00-\#fff red.jpg
% convert -size 595x1400 xc:red redlong.jpg
\documentclass[a4paper]{letter}
\usepackage{graphicx}
\usepackage[hmargin=0.5cm,vmargin=0.5cm]{geometry} % sets page margins
\usepackage{tikz}
\usetikzlibrary{calc}
\newcommand{\imagepage}[1]{
\tikz[overlay,remember picture]\coordinate (image-start); \par
\vfill
\null\hfill
\begin{tikzpicture}[overlay,remember picture]
\path let \p0 = (0,0), \p1 = (image-start) in
node [inner sep=0pt,outer sep=0pt,anchor=center] at (current page.center) {%
\pgfmathsetmacro\imgheight{\y1-\y0}%
\includegraphics[height=\imgheight pt,width=\textwidth,keepaspectratio]{#1}%
};
\end{tikzpicture}%
}
\begin{document}
% there must be a \n\n after {letter!}
\begin{letter}
\imagepage{red.jpg}
\end{letter}
\begin{letter}
\imagepage{redlong.jpg}
\end{letter}
% see also \resizebox{\textwidth}{!}{\includegraphics{red.jpg}}
\end{document}
Note, the letter documentclass is used to allow that each image is split on separate page..