Skip to main content
November 11, 2015
Answered

How to insert a .png image to postscript file that with /ASCII85Decode filter /LZWDecode filter.

  • November 11, 2015
  • 1 reply
  • 22320 views

In linux, I want to develop a customed printer driver.

when print a document, I have get the postscript file send to postscript printer driver, the file content is shown below:

%!PS-Adobe-3.0

%%BoundingBox: 0 0 612 792

%%HiResBoundingBox: 0 0 612.00 792.00

%%Creator: GPL Ghostscript 910 (ps2write)

%%LanguageLevel: 2

%%CreationDate: D:20151103175615+08'00'

%%Pages: 1

%%EndComments

%%BeginProlog

currentfile /ASCII85Decode filter /LZWDecode filter cvx exec

J.'GP1)YJ2:a-L/6rF=&5]f",9VMV4PfsINPg$$lJV;<[.@O%03.smQ('PQ#V^%=ggiP:i9P6m1

&e,,#6QsIUEP1^W4j%>VfmLeP21i['0XteJ5'-rMBI73qYi]MqRS:_)[:!GtMG0%^!tgdCBfAL(

FIC*'*+_5Lbn>92]]a#cSAZ&>A@c2Y\jd2S!P$:g'tTf,7oM*o%:D37/I$S.]\mgscphMRIG413

(Z=Q;")5F8)`Qr"=NfCOoQ)ibUD`CCLE1_#S2=*J!5rCj3Lri1"+f$rI5+n6R8\*imVK6JF'6bb

...

In this file, contains some string in /ASCII85Decode filter /LZWDecode filter, what is meaning of this string, what contents does it contained? And how to generate this string.

And now, I want to edit this postscript file, and add a .png image to print content. How can I do?

Thank you for your help!

This topic has been closed for replies.
Correct answer Test Screen Name

This indicates that the data is compressed with LZW compression, then turned to a compact ASCII representation. LZW is as used in GIF, but that doesn't mean someone has dumped a GIF file.

PNG files use Flate compression but you can't dump a PNG file into PostScript. Your steps

1. Understand the PostScript imaging model.

2. Understand the PostScript image format.

3. Understand how filters are specified in PostScript.

4. Completely parse and decompress the PNG. Hope it does not have an alpha channel!

5. Convert the PNG data you parsed into PostScript.

6. Add suitable image transforms.

7. Add to PostScript. Discovering the right point may not be simple.

Working with JPEG is a bit simpler, since most JPEG files are directly compatible with the DCTDecode filter.

If you don't have the PostScript Language Reference Manual, you will need it, and you'll need to spend some weeks or months immersed in it...

1 reply

November 11, 2015
Please download the attached file to view this post
Test Screen NameCorrect answer
Brainiac
November 11, 2015

This indicates that the data is compressed with LZW compression, then turned to a compact ASCII representation. LZW is as used in GIF, but that doesn't mean someone has dumped a GIF file.

PNG files use Flate compression but you can't dump a PNG file into PostScript. Your steps

1. Understand the PostScript imaging model.

2. Understand the PostScript image format.

3. Understand how filters are specified in PostScript.

4. Completely parse and decompress the PNG. Hope it does not have an alpha channel!

5. Convert the PNG data you parsed into PostScript.

6. Add suitable image transforms.

7. Add to PostScript. Discovering the right point may not be simple.

Working with JPEG is a bit simpler, since most JPEG files are directly compatible with the DCTDecode filter.

If you don't have the PostScript Language Reference Manual, you will need it, and you'll need to spend some weeks or months immersed in it...

Brainiac
November 11, 2015

I examined it more closely. The line with filter ... exec applies LZW and ASCII85 decoding, but what is decoded is not an image but an encoding section of PostScript code. I imagine this is a simple form of copy protection of the procedures included.

You can provisionally ignore it. But this file is a very abstracted representation of data that was original PDF. Your problem is a bit like trying to automatically modify a C++ app to make it always pop-up a logo. Very tough to do in the general case where anyone could have written the app in any style.