TheSwamp

CAD Forums => CAD General => Topic started by: Mark on April 04, 2008, 08:03:40 AM

Title: Ghostscript: The Thread
Post by: Mark on April 04, 2008, 08:03:40 AM
Creating high quality .png files from your .ps/plt files.

Code: [Select]
@echo off
:: process all the .plt files in this directory
::
echo.
for %%f in (*.plt) do gswin32c -dSAFER -dBATCH -dNOPAUSE [color=red]-r300 [/color] -sDEVICE=pnggray -sOutputFile="%%~nf.png" "%%f"
echo Done!

for more quality increase the -r switch.
Title: Re: Ghostscript: The Thread
Post by: M-dub on April 04, 2008, 08:13:58 AM
Interesting!  I'll have to save a copy of that in our plotting folder on the network.  :)
Title: Re: Ghostscript: The Thread
Post by: Mark on April 04, 2008, 08:17:20 AM
couple of examples.

FWIW the 'png16m' device seems to produce a nicer image.

http://www.theswamp.org/screens/mark/images/colorwh-AutoCAD%20Color%20Index.png

http://www.theswamp.org/screens/mark/images/Lineweights.png
Title: Re: Ghostscript: The Thread
Post by: JohnK on April 07, 2008, 08:59:55 AM
Mark,

check out the ``-o'' option in the `uses.htm' found under the doc directory.
Title: Re: Ghostscript: The Thread
Post by: Mark on April 07, 2008, 09:06:23 AM
Mark,

check out the ``-o'' option in the `uses.htm' found under the doc directory.

Good tip!

Quote
-o option:
As a convenient shorthand you can use the -o option followed by the output file specification as discussed above. The -o option also sets the -dBATCH and -dNOPAUSE options. This is intended to be a quick way to invoke ghostscript to convert one or more input files. For instance, to convert somefile.ps to JPEG image files, one per page, use:

gs -sDEVICE=jpeg -o out-%d.jpg somefile.ps
is equivalent to:
gs -sDEVICE=jpeg -sOutputFile=out-%d.jpg -dBATCH -dNOPAUSE somefile.ps

Title: Re: Ghostscript: The Thread
Post by: JohnK on April 07, 2008, 09:20:58 AM
It saves my fingers.
Title: Re: Ghostscript: The Thread
Post by: Antisthenes on April 07, 2008, 02:26:21 PM
PNG  the best of both worlds

16 million colors  transparency and lossless

mmm

cool Batch file
Title: Re: Ghostscript: The Thread
Post by: Robb on April 07, 2008, 05:54:52 PM
PNG  the best of both worlds

16 million colors  transparency and lossless

mmm

cool Batch file

What are you guys using this for? Sounds interesting. Are you using to replace PDF's?
Title: Re: Ghostscript: The Thread
Post by: Krushert on April 07, 2008, 06:15:54 PM
**Drops sonar buoy**
Title: Re: Ghostscript: The Thread
Post by: Robb on April 07, 2008, 07:25:54 PM
**Drops sonar buoy**

???

I'm asking what is the reason to convert plt to png? If I find it beneficial in any way I may use it.

Also, I am trying to run this script above.. I assumed I just create a .bat file and place it in a folder of plt files that I want to convert. Execute the script and all the plt files within that folder will be converted to png. Tried it and nothing happened. Then realized I may need to have ghostscript installed, installed it and still nothing. Do I need to run the script from within GSViewer?

Can someone help me out?

Thanks

Title: Re: Ghostscript: The Thread
Post by: Krushert on April 07, 2008, 07:40:02 PM
**Drops sonar buoy**

???

I'm asking what is the reason to convert plt to png? If I find it beneficial in any way I may use it.

Also, I am trying to run this script above.. I assumed I just create a .bat file and place it in a folder of plt files that I want to convert. Execute the script and all the plt files within that folder will be converted to png. Tried it and nothing happened. Then realized I may need to have ghostscript installed, installed it and still nothing. Do I need to run the script from within GSViewer?

Can someone help me out?

Thanks

No offense meant to you Robb.  Just me being all Smart Alec. (Another words, I was being a Greg)

My comment was to reference that I wanted to watch this topic becuase just like you, I am wanting to do the same thing.  Unfortunately; I had to shelve this project just at the start of my investigations to figure out how it was done.

What I have learned so far is that it produces PDF very efficiently and of sound quality. 
You might want to take a look at this thread over .... (let me go find it) .... http://www.theswamp.org/index.php?topic=21802.0  look for Mark's and Seven's and few others comments to Ghostscript.

Sorry for the confusion.
Title: Re: Ghostscript: The Thread
Post by: Robb on April 07, 2008, 10:12:29 PM
**Drops sonar buoy**

???

I'm asking what is the reason to convert plt to png? If I find it beneficial in any way I may use it.

Also, I am trying to run this script above.. I assumed I just create a .bat file and place it in a folder of plt files that I want to convert. Execute the script and all the plt files within that folder will be converted to png. Tried it and nothing happened. Then realized I may need to have ghostscript installed, installed it and still nothing. Do I need to run the script from within GSViewer?

Can someone help me out?

Thanks

No offense meant to you Robb.  Just me being all Smart Alec. (Another words, I was being a Greg)

My comment was to reference that I wanted to watch this topic becuase just like you, I am wanting to do the same thing.  Unfortunately; I had to shelve this project just at the start of my investigations to figure out how it was done.

What I have learned so far is that it produces PDF very efficiently and of sound quality. 
You might want to take a look at this thread over .... (let me go find it) .... http://www.theswamp.org/index.php?topic=21802.0  look for Mark's and Seven's and few others comments to Ghostscript.

Sorry for the confusion.


It's cool. I've never heard that term before so didn't know if it was a sarcastic remark or what... but there was no answer to my question that is why I gave the  :? , actually I wrote three questions marks and it substituted with that emoticon.

Thanks for the info and link! :)
Title: Re: Ghostscript: The Thread
Post by: Mark on April 07, 2008, 10:28:41 PM
I'm asking what is the reason to convert plt to png? If I find it beneficial in any way I may use it.
Well once in a while I need an image file of the plotted page, think exhibits with purdy graphics. Also it makes more sense at times to send out images rather than pdf's.

Quote
Also, I am trying to run this script above.. I assumed I just create a .bat file and place it in a folder of plt files that I want to convert. Execute the script and all the plt files within that folder will be converted to png.
Correct.

Quote
Tried it and nothing happened. Then realized I may need to have ghostscript installed, installed it and still nothing. Do I need to run the script from within GSViewer?

No. Most likely you don't have your windows path setup so that the batch file will find the gswin32c executable. Just add the complete path to the batch file and all should work. For instance, if you installed ghostscript in C:\Program Files\gs\ then you would change the batch file to read;
Code: [Select]
for %%f in (*.plt) do "C:\Program Files\gs\bin\gswin32c" -dSAFER -dBATCH -dNOPAUSE -r300  -sDEVICE=pnggray -sOutputFile="%%~nf.png" "%%f"
Title: Re: Ghostscript: The Thread
Post by: T.Willey on April 17, 2008, 12:59:47 PM
Thanks Mark for the contents of the bat file.  This will same a lot of time when I have to print to pdf, but I do have one question.  I have searched the net, and found out how to make it show the pdf landscape, but it won't show any of the information.  I added

Code: [Select]
-c "<< /Orientation 3 >> setpagedevice"

After the output file name.  Can someone help with rotating the prints to show landscape instead of portrait?  All the information will show when portrait, but will not when landscape.

Here is my whole line (pretty much Marks) for the conversion to a pdf.
Code: [Select]
for %%f in (*.plt) do "c:\gs\gs8.54\bin\gswin32c" -dSAFER -dBATCH -dNOPAUSE -r300 -sDEVICE=pdfwrite -sOutputFile="%%~nf.pdf" -c "<< /Orientation 3 >> setpagedevice" "%%f"

Thanks.
Title: Re: Ghostscript: The Thread
Post by: Mark on April 17, 2008, 01:22:24 PM
Try this one.

Code: [Select]
for %%f in (*.plt) do "c:\gs\gs8.61\bin\gswin32c" -dSAFER -dBATCH -dNOPAUSE -sOutputFile="%%~nf.pdf" -sDEVICE=pdfwrite -c "<</Orientation 3>> setpagedevice" -f "%%f"
P.S. I'm using a newer version so you'll need to change the path to gswin32c
Title: Re: Ghostscript: The Thread
Post by: T.Willey on April 17, 2008, 01:44:26 PM
Thank You Mark!!!

Now I need a switch to print upside down, as the rotation is upside down.  I think I saw an option for that, so I'll see if I can find it again, but if you/anyone knows it off the top of your heads I'm will to accept the help.   :-)
Title: Re: Ghostscript: The Thread
Post by: T.Willey on April 17, 2008, 02:45:31 PM
I have seen, in my searches, that the orientation for landscape could be 1 or 3.  I used 1 and now it is not upside down.  Thanks a lot.

Not to see if I can expand on this, and have them all put into one pdf file based on the numbers.  This might be a pipe drawing, but if it works that will be great.
Title: Re: Ghostscript: The Thread
Post by: Mark on April 17, 2008, 03:43:43 PM
Not to see if I can expand on this, and have them all put into one pdf file based on the numbers.  This might be a pipe drawing, but if it works that will be great.

I use pdftk for that because I get files from multiple sources.
Title: Re: Ghostscript: The Thread
Post by: Mark on April 17, 2008, 03:44:08 PM
Thank You Mark!!!

You're welcome! :)
Title: Re: Ghostscript: The Thread
Post by: T.Willey on April 17, 2008, 05:24:07 PM
Not to see if I can expand on this, and have them all put into one pdf file based on the numbers.  This might be a pipe drawing, but if it works that will be great.

I use pdftk for that because I get files from multiple sources.

Does this mean that it can't be done with ghostscript?  I see that if you list all the names, then it will, but I want it to find all the pdfs in the current directory and create a single pdf out of them.  I can't seem to find a way to do it without listing all the files to convert.  I don't know how to use batch files, so this is a learning experience, and I can't seem to find the correct resources.
Title: Re: Ghostscript: The Thread
Post by: Mark on April 17, 2008, 07:10:31 PM
Not to see if I can expand on this, and have them all put into one pdf file based on the numbers.  This might be a pipe drawing, but if it works that will be great.

I use pdftk for that because I get files from multiple sources.

Does this mean that it can't be done with ghostscript?

I'm not saying that because I'm not sure, I just like the pdftk works. :)

http://www.theswamp.org/index.php?topic=21802.msg265987#msg265987
Title: Re: Ghostscript: The Thread
Post by: Krushert on May 29, 2008, 02:35:13 PM
Okay so I got some time to give this Ghost Script a try to what it can do.

Well I manage to get a "_.at" File with this inside
Quote
-dCompatibilityLevel#1.4
A7.1
SERIES-A7.1.plt

For my batch file, I started with Mark's version (http://www.theswamp.org/index.php?topic=21802.msg265587#msg265587) and ended up with this.
Code: [Select]
rem @echo off
rem Ted Krush
rem 05/29/2008 - testing PDFs
rem
%echo off
::
echo looking for .plt files ....
echo.
echo.
echo Converting to pdf ....
echo.
for %%f in (*.plt) do call "C:\Program Files\GhostScript\ghostscript-8.62\lib\ps2pdf" %%f ..\output\%%~nf.pdf
echo.
echo.
echo.
echo.
echo.
echo.
echo All done!



I am assuming that the at file is a log file of what went wrong.  Where did I screw up at and where do I go to figure it out.

Title: Re: Ghostscript: The Thread
Post by: JohnK on May 29, 2008, 04:45:38 PM
Why are you calling the BAT file when you can/should get in the habit of calling the program...

Set up GS the right way; -i.e. at min. set up your environment vars, and then you can use this for all your conversion needs.

Code: [Select]
for %%f in (*.plt) do gswin32c -dSAFER -r600 -sDEVICE=pdfwrite -o "%%~nf.pdf" "%%f"
I created a VBS file instead of a BAT file, this way i can drag and drop files to that script to be converted (i dont have to convert all the files).
Title: Re: Ghostscript: The Thread
Post by: Krushert on May 29, 2008, 05:37:01 PM
Why are you calling the BAT file when you can/should get in the habit of calling the program...

Set up GS the right way; -i.e. at min. set up your environment vars, and then you can use this for all your conversion needs.

Code: [Select]
for %%f in (*.plt) do gswin32c -dSAFER -r600 -sDEVICE=pdfwrite -o "%%~nf.pdf" "%%f"

I DON'T KNOW! 
The way I have it set up was the most I got of it after trial and error.  I tried similar code that you guys have posted and got nothing but the dos shell.  Mater of fact I just tried you code above and got the same results

Noticed I downloaded the latest version and no where can find the exe file and the only gswin32 files that I found found are the 4 files in the image below.

Also I see mentioin of making a make file?  But I can't

I created a VBS file instead of a BAT file, this way i can drag and drop files to that script to be converted
This is what I want.  What is the difference besides the file extensions?  How do draft it up?  After a quick search, it is a Visual Basic and I have to say I know nothing about Visual Basic

(i dont have to convert all the files).
  Huh You only have to drag and drop some of them to to convert all of them?

Again I am fish out of water and all I am doing is flopping arround and making a big mess.
Title: Re: Ghostscript: The Thread
Post by: Keith™ on May 29, 2008, 05:42:39 PM
I would still like to see the ability to capture multiple plots and put them into a single PDF file
Title: Re: Ghostscript: The Thread
Post by: JohnK on May 29, 2008, 06:24:59 PM
<snip>
Again I am fish out of water and all I am doing is flopping arround and making a big mess.[/i]

*lmao* Yes you are! We need to talk tomorrow. I will get you all set up. 15 minutes tops.

BTW, your looking at the source code.

Keith, That's no problem. I will show you how tomorrow.


Im going home now.
Title: Re: Ghostscript: The Thread
Post by: Maverick® on May 29, 2008, 06:37:01 PM
Im going home now.

'Nite John boy.
Title: Re: Ghostscript: The Thread
Post by: JohnK on May 30, 2008, 10:28:52 AM
I would still like to see the ability to capture multiple plots and put them into a single PDF file

This is the essence for putting several files into one.

Code: [Select]
gs -sDEVICE=pdfwrite -o output.pdf file1.ps file2.ps file3.ps
Title: Re: Ghostscript: The Thread
Post by: Keith™ on May 30, 2008, 10:32:53 AM
Cool .. now I just need to automate it in my plotting script
Title: Re: Ghostscript: The Thread
Post by: T.Willey on May 30, 2008, 01:21:26 PM
Cool .. now I just need to automate it in my plotting script
Please post how you automate, as I couldn't figure it out.
Title: Re: Ghostscript: The Thread
Post by: Krushert on July 10, 2008, 12:05:44 PM
Has anyone run across issues with regards to Autocad wipe outs just become bleeding thru with certain plotters?

I am currently trying to find if there is a setting but I haven't exhausted searching thru things for a setting.
Title: Re: Ghostscript: The Thread
Post by: Mark on July 10, 2008, 12:21:11 PM
My printing Co. had problems with wipe-outs until we told them about a certain setting in Acrobat Reader.

Title: Re: Ghostscript: The Thread
Post by: Krushert on July 10, 2008, 12:56:13 PM
My printing Co. had problems with wipe-outs until we told them about a certain setting in Acrobat Reader.
It was uncheck and still is.  Actualy I tried checking it and it lessen the bleed thru but I set it back to uncheck..

Background. 
After getting set up by Se7en back in the middle of June (Thanks! Seven), I ran a project thru and FTPed the drawings to our Printer.  Since I we are under the gun on some other projects I was told thru set under desk since the owners and state housing authority and jump on other project.  I am not getting to that set.  The wipe outs in the right side of the sheet; from the printer's set; start to get lines in the middle of the wipe out.  I new it was a printer issue but using other PDF writers (autocad's and Adobe writer 5) in the past has never had a issue.  So verify that Ghostscript is or is not the problem ran the very same pdf file to our plotter (hp1050c and printer Sharp MX-2300 [8 1/2x11 & 11x17]).  The plotter no problem but the Sharp had major bleed thru.  (I really thought I had tested both printers back in June for this, but it was so long ago)  Tweaking some settings dpi and some ole raster slide bar in Ghostscript has made a slight improvement in the bleed thru from the Sharp
Title: Re: Ghostscript: The Thread
Post by: JohnK on July 10, 2008, 02:54:30 PM
No problem.

Can you email me one of those PDFs?
Title: Re: Ghostscript: The Thread
Post by: Krushert on July 10, 2008, 03:45:56 PM
No problem.

Can you email me one of those PDFs?
Coming at you.
Thanks.

What I have got so far is that if I crank down the DPI to 150 the bleeding stops on the Sharp and still maintains good line "crispness" but it plots horrible on the HP.  :x
Title: Re: Ghostscript: The Thread
Post by: T.Willey on July 25, 2008, 01:38:29 PM
Cool .. now I just need to automate it in my plotting script
Please post how you automate, as I couldn't figure it out.

I found a way to combine all the pdf's in one directory into one pdf with ghostscript.  You have to enable 'Delayed environment Variable Expansion' in the registry, but that is explained in the batch file code posted.  I couldn't figure out how to do it at run time.  They said to start a new command window with the /v:on statement, but I didn't know how to do that unless I have one batch open a new command window with the switch on, and then call another batch file to execute the code.  I'm welcomed to suggestions.

Code: [Select]
@echo off

::  The ! syntax is needed to cause the environment variable to
::  be evaluated every time it's referenced instead of only at
::  the beginning of the statement. This is known as Delayed
::  Environment Variable Expansion (catchy name, I know). This is
::  NOT turned on by default.
 
::  To turn on Delayed Environment Variable Expansion for this
::  just script, run cmd with the /v:on switch. To set Delayed
::  Environment Variable Expansion on permanently for a given
::  user on a machine, create this REG_DWORD value and set it to 1:
 
::  HKEY_CURRENT_USER\Software\Microsoft\Command Processor\DelayedExpansion

::  To set this as the default for all users on a given machine,
::  use this key instead:
 
::  HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\DelayedExpansion

::  http://aspn.activestate.com/ASPN/Mail/Message/activeperl/3002204
echo.

set list=
for /F "delims=" %%i in ('dir *.pdf /b /od') do set list=!list! %%i
"c:\gs\gs8.54\bin\gswin32c" -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=allfiles.pdf %list%
echo Done!

Here is code to create pdf of all the .plt's in the directory, and combine them into one pdf.

Code: [Select]
@echo off
::  process all the .plt files in this directory to create them as pdf files,
::  then add them all into one pdf file named "AllFiles.pdf"

::  The ! syntax is needed to cause the environment variable to
::  be evaluated every time it's referenced instead of only at
::  the beginning of the statement. This is known as Delayed
::  Environment Variable Expansion (catchy name, I know). This is
::  NOT turned on by default.
 
::  To turn on Delayed Environment Variable Expansion for this
::  just script, run cmd with the /v:on switch. To set Delayed
::  Environment Variable Expansion on permanently for a given
::  user on a machine, create this REG_DWORD value and set it to 1:
 
::  HKEY_CURRENT_USER\Software\Microsoft\Command Processor\DelayedExpansion

::  To set this as the default for all users on a given machine,
::  use this key instead:
 
::  HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\DelayedExpansion

::  http://aspn.activestate.com/ASPN/Mail/Message/activeperl/3002204
echo.
for %%f in (*.plt) do "c:\gs\gs8.54\bin\gswin32c" -dSAFER -dBATCH -dNOPAUSE -sOutputFile="%%~nf.pdf" -sDEVICE=pdfwrite -c "<</Orientation 1>> setpagedevice" -f "%%f"

set list=
for /F "delims=" %%i in ('dir *.pdf /b /od') do set list=!list! %%i
"c:\gs\gs8.54\bin\gswin32c" -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=AllFiles.pdf %list%

echo Done!

Edit:  If you want to delete the pdf files used to create the main pdf, then you can add this line right after you create the main pdf ( the blank line before 'echo Done!' ).
Code: [Select]
for %%f in ( %list% ) do del %%f