Copy link to clipboard
Copied
I need to add an image to my existing postscript. If an condition is satisfied, it need to print the new image (below code i got it when i converted it from jpg to ps) instead of the old image (designed using simple ps commands).
When i include the complete set of code, it prints FINE on a separate page.But i need to have the new logo in place of old logo based on a condition. To print this on a conditional basis, i need to move this withing the /NLOGO {.....} bind def and call the logo like below. But it fails (Error Message at the bottom). Please let me know where to NLOGO {.....} bind def definition.
code snippet from main
gsave
newpath
SA 00 get (R) eq
{ /Scalefactor .25 def
0 45 translate
Scalefactor Scalefactor scale
OLOGO } if
SA 00 get (M) eq
{ /Scalefactor .20 def
10 30 translate
Scalefactor Scalefactor scale
NLOGO } if
New Image
/languagelevel where
{ pop languagelevel } { 1 } ifelse
3 lt { /Helvetica findfont 12 scalefont setfont 50 500 moveto
(This print job requires a PostScript Language Level 3 printer.) show
showpage quit } if
/q { gsave } bind def
/Q { grestore } bind def
/cm { 6 array astore concat } bind def
/w { setlinewidth } bind def
/J { setlinecap } bind def
/j { setlinejoin } bind def
/M { setmiterlimit } bind def
/d { setdash } bind def
/m { moveto } bind def
/l { lineto } bind def
/c { curveto } bind def
/h { closepath } bind def
/re { exch dup neg 3 1 roll 5 3 roll moveto 0 rlineto
0 exch rlineto 0 rlineto closepath } bind def
/S { stroke } bind def
/f { fill } bind def
/f* { eofill } bind def
/n { newpath } bind def
/W { clip } bind def
/W* { eoclip } bind def
/BT { } bind def
/ET { } bind def
/BDC { mark 3 1 roll /BDC pdfmark } bind def
/EMC { mark /EMC pdfmark } bind def
/cairo_store_point { /cairo_point_y exch def /cairo_point_x exch def } def
/Tj { show currentpoint cairo_store_point } bind def
/TJ {
{
dup
type /stringtype eq
{ show } { -0.001 mul 0 cairo_font_matrix dtransform rmoveto } ifelse
} forall
currentpoint cairo_store_point
} bind def
/cairo_selectfont { cairo_font_matrix aload pop pop pop 0 0 6 array astore
cairo_font exch selectfont cairo_point_x cairo_point_y moveto } bind def
/Tf { pop /cairo_font exch def /cairo_font_matrix where
{ pop cairo_selectfont } if } bind def
/Td { matrix translate cairo_font_matrix matrix concatmatrix dup
/cairo_font_matrix exch def dup 4 get exch 5 get cairo_store_point
/cairo_font where { pop cairo_selectfont } if } bind def
/Tm { 2 copy 8 2 roll 6 array astore /cairo_font_matrix exch def
cairo_store_point /cairo_font where { pop cairo_selectfont } if } bind def
/g { setgray } bind def
/rg { setrgbcolor } bind def
/d1 { setcachedevice } bind def
/cairo_data_source {
CairoDataIndex CairoData length lt
{ CairoData CairoDataIndex get /CairoDataIndex CairoDataIndex 1 add def }
{ () } ifelse
} def
/cairo_flush_ascii85_file
{ cairo_ascii85_file status { cairo_ascii85_file flushfile } if } def
/cairo_image { image cairo_flush_ascii85_file } def
/cairo_imagemask { imagemask cairo_flush_ascii85_file } def
/cairo_set_page_size {
% Change paper size, but only if different from previous paper size otherwise
% duplex fails. PLRM specifies a tolerance of 5 pts when matching paper size
% so we use the same when checking if the size changes.
/setpagedevice where {
pop currentpagedevice
/PageSize known {
2 copy
currentpagedevice /PageSize get aload pop
exch 4 1 roll
sub abs 5 gt
3 1 roll
sub abs 5 gt
or
} {
true
} ifelse
{
2 array astore
2 dict begin
/PageSize exch def
/ImagingBBox null def
currentdict end
setpagedevice
} {
pop pop
} ifelse
} {
pop
} ifelse
} def
%%EndProlog
%%BeginSetup
%%EndSetup
%%Page: 1 1
q 0 0 135 32 rectclip
1 0 0 -1 0 32 cm q
Q q
q
0 0 135 32 re W n
[ 134.240005 0 0 -31.040001 0 31.040001 ] concat
/cairo_ascii85_file currentfile /ASCII85Decode filter def
/DeviceRGB setcolorspace
<<
/ImageType 1
/Width 2226
/Height 296
/Interpolate true
/BitsPerComponent 8
/Decode [ 0 1 0 1 0 1 ]
/DataSource cairo_ascii85_file /FlateDecode filter
/ImageMatrix [ 2226 0 0 -296 0 296 ]
>>
%}
cairo_image
Gb"-V^MY=9j6lrX"(-ZA]n*]s8(NEYJ-[`XL^+MFEeog=*$EPc(Kj:^#Tlfr&D@[*-ZB-_(
...
...
Az0T2fB%YmDSQ<R]%z!!(2'T?f\g!rr<$!!'6M+s?pdJ6BMen^-/?~>
Q
Q Q
showpage
%%Trailer
Error Received
Error: /syntaxerror in -file-
Operand stack:
NLOGO
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostri
val-- --nostringval-- false 1 %stopped_push 1 3 %oparray_pop 1 3 %oparray_pop 1 3 %oparray_pop .runexe
--nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval--
Dictionary stack:
--dict:1049/1123(ro)(G)-- --dict:0/20(G)-- --dict:151/200(L)--
Current allocation mode is local
Last OS error: 2
Current file position is 23334
1 Correct answer
Thanks a lot for your help. Finally, i was able to finish my project using the below code.
/ImageData
currentfile
<< /Filter /SubFileDecode
/DecodeParms << /EODCount 0 /EODString (*EOD*) >>
>> /ReusableStreamDecode filter
…..
[Insert your PS code here]
…..
*EOD* def
/LogoForm
<< /FormType 1
/BBox [0 0 212 792]
/Matrix [ 1 0 0 1 0 0]
...Copy link to clipboard
Copied
As many people have found, and been unable to proceed further, where an image uses inline data you CANNOT move it into a procedure. That’s because it expects to find the inline data at the current point in the file NOT the current point in the procedure.
The ReusableStream decide filter was designed for this. You’d need a complete rewrite.
Copy link to clipboard
Copied
Thanks for your response. Will you be able to help me re-writing?
Copy link to clipboard
Copied
/imgFile
% TBD replace the data between the following line and def with your image
currentfile<</Filter[/ASCII85Decode]>>/ReusableStreamDecode filter
def
/doimage
{
gsave
[540.0000 0.0000 0.0000 381.6000 36.0000 205.2000] concat
/ImageDict 8 dict def
ImageDict begin
/ImageType 1 def
/Width 1500 def
/Height 1060 def
/BitsPerComponent 8 def
/ImageMatrix [1500.0000 0.0000 0.0000 -1060.0000 0.0000 1060.0000] def
/DataSource imgFile /FlateDecode filter def
/MultipleDataSources false def
/Decode [ 0 1 ] def
end
[/CIEBasedA <<
/MatrixA [0.9642 1.0000 0.8249]
/WhitePoint [0.9642 1.0000 0.8249]
>>] setcolorspace
ImageDict image
grestore
imgFile resetfile
} def
% test image twice
50
{
0 144 translate
doimage
0 -360 translate
doimage
showpage
} repeat
% note image data cut out
Copy link to clipboard
Copied
Again Thanks. I may need some more help. Code in italics is what i got after converting the image to EPS. Code in bold is what you suggested. I am getting the error message (refer the bottom). I tried putting the below lines and still got the same error message. "/imgFile currentfile<</Filter[/ASCII85Decode]>>/ReusableStreamDecode filter" after "%%EndProlog".
Please advise.
/imgFile
currentfile<</Filter[/ASCII85Decode]>>/ReusableStreamDecode filter
%!PS-Adobe-3.0
%%Creator: cairo 1.15.10 (http://cairographics.org)
%%CreationDate: Mon May 14 18:02:32 2018
%%Pages: 1
%%DocumentData: Clean7Bit
%%LanguageLevel: 3
%%DocumentMedia: 188x25mm 534 71 0 () ()
%%BoundingBox: 0 0 535 72
%%EndComments
%%BeginProlog
/languagelevel where
{ pop languagelevel } { 1 } ifelse
3 lt { /Helvetica findfont 12 scalefont setfont 50 500 moveto
(This print job requires a PostScript Language Level 3 printer.) show
showpage quit } if
/q { gsave } bind def
/Q { grestore } bind def
/cm { 6 array astore concat } bind def
/w { setlinewidth } bind def
/J { setlinecap } bind def
/j { setlinejoin } bind def
/M { setmiterlimit } bind def
/d { setdash } bind def
/m { moveto } bind def
/l { lineto } bind def
/c { curveto } bind def
/h { closepath } bind def
/re { exch dup neg 3 1 roll 5 3 roll moveto 0 rlineto
0 exch rlineto 0 rlineto closepath } bind def
/S { stroke } bind def
/f { fill } bind def
/f* { eofill } bind def
/n { newpath } bind def
/W { clip } bind def
/W* { eoclip } bind def
/BT { } bind def
/ET { } bind def
/BDC { mark 3 1 roll /BDC pdfmark } bind def
/EMC { mark /EMC pdfmark } bind def
/cairo_store_point { /cairo_point_y exch def /cairo_point_x exch def } def
/Tj { show currentpoint cairo_store_point } bind def
/TJ {
{
dup
type /stringtype eq
{ show } { -0.001 mul 0 cairo_font_matrix dtransform rmoveto } ifelse
} forall
currentpoint cairo_store_point
} bind def
/cairo_selectfont { cairo_font_matrix aload pop pop pop 0 0 6 array astore
cairo_font exch selectfont cairo_point_x cairo_point_y moveto } bind def
/Tf { pop /cairo_font exch def /cairo_font_matrix where
{ pop cairo_selectfont } if } bind def
/Td { matrix translate cairo_font_matrix matrix concatmatrix dup
/cairo_font_matrix exch def dup 4 get exch 5 get cairo_store_point
/cairo_font where { pop cairo_selectfont } if } bind def
/Tm { 2 copy 8 2 roll 6 array astore /cairo_font_matrix exch def
cairo_store_point /cairo_font where { pop cairo_selectfont } if } bind def
/g { setgray } bind def
/rg { setrgbcolor } bind def
/d1 { setcachedevice } bind def
/cairo_data_source {
CairoDataIndex CairoData length lt
{ CairoData CairoDataIndex get /CairoDataIndex CairoDataIndex 1 add def }
{ () } ifelse
} def
/cairo_flush_ascii85_file
{ cairo_ascii85_file status { cairo_ascii85_file flushfile } if } def
/cairo_image { image cairo_flush_ascii85_file } def
/cairo_imagemask { imagemask cairo_flush_ascii85_file } def
/cairo_set_page_size {
% Change paper size, but only if different from previous paper size otherwise
% duplex fails. PLRM specifies a tolerance of 5 pts when matching paper size
% so we use the same when checking if the size changes.
/setpagedevice where {
pop currentpagedevice
/PageSize known {
2 copy
currentpagedevice /PageSize get aload pop
exch 4 1 roll
sub abs 5 gt
3 1 roll
sub abs 5 gt
or
} {
true
} ifelse
{
2 array astore
2 dict begin
/PageSize exch def
/ImagingBBox null def
currentdict end
setpagedevice
} {
pop pop
} ifelse
} {
pop
} ifelse
} def
%%EndProlog
%%BeginSetup
%%EndSetup
%%Page: 1 1
%%BeginPageSetup
%%PageMedia: 188x25mm
%%PageBoundingBox: 0 0 535 72
535 72 cairo_set_page_size
%%EndPageSetup
q 0 0 535 72 rectclip
1 0 0 -1 0 72 cm q
Q q
q
0 0 535 72 re W n
[ 534.240005 0 0 -71.040001 0 71.040001 ] concat
/cairo_ascii85_file currentfile /ASCII85Decode filter def
/DeviceRGB setcolorspace
<<
/ImageType 1
/Width 2226
/Height 296
/Interpolate true
/BitsPerComponent 8
/Decode [ 0 1 0 1 0 1 ]
/DataSource cairo_ascii85_file /FlateDecode filter
/ImageMatrix [ 2226 0 0 -296 0 296 ]
>>
cairo_image
Gb"-V^MY=9j6lrX"(-ZA]n*]s8(NEYJ-[`XL^+MFEeog=*$EPc(Kj:^#Tlfr&D@[*-ZB-_(
....
....
Az0T2fB%YmDSQ<R]%z!!(2'T?f\g!rr<$!!'6M+s?pdJ6BMen^-/?~>
Q
Q Q
showpage
%%Trailer
%%EOF
def
/doimage
{
gsave
[540.0000 0.0000 0.0000 381.6000 36.0000 205.2000] concat
/ImageDict 8 dict def
ImageDict begin
/ImageType 1 def
/Width 1500 def
/Height 1060 def
/BitsPerComponent 8 def
/ImageMatrix [1500.0000 0.0000 0.0000 -1060.0000 0.0000 1060.0000] def
/DataSource imgFile /FlateDecode filter def
/MultipleDataSources false def
/Decode [ 0 1 ] def
endve
[/CIEBasedA <<
/MatrixA [0.9642 1.0000 0.8249]
/WhitePoint [0.9642 1.0000 0.8249]
>>] setcolorspace
ImageDict image
grestore
imgFile resetfile
} def
Error Message Received
Error: /ioerror in --readstring--
Operand stack:
imgFile --nostringval-- --dict:1/1(L)-- --dict:1/1(L)-- --nostringval-- --nostringval-- true --dict:0/10(L)-- -
ostringval-- --nostringval-- (\f\234\322u\3257%k\310\r<\257\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\00
000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\00
000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\00
000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\00
000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\00
000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\00
000\000\000\000\000\000...)
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostri
val-- --nostringval-- false 1 %stopped_push 1 3 %oparray_pop 1 3 %oparray_pop 1 3 %oparray_pop .runexe
--nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- 4 3 %oparray_pop 3 3 %opa
ay_pop --nostringval-- --nostringval-- --nostringval-- %loop_continue --nostringval-- --nostringval-- --nostringval-
Dictionary stack:
--dict:1049/1123(ro)(G)-- --dict:0/20(G)-- --dict:106/200(L)--
Current allocation mode is local
Last OS error: 2
Copy link to clipboard
Copied
Below is an example with data. Start by ensuring this works and then you need to replace the image data and dictionary with yours.
This example is ASCII85 so you'll also need the correct decode filter(s) for your image.
%!PS-Adobe-2.0
%%Pages: 1
%%EndComments
%%EndProlog
%%BeginSetup
%%EndSetup
%%BeginPageSetup
%%Page: 1 1
%%EndPageSetup
/imgFile
currentfile
/ASCII85Decode filter <</Intent 0 /AsyncRead true>>
/ReusableStreamDecode filter
2dK<@>Z*Od;EA#[4BbWH=].Fd;En8]6<ZuG=%>GT7QsjB5#t-;=%>Y`9M&Yi3*oND
>uNah;`\,\4BbWG=A_4`;*@rV6!6cD=%>GT7QsjB5?C??=@bkd9hStp3abrL?WB-n
<'"5]4'>EB<_kbV:-2EM6!6cD=%>GT7R'sE5ZgQD>"V=n:ekV'4(2/O?WB-n<'"5]
3`o3><DGMP9K?!E5ZgQA=%>JV7mU9L6<ZuM>tn"'<)RI73F>`H?;rpj;`S#Y3EK!;
<DGPR9fZ*F5ZgQ@<^o;T7m^BO79rVZ@8Tj7=BBEJ2I'*<>>[:^:cMTS3EK!<<_keX
:HMNN5?C?=<^o;T7mgKR7pf%cA5lNE>[)8Z10@7,=%tMR:,c9N3`o3@=&;%^;*J&Y
5#t-:<^o>V846]V8RYIkAl_uO?X@nf03(V!<D,)J9K#sI3`o3B=].If;aFSd5#t-:
<^o>V84?fY8n([oB3/2S?sn4m/PAA`:dm-?8i9aG2crd7=%tkY9gDWO793/R=ADIm
;,(Cr:h!=%B2i#M=^5lL/PAA`:dm*=8MsXF2crd7=%tkY9gDWO7TWAV=\h[q;GCLs
:h!=$AlDfI=BfZH/PAA`:dm-?8i9aG3*B!:=%tkY9gM`R7p&SZ>#7js;GCLs:LR*u
APuQC<`s6@024eh;F`QG9K-0O3Ef3?=\h:a:I8&W8Qo"a>>\(";b^Ut:1-mp@o-*9
;c[U41JpY"<D#2S:HDf[4^M&O>uO-q;asng93bFi>uOI(<)$^u9j^[k@89X/:fCt(
3*&^7>>RFi<'Oko6=X+c@TZ30=A)t&9jUjp?;s[,<D?h!9O:If?VF4':/GFr4^1cJ
?W9=&=[Zq.7qc1"B3e8D>u5$::1%'t?WBj.<D?h!93k7a>tRdt9MJng5[IDV@TPs2
>XrR:8o%g.C1'nP?rLZF:LI:#?rg'2<_Zq"8mG%]>Y.Rp92&\c~>
def
[540.0000 0.0000 0.0000 540.0000 36.0000 126.0000] concat
/ImageDict 8 dict def
ImageDict begin
/ImageType 1 def
/Width 16 def
/Height 16 def
/BitsPerComponent 8 def
/ImageMatrix [16.0000 0.0000 0.0000 -16.0000 0.0000 16.0000] def
/DataSource imgFile def
/MultipleDataSources false def
/Decode [ 0 1 0 1 0 1 ] def
end
[/CIEBasedABC <<
/DecodeABC [ { dup 0.0405 le {12.9232 div} {0.0550 add 1.0550 div 2.4000 exp} ifelse } bind dup dup ]
/MatrixABC [
0.412381 0.212620 0.019343
0.357573 0.715139 0.119212
0.180452 0.072150 0.950507]
/WhitePoint [0.9504 1.0000 1.0889]
>>] setcolorspace
ImageDict image
showpage
%%PageTrailer
%%Trailer
%%EOF
Copy link to clipboard
Copied
Thanks a lot for your help. Finally, i was able to finish my project using the below code.
/ImageData
currentfile
<< /Filter /SubFileDecode
/DecodeParms << /EODCount 0 /EODString (*EOD*) >>
>> /ReusableStreamDecode filter
…..
[Insert your PS code here]
…..
*EOD* def
/LogoForm
<< /FormType 1
/BBox [0 0 212 792]
/Matrix [ 1 0 0 1 0 0]
/PaintProc
{ pop
/ostate save def
/showpage {} def
/setpagedevice /pop load def
% 10 150 translate % change to the position you need
% 1 1 scale % remove or alter to change size
ImageData 0 setfileposition ImageData cvx exec
ostate restore
} bind
>> def
%
*************done**************
Use the below command to call the image.
/Scalefactor .25 def
LogoForm execform

