Skip to main content
January 28, 2019
Question

Extract image from PostScript file

  • January 28, 2019
  • 2 replies
  • 1126 views

Hello Everyone.
I'm trying to extract an image from a PostScript file but with no success. In order to get the image, i actually convert the .ps file to .pdf - but it just shows blank.

I believe i did everything correctly according to the PostScript reference manual. So i would like to ask for any help.

My PostScript file is:

%!PS-Adobe-3.0 EPSF-3.0

%%Creator:  PostScript Test

%%BoundingBox: 0 0 1465 1191

%%LanguageLevel: 2

%%Pages: 1

%%DocumentData: Clean7Bit

100 100 scale

1465 1191 8 1465 0 0 -1191 0 1191]

/ASCIIHexDecode filter

/RunLengthDecode filter

{currentfile 3 100 mul string readhexstring pop} bind

false 3 colorimage

...hex image data...

>

Any input is very appreciated

Thanks a lot

Link for the full file on Google Drive:

TestPostScript.ps - Google Drive

This topic has been closed for replies.

2 replies

Participating Frequently
February 7, 2019

Hi.

abeddie’s comment is apt: using image with a dictionary is a much better approach than the colorimage operator.

In addition, note that rgb images often have a fourth byte added to each rgb sample, making the pattern “rgba rgba rgba…”, which is a problem because PostScript expects only three components per sample: rgb rgb rgb…

For my PostScript classes, I used to take image data from Photoshop EPS files and would have to run a short program that stripped every fourth byte from the data before I could use it.

As a side note, I’m assuming that the line in your sample code

  1465 1191 8 1465 0 0 -1191 0 1191]

was just a typo, omitting the opening bracket for the image matrix.

Best regards,

John

-------

John Deubert

Acumen Training

PostScript & PDF consulting and training

john@acumentraining.com

www.acumentraining.com

Participating Frequently
January 28, 2019

Typically an image dictionary would be used verses the colorimage operator e.g.

%!PS

10 10 scale

36 36 translate

/temp 4 string def

/DeviceCMYK setcolorspace

<<

  /ImageType 1

  /Width 8

  /Height 12

  /BitsPerComponent 1

  /Decode [ 0 1 0 1 0 1 0 1 ]

  /ImageMatrix [1 0 0 1 0 0]

  /DataSource { currentfile temp readhexstring pop }

%  /DataSource currentfile /ASCII85Decode filter

>>

image

AA77A7C7F770AAC7EDEDEDED

AA77A7C7F770AAC7EDEDEDED

AA77A7C7F770AAC7EDEDEDED

AA77A7C7F770AAC7EDEDEDED

showpage