Skip to main content
October 21, 2015
Answered

Replace or skip a line

  • October 21, 2015
  • 2 replies
  • 1520 views

Greetings!

I'm injecting a piece of ps code into an existing print stream with a separator page. The injecting works fine, but I can't to seem to get the injected code right. The code should actually skip (or delete or replace by empty line) one or more lines further down in the ps datastream.

I've tried using currentfile and readline/readstring but I can't seem to figure this out. How can I skip a command matching a certain text.

something like:

*here I setup some forms to overlay on the printjob*

%this is the code I created to skip a line/or delete/ignore it

{ currentfile 14 string

{2 copy readline {(12345X) search {exit}{pop} ifelse}{exit}ifelse} loop

pop pop

} exec

%end of my miserably failed tries

*here is the line I'm trying to skip/avoid, it maybe right after my code or further down the following ps code*

The line I'm trying to skip/avoid is the first line of the printjob itself, the hp driver adds a UEL <esc>%-12345X command which resets the memory and with it my ps code from the separator page (the forms to overlay the printjob with).

To test, I deleted the line I want to delete manually and it works. So all I need to complete this is a way to skip/delete/ignore it.

Thank you very much for any tips

Greetings,

Lex

This topic has been closed for replies.
Correct answer jdeubert

Hi, Cyberlex -

Two approaches come to mind here.

1. It would be interesting to redefine <esc>12345X as a PostScript procedure:

(\033%-12345X) cvlit { } def

The odd syntax (creating a string then converting it to a name) lets you create a name with an escape character in it.

If you place this line at the beginning of your ps file, the PostScript interpreter should treat the HP command as a PostScript procedure name which will execute our (empty) procedure.

2. The other thing to try would be to use the string as an end-of-job string in a SubFileDecode filter:

currentfile 0 (\033%-12345X) /SubFileDecode filter flushfile

In principle, the above line should cause everything in the PostScript stream to be ignored up to and including the first instance of <exc>%-12345X. Again, just put this at the start of your file and it should work.

For the details on how SubFileDecode works, I’ll refer you to Issue 17 (way back in June 2002) of the Acumen Journal. This is available free for the downloading at

acumentraining.com/acumenjournal.html

Hope this helps a bit.

- John

P.S. Oh, by the way, I haven't tested the above code snippets for typos. Sorry; in a rush.

-------

John Deubert

Acumen Training

PostScript & PDF consulting and training

john@acumentraining.com

www.acumentraining.com

2 replies

Legend
October 22, 2015

I feel this approach, no matter how ingenious, is doomed to failure. This escape is processed as a reset outside and above PostScript, so there is no way in PostScript to see it.

October 22, 2015

Greetings!

Aye, that's what I thought as well. But while playing around with the currentfile and readline, I could actually find the UEL reset line. What I did to find out was adding a bogus ps command so the printer would actually print a ps error page where I could see a positive match in an if eq to the UEL command on the stack. So it is actually running through the postscript interpreter of the hp device. Both PS and PCL do actually know the UEL universal exit language so the proposed solution from John works by flushing over the UEL till the next !PS.

The solution by defining the UEL as PS command did not work.

Thanks for taking your time,

Lex

jdeubertCorrect answer
Participating Frequently
October 22, 2015

Hi, Cyberlex -

Two approaches come to mind here.

1. It would be interesting to redefine <esc>12345X as a PostScript procedure:

(\033%-12345X) cvlit { } def

The odd syntax (creating a string then converting it to a name) lets you create a name with an escape character in it.

If you place this line at the beginning of your ps file, the PostScript interpreter should treat the HP command as a PostScript procedure name which will execute our (empty) procedure.

2. The other thing to try would be to use the string as an end-of-job string in a SubFileDecode filter:

currentfile 0 (\033%-12345X) /SubFileDecode filter flushfile

In principle, the above line should cause everything in the PostScript stream to be ignored up to and including the first instance of <exc>%-12345X. Again, just put this at the start of your file and it should work.

For the details on how SubFileDecode works, I’ll refer you to Issue 17 (way back in June 2002) of the Acumen Journal. This is available free for the downloading at

acumentraining.com/acumenjournal.html

Hope this helps a bit.

- John

P.S. Oh, by the way, I haven't tested the above code snippets for typos. Sorry; in a rush.

-------

John Deubert

Acumen Training

PostScript & PDF consulting and training

john@acumentraining.com

www.acumentraining.com

October 22, 2015

Greetings John!

You are my hero Thank you so much! /The SubFileDecode filter flushfile did the trick! I could ignore the driver generated UEL and PJL commands of the job by flushing until the next !PS.

/bow

Thanks again, very much appreciated!

Lex

Legend
October 22, 2015

Interesting. Sounds as if the escape sequence isn't implemented in the way I'd expect.