Error in Converting PDF to PostScript with GhostScript, Access is denied Unable to open command line file _.at - pdf

I installed ghostscript and updated the appropriate path variables ... however, I'm getting an error when I try to execute this command:
C:\PROGRA~1\gs\gs8.64\lib>pdf2ps mydocument.pdf mydocument.ps
Access is denied.
Unable to open command line file _.at
Is this the right command? Did I miss some configuration or path setting? Otherwise, is there a sane method of doing this conversion?

Access is denied suggest something to do with access to paths etc. I'd suggest rechecking the folder permission (although I'm sure you've done that). Also, you might want to try running the gswin32c.exe instead of the pdf2ps to see if you still get the error, you might get something a little more specific.
gswin32c.exe ^
-dNOPAUSE ^
-dBATCH ^
-sDEVICE=pswrite ^
-sOutputFile=mydocument.ps ^
mydocument.pdf

Using pdf2ps runs a batch file, really named pdf2ps.bat or pdf2ps.cmd. You can easily look up and understand its "source code". If you do, you'll see it tries to write some of its commandline options into a temporary file named _.at, in order to overcome the 128 character limit for DOS/cmd commandline length that exist on some Win/DOS platforms.
Since you are invoking pdf2ps from the %programs% directory where Ghostscript is installed, you don't seem to be using an account that is permitted to write stuff in there. :-)

With Ghostscript version gs9.10 the method pswrite didn't worked for me instead I tried using ps2write instead, and it worked for me, so the command worked for me is as below:
gswin32c.exe ^
-dNOPAUSE ^
-dBATCH ^
-sDEVICE=ps2write ^
-sOutputFile=mydocument.ps ^
mydocument.pdf
and if this thing doesn't even works, then one can do this :
try getting help by typing gswin32c.exe -h and then it will list all the available devices as shown below:
Default output device: display
Available devices:
bbox bit bitcmyk bitrgb bj10e bj200 bjc600 bjc800 bmp16 bmp16m bmp256
bmp32b bmpgray bmpmono bmpsep1 bmpsep8 cdeskjet cdj550 cdjcolor cdjmono
cp50 declj250 deskjet devicen display djet500 djet500c eps9high eps9mid
epson epsonc epswrite ibmpro ijs inkcov jetp3852 jpeg jpegcmyk jpeggray
laserjet lbp8 lj250 ljet2p ljet3 ljet3d ljet4 ljet4d ljetplus m8510
mswindll mswinpr2 necp6 nullpage pamcmyk32 pamcmyk4 pbm pbmraw pcx16
pcx24b pcx256 pcxcmyk pcxgray pcxmono pdfwrite pgm pgmraw pgnm pgnmraw pj
pjxl pjxl300 pkmraw plan planc plang plank planm plib plibc plibg plibk
plibm png16 png16m png256 pngalpha pnggray pngmono pngmonod pnm pnmcmyk
pnmraw ppm ppmraw **ps2write** psdcmyk psdrgb pxlcolor pxlmono r4081 spotcmyk
st800 stcolor svg t4693d2 t4693d4 t4693d8 tek4696 tiff12nc tiff24nc
tiff32nc tiff48nc tiff64nc tiffcrle tiffg3 tiffg32d tiffg4 tiffgray
tifflzw tiffpack tiffscaled tiffscaled24 tiffscaled32 tiffscaled4
tiffscaled8 tiffsep tiffsep1 txtwrite uniprint xpswrite
Search path:
C:\Program Files (x86)\gs\gs9.10\bin ;
C:\Program Files (x86)\gs\gs9.10\lib ;
C:\Program Files (x86)\gs\gs9.10\fonts ; %rom%Resource/Init/ ;
%rom%lib/ ; c:/gs/gs9.10/Resource/Init ; c:/gs/gs9.10/lib ;
c:/gs/gs9.10/Resource/Font ; c:/gs/fonts
Initialization files are compiled into the executable.
As one can see only for the convenience only I have placed star(*) around the ps2write

use gimp open PDF file.
file -> export -> postscript.

If you want to use the gs executable you have to change the permissions.In the command prompt go to the location where gs executable is located and then use chmod 755 gs.

What you are doing is you are not writing command line at right place first you have to find out the instillation exe of ghostscript which is by default located at
c:\Program Files(x86)\gs\gs9.20(your ghostscript
version)\bin\gswin32c.exe
there are two exe
1- gswin32.exe
2- gswin32c.exe
you have to use the second one because it execuit commmands at cmd not in gs cmd
ok now what you have to do is write command like
...bin\gswin32c.exe -dNOPAUSE -dBATCH -sDEVICE=pswrite -sOutputFile=mydocument.ps mydocument.pdf
note please check the file path correctly and one more thing
file path like
"D:\htmltopdf\document.ps"
should be write as
"D:/htmltopdf/document.ps"
yes exactly replace backward slash with foreword slash only in file path
and the command line is case sensitive also so be carefull with cases

Related

Ghostscript PDF combine file limit?

If I have a bat file on windows to drive ghostscript PDF combine like:
C:\Program Files (x86)\GPLGS>gswin32c.exe -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=c:\copyfolder\combine.pdf -dBATCH c:\copyfolder\AgentLetter.pdf c:\copyfolder\iso.pdf c:\copyfolder\disclosure.pdf
In the above example I am combining 3 files. Is there a limit to the number of files I can list to be combined ?
Thanks
I just tried a test combining 3 files and it works. Wondering if there is a limit on number of files I can combine at once ?
The use of CLI programming is sometimes discouraged but is the basis of all top level machine OS code just same as running Pythonic Wheels or powershell instructions or scraping web pages, the aim is to do as much programatically in one line of instruction so as to be modular in computer applications.
[Edit]
As mentioned by KenS in comment use a #filelist (TL;DR its at the end) or for single command line usage you can shorten the total string length.
You will find on Windows it is the string length of a CMD console is the limit so abbreviate the programming commands as much as possible
traditionally you could rename the exe to same as Unix and use newer -o for output and keep names short without paths would go further to help
>gs -q -sDEVICE=pdfwrite -ocombine.pdf 01.pdf 02.pdf 03.pdf
example
>gs.exe -q -sDEVICE=pdfwrite -ocombine.pdf 01.pdf 02.pdf 03.pdf
C:\Apps\PDF\GS\gs1000w64\bin>dir 0*.pdf
Directory of C:\Apps\PDF\GS\gs1000w64\bin
01/02/2023 19:23 2,821,328 01.pdf
01/02/2023 19:23 2,821,328 02.pdf
01/02/2023 19:23 2,821,328 03.pdf
3 File(s) 8,463,984 bytes
C:\Apps\PDF\GS\gs1000w64\bin>dir co*.pdf
Directory of C:\Apps\PDF\GS\gs1000w64\bin
17/02/2023 16:32 2,831,780 combine.pdf
amazing the 27 page file is not much bigger than 1 of 9 pages, but I cheated they are the same file, thus same fonts.
if really string is an issue GS does not need .pdf simply .p will do but for windows sake use at least one letter as extension.
C:\bin>gs -q -sDEVICE=pdfwrite -oALL.pdf 01.p 02.p 03.p
using
"path\gswin##c.exe" "path to\#filesmerge.txt"
commands as program instructions are strung out vertically but any filename with spaces needs "quot ing"
filesmerge.txt
-sDEVICE=pdfwrite
-oALL.pdf
"C:\Any where with\a long name.pdf"
C:\Data\somewhere\blank.pdf
"C:\Data\some where\c me c you.pdf"
"C:\Data\some where else\done.pdf"
You can mix and match so if just the filesnames to merge are listed you can run
"C:\Apps\PDF\GS\gs1000w64\bin\gswin64c.exe" -sDEVICE=pdfwrite -o"c:\data\all my.pdf" "#C:\source folder\filenames.txt"

Ghostscript to convert PDF 2 Back to PDF version 1.7

I need to build a PDF serverside by reading in a number of PDFs and inserting each page into a new multipage PDF. The problem is that the PDFs are provided in version 2.0 format, but my application can only read version 1.7. I would like to convert the version 2 files back into a version 1.7 file so that my application can read it.
I am using ghostscript version 9.27, and have tried several commands, but each time I end up with an empty PDF. Example:
/usr/local/bin/gs \
-q -dNOPROMPT \
-dBATCH \
-dDEVICEWIDTH=595 \
-dDEVICEHEIGHT=842 \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.7 \
-sFileName=pdf-version-2.pdf \
-sOutputFile=fileout.pdf
There is no error, just an empty PDF. The "file" command does give the expected output "PDF document, version 1.7" but that's not much good when the file is blank. Any help greatly appreciated!
OK so I think the problem is your command line (as pointed out to me by one of my colleagues). You've specified -sFileName=pdf-version-2.pdf, which looks like you're trying to specify the input file.
There is no Ghostscript switch -sFileName, you specify the input filename(s) by simply putting the name on the command line. So you really want:
/usr/local/bin/gs \
-q -dNOPROMPT \
-dBATCH \
-dDEVICEWIDTH=595 \
-dDEVICEHEIGHT=842 \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.7 \
-sOutputFile=fileout.pdf \
pdf-version-2.pdf
For reasons that were good 30 years ago, the Ghostscript command line switches are copied into the PostScript environment, where they can be accessed by PostScript programs. So while its true (and possibly the szource of your confusion) that some of the utility programs shipped with Ghostscript do use -sFileName, Ghostscript itself doesn't, it just defines a PostScript variable using that name, so that programs can read it.
Because you've specified BATCH and NOPROMPT, but haven't specified an input file, the interpreter starts up, erases the current page to white, then exits. Closing the pdfwrite device causes it to write out the current content of the page, which is, well, white, resulting in your empty PDF file.
The slightly modified command line above worked well for me, but as I noted in my comments specifying DEVICEWIDTHPOINTS and DEVICEHEIGHTPOINTS won't actually do anything.

Why text is missing after convert this PDF to image using ImageMagick/Ghostscript?

Text is missing after convert this pdf to image(png or jpg), but there no any error log.
Use ImageMagick:
convert -density 150 -quality 100 "d:/t/pdf/fp.pdf" -alpha Remove "d:/t/pdf/5/fp.png"
Use Ghostscript (testing with version 9.23 and 9.25):
gswin64 -dSAFER -dBATCH -dNOPAUSE -r300 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -sDEVICE=jpeg -sOutputFile=D:\t\pdf\123.jpg D:\t\pdf\fp.pdf
Anyone know what the reason and how to solve it? Thx.
PDF File for testing
image 1 image 2
There are two CIDFonts (STSong-Light and AdobeKaitiStd-Regular) used but not embedded. This means that a substitute font must be used. When run through Ghostscript this produces the following transcript:
GPL Ghostscript GIT PRERELEASE 9.26 (2018-09-13)
Copyright (C) 2018 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
Can't find CID font "AdobeKaitiStd-Regular".
Attempting to substitute CID font /Adobe-GB1 for /AdobeKaitiStd-Regular, see doc
/Use.htm#CIDFontSubstitution.
The substitute CID font "Adobe-GB1" is not provided either. attempting to use fa
llback CIDFont.See doc/Use.htm#CIDFontSubstitution.
Loading a TT font from %rom%Resource/CIDFSubst/DroidSansFallback.ttf to emulate
a CID font Adobe-GB1 ... Done.
Can't find CID font "AdobeKaitiStd-Regular".
Attempting to substitute CID font /Adobe-GB1 for /AdobeKaitiStd-Regular, see doc
/Use.htm#CIDFontSubstitution.
Can't find CID font "AdobeKaitiStd-Regular".
Attempting to substitute CID font /Adobe-GB1 for /AdobeKaitiStd-Regular, see doc
/Use.htm#CIDFontSubstitution.
Loading NimbusSans-Regular font from %rom%Resource/Font/NimbusSans-Regular... 71
35536 5791889 4867288 3488798 3 done.
Can't find CID font "STSong-Light".
Attempting to substitute CID font /Adobe-GB1 for /STSong-Light, see doc/Use.htm#
CIDFontSubstitution.
Loading NimbusMonoPS-Regular font from %rom%Resource/Font/NimbusMonoPS-Regular..
. 10713600 9353422 4987912 3610458 3 done.
**** Error: Executing Do inside a text block, attempting to recover
Output may be incorrect.
>>showpage, press <return> to continue<<
So you can see two fonts being substituted, and then a more concrete problem. Your PDF file executes an image operator inside a text block, which is illegal. However for me the output is apparently correct.
[EDIT]
There is some odd behaviour here. I downloaded the 64-bit release code last night and tried that, and I do see the error. The back channel transcript contains this :
Can't find CID font "AdobeKaitiStd-Regular".
Attempting to substitute CID font /Adobe-GB1 for /AdobeKaitiStd-Regular, see doc
/Use.htm#CIDFontSubstitution.
Loading NimbusSans-Regular font from %rom%Resource/Font/NimbusSans-Regular... 77
20460 6369217 2670672 1276767 3 done.
**** Error: can't process embedded font stream,
attempting to load the font using its name.
Output may be incorrect.
**** Error reading a content stream. The page may be incomplete.
Output may be incorrect.
Loading NimbusMonoPS-Regular font from %rom%Resource/Font/NimbusMonoPS-Regular..
. 11808228 10439970 2690872 1310356 3 done.
**** Error: Executing Do inside a text block, attempting to recover
Output may be incorrect.
**** Error: File did not complete the page properly and may be damaged.
Output may be incorrect.
Page 2
The key part is "Can't process embedded font stream....' That's why your text is going missing.
When I run the same command line using the current HEAD of our Git repository I don't see this error, and the file runs to completion. So it looks like this was a bug which has been fixed.
You have two options;
1) If you don't mind building the code, clone our Git repository, open the Visual Studio solution file, allow VS to update it to your version, then build Ghostscript. Use that binary.
2) As you've already discovered, don't use SAFER. I should caution you that this is a potentially dangerous setup. As long as you are processing files which you created yourself you should be fine, but please don't use this setup to process random files from untrusted sources, you could be laying yourself open to attack.
[edit 2]
And here's a third option. With 9.25 we started shipping the Resource files with Windows, just as we do with Linux. I suspect that if you add -I"c:/program files/gs/gs9.25/Resource/Init" to the beginning of your command line, it will work even when -dSAFER is true.
BTW its useful to quote the messages from the back channel when you have a problem, it may not tell you much, but it has useful information for PostScript developers.
The missing text came back when I removed the parameter -dSAFER. I don't understand why; I can't find the reason in the Ghostscript documentation.
This is my final command line:
gswin64 -dBATCH -dNOPAUSE -r150 -sDEVICE=jpeg -sOutputFile=D:\t\pdf\6\fp%03d.jpg D:\t\pdf\fp.pdf

embed icc color profile in ps2pdf ghostscript

hi im trying the following with ghostscript 9.18 on windows 10:
CALL "C:\Program Files\gs\gs9.18\bin\gswin64c.exe" ^
-dNumRenderingThreads=8 ^
-dSAFER ^
-r720 ^
-dCompressFonts=true ^
-dPDFSETTINGS=/prepress ^
-dPDFA=2 ^
-dBATCH ^
-dNOPAUSE ^
-sProcessColorModel=/DeviceRGB ^
-dProcessColorModel=/DeviceRGB ^
-sColorConversionStrategy=/UseDeviceIndependentColor ^
-sDefaultGrayProfile="C:\Program Files\gs\gs9.18\iccprofiles\ISOcoated_v2_grey1c_bas.ICC" ^
-sDefaultRGBProfile="C:\Program Files\gs\gs9.18\iccprofiles\sRGB_v4_ICC_preference.icc" ^
-sDefaultCMYKProfile="C:\Program Files\gs\gs9.18\iccprofiles\PSOuncoated_v3_FOGRA52.icc" ^
-dOverrideICC=true ^
-sOutputICCProfile="C:\Program Files\gs\gs9.18\iccprofiles\sRGB_v4_ICC_preference.icc" ^
-sDEVICE=pdfwrite -sOutputFile="%~n1.pdf" %1
pause
but it fails, it writes without error, but no ecc profile will be included, no matter what input. please can someone help? i found other topics but no real answer...
I answered this question on the #ghostscript channel on irc.freenode.net yesterday. The command line has a number of problems:
-dNumRenderingThreads has no effect on any high level device, since they don't render
You should not set the resolution on high level devices unless you anticipate that there will be rendered output (PDF transparent input to a version of PDF < 1.4). If you do set resolutoin you should not set it to the default, that's just pointless.
In general I would not use PDFSETTINGS, especially when trying to create a PDF/A file. If you order the command incorrectly the result will not be a valid PDF/A file.
You have set ProcessColorModel twice, once each with the name and string syntax switches, and the string switch is incorrect.
You have set ColorConversionStrategy using the string switch (-s) but have supplied a name. That won't work and will have no effect.
You absolutely do not want to set OverrideICC or OutputICCProfile and unless you are working in a tightly controlled colour managed workflow (and I know you are not) then you should not set the Default ICC profiles.
All this is for the benefit of anyone else who should happen across this question. Do not copy the command line above thinking its useful, it isn't.
As already explained to the poster on IRC, his output file does include an ICC profile. Since he doesn't appear to understand colour management or PDF, he is unable to explain what he wants (or why) other than to say he wants to include an ICC profile 'for a professional result'.

Split multi-page PDF into JPG (or PNG...) files using ImageMagick

I'm facing a little problem with Image Magick, which I found a marvellous tool so far, but here it doesn't achieve what I expect (N.B: I work in Windows 7)
I read that, to split a 3 pages (for example) pdf file, you just have to do:
img2img My3pageFile.pdf SplittedImage.jpg
and then, ImageMAgick would automatically create SplittedImage-1.jpg, SplittedImage-2.jpg and SplittedImage-3.jpg.
Well instead of this, I obtain an error message like this: (let me hope you'll believe me if I say that I have no doubt here under that the file "benef.pdf" does exist on D:).
D:\>img2img benef.pdf benef.jpg
img2img: `%s': %s "gswin32c.exe" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH
-dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=0
"-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-g595x842" "-r72x72"
"-sOutputFile=C:/Users/ADM-A2~1/AppData/Local/Temp/magick-o3McMMZQ" "-fC:/Users
/ADM-A2~1/AppData/Local/Temp/magick-EOLT_ZO2" "-fC:/Users/ADM-A2~1/AppData/Local
/Temp/magick-mUWMMcc0".
img2img: Postscript delegate failed `benef.pdf'.
img2img: missing an image filename `benef.jpg'.
The answer is simply to install and download GhostScript at the following address, after what the instruction I gave at the beginning works perfectly well.
So here's the link:
http://downloads.ghostscript.com/public/