Active8 years, 7 months ago
- Ghostscript Convert Pdf To Png Quality
- Ghostscript Pdf To Image
- Ghostscript Convert Png To Pdf Windows
I am attempting, unsuccessfully, to use Ghostscript to rasterize PDF files with atransparent background to PNG files with a transparent background. I'vesearched high and low for questions from others attempting the same thingand none of the posted solutions, which as far as I can tell come down tospecifying -sDEVICE=pngalpha, have worked with my test files. At this pointI would really appreciate any advice or tips a more experienced hand couldprovide.
My test PDF is located here: http://www.kolossus.com/files/test.pdf
It could be that the issue is with this file, but I doubt it. As far as Ican tell, it has no specified background, and when I open the file with atransparency-aware app like Photoshop or Illustrator, sure enough itdisplays with a transparent background. However, when opened with anapplication like Adobe Reader the file is rendered with a white background.I believe that this has more to do with the application rendering the PDFthan with the PDF itself -- apps like Adobe Reader assume you want to seewhat a printed document will look like and therefore always show a whitecanvas behind the artwork -- but I can't be sure.
The gs command I'm using is:
- Using Ghostscript with PDF files. Ghostscript is normally built to interpret both PostScript and PDF files, examining each file to determine automatically whether its contents are PDF or PostScript. All the normal switches and procedures for interpreting PostScript files also apply to PDF files, with a few exceptions.
- Mar 14, 2016 How To Convert PostScript (eps/ps) to PDF with Ghostscript on Windows 10. In this tutorial you’ll do four. Convert the Postscript file to a PDF.
@run: No, you can only get the image to the lower left corner in one go. But, after you placed the image on the PDF page successfully, you could employ a second step gs commandline to shift the image. That's why I wrote '.script makes each PDF page use the same page dimensions as the original JPEG for the page'. – Kurt Pfeifle Feb 23 '12 at. To convert a multi-page pdf file and generate separate png file for each page the command is: gs -dNOPAUSE -dBATCH -sDEVICE=png16m -sOutputFile='Pic-%d.png' input.pdf The above command will generate a separate PNG file for each page in the pdf file input.pdf.
This produces a PNG that has transparent pixels outside of the bounding boxof the artwork in the file, but all pixels that are inside the artwork'sbounding box are rasterized against a white background. This is a problemfor me, as my artwork has drop shadows and antialiased edges that need to bepreserved in the final output, and can't just be postprocessed out withImageMagick. A sample of my PNG output is at the same location as the pdf above, with .png at the end (stackoverflow won't let me include more than one url in my post).
And in the img.Process; actually the pdf is converting to png image. After Conversion the PdfFolder looks like this, And the ImgFolder looks like this, Note. In the above example, I converted the PDF file into png image file. But, if you want to convert pdf file into jpg/jpeg, then in place of png, please write jpg/jpeg.
Interestingly, I see no effects from using the -dBackgroundColor flag, evenif I set it to something non-white like -dBackgroundColor=16#ff0000. Perhapsmy understanding of the syntax of this flag is wrong.
Also interestingly, I see no effects from using the -dTextAlphaBits=4-dGraphicsAlphaBits=4 flags to try to enable subpixel antialiasing. I wouldalso appreciate any advice on how to enable subpixel antialiasing,especially on text.
Finally, I'm using GPL Ghostscript 8.64 on Mac OS 10.5.7, and the renderingworkflow I'm trying to get set up is to generate transparent PNG images fromPDFs output by PrinceXML. I'm calling Ghostscript directly for the rasterization instead of using ImageMagick because ImageMagick delegates to Ghostscript for PDF rasterization and I should be able to control the rasterization better by calling GS directly.
Thanks for your help.
-Jon Wolfe
Jonathon Wolfe
3 Answers
I share your experience with the
-dTextAlphaBits=4
and -dGraphicsAlphaBits=4
flags. They appear not to work on all texts. The 'fix' I came up with was to just render the image at 4 times the desired size, and then scale the image down. Game untuk android terbaik. Luckily ghostscript has no problems rendering gigapixel PNG files.update
Ghostscript (up to version 9) also seems to enjoy major problems when rendering transparent PNG's with a pixel count above 2.500.000 (i.e. 10 mb of pixel buffer). The transparent background suddenly turns white.
Drilling down the source of ghostscript, I found that when the pixel buffer size exceeds 10 mb, it switches to a different memory allocation scheme. More specifically, the image is rendered using device
image32
instead of pngalpha
. Given the way the pngalpha
driver is implemented, it's whole purpose vanishes when gs decides not to use its pngalpha_fill_rectangle()
.Luckily, there is a switch called
-dMaxBitmap=N
to configure this parameter at runtime. This is mentioned in a workaround for a totally different bug dating back to 1999-01-15, see http://pages.cs.wisc.edu/~ghost/doc/AFPL/5.50/relnotes/index.htm.Made In India Mp3 Song - Guru Randhawa Song MP3 Songs Punjabi Songs 2018 Punjabi Songs, Download Bestwap, Bestwap.in, Mp3 Songs, Mp3 Song. Made in india full song.
Adding
-dMaxBitmap=2147483647
solved a lot of problems for me. On 64 bit systems, this number can be higher.A true fix would of course be to rework the
mvdsmvdspngalpha
driver so that it sets the background color to 0x7f000000
no matter the actual code path, but most systems have enough ram on board for the above trick to work.40.1k66 gold badges8787 silver badges106106 bronze badges
Afraid I can't tell you what ghostscript can do but I do have a suggestion. Try rendering your PDF with both a black and a white background. Any pixel that comes out the same in the two images was clearly meant to be opaque (i.e., alpha 1.0). Pixels that are different have a non-zero alpha which can be computed by subtracting the black background pixel from the white background pixel. Give or take some precision, the value of any red, green or blue component will be the alpha value.
George PhillipsGeorge Phillips
Ghostscript can handle transparency only if at build time the 'transpar' option was selected. Assuming your Ghostscript is the right version, you can add a parameter on the commandline:
(You can use variants for the opacity in the range [0.1]).
Also, have you tried to convert your Ghostscript-created .png (in case that background indeed is white instead of transparent) to a transparent background using ImageMagick's
convert
or GraphicMagick's gm convert
commands? Here is an example:BTW, in case Acrobat or AcroReader show all page backgrounds as white: this is the default setting even for really transparent backgrounds. You can change it in the application's setup options: IIRC the setting was inside the 'Page Display' options and named s.th. like 'Show transparency rasters'. (If I looked it up in detail, it possibly wouldn't help too much -- Adobe keeps shifting all options around in every new release. Just poke around there yourself, you'll find it now that you know it's there.)
Kurt PfeifleKurt Pfeifle68.4k1515 gold badges186186 silver badges285285 bronze badges
Active1 year, 10 months ago
as the title says I am trying to convert png to pdf.I could not find well described example anywhere about this.
I used this command
but all I get is
this error message. And now I started wodering if such feature is possible in ghostscript. Should I use other software?** I'm runing the latest 9.07 version
Eugene YuEugene Yu1,46833 gold badges1616 silver badges2626 bronze badges
2 Answers
Ghostscript can output multiple formats (png included) but I don't believe it is able to take png as an input. You may be able to accomplish your goal using something like imagemagick's
Ricky Smithconvert
utility, though: convert test.png test.pdf
2,30111 gold badge1212 silver badges2929 bronze badges
Ghostscript Convert Pdf To Png Quality
oakadoakad
Ghostscript Pdf To Image
Yes, image magick can do this no problem - here's the cmd line for looping through all the pngs in a folder and converting to pdf:
cd to the folder with the pngs
mogrify -format pdf -density 300 -units PixelsPerInch *png
mikemike