Send postscript file pages to different trays - ghostscript

I am trying to print a postscript file where the first page has to use one tray and the second page has to use a second one.
I have tried this using setDevice but it does not work. The printer either sends all pages to one tray or to another but does not switch between pages.
I tried with the following command
<</ManualFeed false /MediaPosition 0>> setpagedevice
I tried placing it before the %%BeginPageSetup and within the %%BeginPageSetup but it does not make a difference. I use ghostscript command to send it to the printer.
<</ManualFeed false /MediaPosition 0>> setpagedevice
%%Page: 1 1
%%BeginPageSetup
GS_pswrite_2_0_1001 begin
595 842 /a4 setpagesize
/pagesave save store 197 dict begin
0.1 0.1 scale
%%EndPageSetup
gsave mark
...
cleartomark end end pagesave restore
showpage
%%PageTrailer
<</ManualFeed false /MediaPosition 1>> setpagedevice
%%Page: 2 2
%%BeginPageSetup
GS_pswrite_2_0_1001 begin
595 842 /a4 setpagesize
/pagesave save store 197 dict begin
0.1 0.1 scale
%%EndPageSetup
gsave mark
...
cleartomark end end pagesave restore
showpage
%%PageTrailer
Here is the prolog
%%BeginProlog
% This copyright applies to everything between here and the %%EndProlog:
% Copyright (C) 2008 Artifex Software, Inc. All rights reserved.
%%BeginResource: procset GS_pswrite_2_0_1001 1.001 0
/GS_pswrite_2_0_1001 80 dict dup begin
/PageSize 2 array def/setpagesize{ PageSize aload pop 3 index eq exch
4 index eq and{ pop pop pop}{ PageSize dup 1
5 -1 roll put 0 4 -1 roll put dup null eq {false} {dup where} ifelse{ exch get exec}
{ pop/setpagedevice where
{ pop 1 dict dup /PageSize PageSize put setpagedevice}
{ /setpage where{ pop PageSize aload pop pageparams 3 {exch pop} repeat
setpage}if}ifelse}ifelse}ifelse} bind def
/!{bind def}bind def/#{load def}!/N/counttomark #
/rG{3{3 -1 roll 255 div}repeat setrgbcolor}!/G{255 div setgray}!/K{0 G}!
/r6{dup 3 -1 roll rG}!/r5{dup 3 1 roll rG}!/r3{dup rG}!
/w/setlinewidth #/J/setlinecap #
/j/setlinejoin #/M/setmiterlimit #/d/setdash #/i/setflat #
/m/moveto #/l/lineto #/c/rcurveto #
/p{N 2 idiv{N -2 roll rlineto}repeat}!
/P{N 0 gt{N -2 roll moveto p}if}!
/h{p closepath}!/H{P closepath}!
/lx{0 rlineto}!/ly{0 exch rlineto}!/v{0 0 6 2 roll c}!/y{2 copy c}!
/re{4 -2 roll m exch dup lx exch ly neg lx h}!
/^{3 index neg 3 index neg}!
/f{P fill}!/f*{P eofill}!/s{H stroke}!/S{P stroke}!
/q/gsave #/Q/grestore #/rf{re fill}!
/Y{P clip newpath}!/Y*{P eoclip newpath}!/rY{re Y}!
/|={pop exch 4 1 roll 1 array astore cvx 3 array astore cvx exch 1 index def exec}!
/|{exch string readstring |=}!
/+{dup type/nametype eq{2 index 7 add -3 bitshift 2 index mul}if}!
/#/currentfile #/${+ # |}!
/B{{2 copy string{readstring pop}aload pop 4 array astore cvx
3 1 roll}repeat pop pop true}!
/Ix{[1 0 0 1 11 -2 roll exch neg exch neg]exch}!
/,{true exch Ix imagemask}!/If{false exch Ix imagemask}!/I{exch Ix image}!
/Ic{exch Ix false 3 colorimage}!
/F{/Columns counttomark 3 add -2 roll/Rows exch/K -1/BlackIs1 true>>
/CCITTFaxDecode filter}!/FX{<</EndOfBlock false F}!
/X{/ASCII85Decode filter}!/#X{# X}!/&2{2 index 2 index}!
/#F{# &2<<F}!/#C{#X &2 FX}!
/$X{+ #X |}!/&4{4 index 4 index}!/$F{+ # &4<<F |}!/$C{+ #X &4 FX |}!
/IC{3 1 roll 10 dict begin 1{/ImageType/Interpolate/Decode/DataSource
/ImageMatrix/BitsPerComponent/Height/Width}{exch def}forall
currentdict end image}!
/~{# read {pop} if}!
end def
%%EndResource
/pagesave null def
%%EndProlog
Thanks for you help,
Pat

This isn't really a Ghostscript question.
The selection of tray position is device-dependent, you need to find out what your particular PostScript printer needs. If that fragment of PostScript is correct, then all I can suggest is that you try putting the setpagedevice after the setpagesize. I can't recall offhand exactly what that routine does, and you haven't included the entire prolog, but it certainly will involve a call to setpagedevice.
The obvious way to test this, of course, is to send a simple 'do nothing' PostScript test program with the tray selection commands to the printer:
%!
<</ManualFeed false /MediaPosition 0>> setpagedevice
showpage
<</ManualFeed false /MediaPosition 1>> setpagedevice
showpage
That should eject a blank page from each tray. If that doesn't work, then you need some other magic for your printer.
I note that the PostScript is fairly obviously the output from Ghostscript's ps2write device. You can have that device inject the PostScript for you by using the PSPageOptions switch. Of course, the PostScript still has to be correct for the device.

Related

Issue on DXF code for an ELLIPSE for AutoCad

I´m having an issue with a DXF code for an Ellipse, I´m trying to have it Graphed by AutoCad 2019 but it won´t recognize the code for an unknown reason. I would greatly apreciate any insight on the issue. Thanks a lot in advance
0
SECTION
2
ENTITIES
0
ELLIPSE
8
0
10
43.6886
20
16.2019
30
0
11
64.4949
21
16.2019
31
0
210
0
220
0
230
0
40
0.4
41
0
42
6.28319
0
ENDSEC
0
EOF
Well, you are missing some AutoCAD 'housekeeping' stuff in your dxf file. You have all the geometry bits for your ellipse, but AutoCAD doesn't know where to put them in the overall DXF file. So you have to include things like the drawing 'Handle' and the other required elements that place the ellipse in the overall framework of the whole drawing. An ellipse in a DXF file starts out like what is shown below:
ENTITIES
0
ELLIPSE
5
86
330
70
100
AcDbEntity
8
0
100
AcDbEllipse
10
43.6886
20
16.2019
30
0
The R2000 dxf spec will tell you what all those pieces are for specifically, but everything above
AcDbEllipse
10
is needed to place the ellipse in the greater context of the rest of the drawing. Without it, the ellipse would not be recognized.
I can tell you that code 8 identifies the layer the entity is on, in this case, 0 and code 5 identifies a unique handle (id code) for the entity, in this case 86. The handle must be unique for every entity in a dxf file. If you are manipulating/creating dxf entities in code, you have to be very careful to never have duplicate handles.
This ia an example of DXF with a line from 100,100,0 to 200,200,0
999
Start Section ***************************************************************
0
SECTION
999
Start Entities ****************************************************************
2
ENTITIES
999
Line ************************************************************************
0
LINE
8
LAYER1
10
100
20
100
30
0
11
200
21
200
31
0
0
ENDSEC
999
End Section ***************************************************************
999
End File ********************************************************************
0
EOF
999 is for comment
then you have to start section and entities
at the end close section and file
If you need more Info contact me

Encapsulated poscript max line limit

I think that I'm exceeding EPS max line limits:
I'm generating an eps programmatically that consists of a grid of pictures.
My EPS has this structure:
%!PS-Adobe-3.0 EPSF-3.0
.
.
%%BeginProlog
%%EndProlog
%%Page: 1 1
%%Begin Raster Image. Index: 0
save
449 2576 translate
0 rotate
-282 -304 translate
[1 0 0 1 0 0] concat
0 0 translate
[1 0 0 1 0 0] concat
0 0 translate
userdict begin
DisplayImage
0 0
564 608
12
564 608
0
0
FBDBB9FBDCBCFDDBBAFFD8B2FFD7A9FED4A1FCD29CFDD09EFED0A2FFD0A6FFCDA3FFCBA0FFCBA0...
EED79CEBD09CEDD19EEED2A1EFD3A3F0D4A5F0D4A6F0D4A7F1D4A4F3D4A0F3D49F
end
restore
%%End Raster Image
%%Begin Raster Image. Index: 1
.
.
end
restore
%%End Raster Image
%%Begin Raster Image. Index: 2
etc
So the thing is if I write up to 4 images to the EPS, everything works fine, but when I try to write a 5th, the eps won't open on any EPS viewer including Adobe Illustrator (the operation cannot complete because of an unknown error).
I tried using different images to make sure that the particular images were ok and I got the same result, as long as I'm writing 4 images (105825 lines file) everything works. But when I use 5 (132253 lines file) it fails.
Is it possible that I'm exceeding the maximum line limit for EPS?
This are the files in question if you'd like to analyze them:
the one that works - >https://files.fm/u/bfn2d32m and the one that doesn't ->
https://files.fm/u/4gbybr3y
There's no 'line limit' in PostScript or EPS, so you can't be hitting that.
When I run your file through Ghostscript it throws an error /undefined in yImage (I'd suggest you debug PostScript using a proper PostScript interpreter, not Adobe Illustrator).
This suggests to me that one of your images is using more data than you have supplied, so the interpreter runs off the end of the data, consuming parts of the program, until it has read sufficient bytes from currentfile to satisfy the request. At that point is starts processing the file as PostScript again, but the file pointer now points to the 'yImage' of the next 'DisplayImage'. Since you haven't defined a 'yImage' key, naturally this gives you an 'undefined' error.
From your description, this would seem likely to be the 4th image, since adding the 5th throws the error. Note that if your program terminates without supplying enough data (so the interpreter reaches EOF) then the data supplied will be drawn. So it might look like your 4th image is correct even when it isn't, provided it isn't followed by any further program code.
A style note; PostScript is a stack-based language, so normally one would proceed by pushing values onto the stack and reading them from there, instead of executing the 'token' operator.
So your input would be more like :
0 0
564 608
12
564 608
0
0
DisplayImage
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
...
And the DisplayImage code would be :
/DisplayImage
{
%
% Display a DirectClass or PseudoClass image.
%
% Parameters:
% x & y translation.
% x & y scale.
% label pointsize.
% image label.
% image columns & rows.
% class: 0-DirectClass or 1-PseudoClass.
% compression: 0-none or 1-RunlengthEncoded.
% hex color packets.
%
gsave
/buffer 512 string def
/byte 1 string def
/color_packet 3 string def
/pixels 768 string def
/compression exch def
/class exch def
/rows exch def
/columns exch def
/pointsize exch def
scale
translate
This avoids you having to use token at all for the scale and translate operations for instance.

how to delete character in ruby command line

I have a .txt file that contain my schedule of playlist for my tv channel. In the file there are many characters as 'logo_0 2' in. I run a ruby command to process the playlist (.txt file). How i want to delete these all 'logo_0 2' in the ruby ? Attached herewith is the .txt file and the rb file to execute the process. I need to eliminate the 'logo_0 2' in .txt file.
ITEM
preset_date 04/08/16
preset_time 22:09:00:00
title Awani (Comedy) Obviously Harith Iskander Sat Ep11 : Logo Inti College + Air Asia + Radio (E) Aug06 Sat 9.30pm
clip HUZKN01HM01AS
in_src 928500
out_src 929250
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148671633
aspect_ratio 2
channel_id 2
use_subtitle 0
end
ITEM
preset_date 04/08/16
preset_time 22:09:30:00
title RiaHD (Series) Lelaki Macam Dia : Generic (Bm) Isnin - Khamis # 2200
clip HUJST01HM01DV
in_src 1018125
out_src 1018875
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148669553
aspect_ratio 2
channel_id 2
use_subtitle 0
end
ITEM
preset_date 04/08/16
preset_time 22:10:00:00
title Citra Mustika (Movie Compact) August Highlights (Bm)
clip HUXAP01HM01CM
in_src 962500
out_src 963250
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148671344
aspect_ratio 2
channel_id 2
use_subtitle 0
end
ITEM
preset_date 04/08/16
preset_time 22:10:30:00
title Awani (News) Awani 7.45 (Bm) Setiap Hari # 1945
clip HULHP01HM01AE
in_src 909000
out_src 909750
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148671634
aspect_ratio 2
channel_id 2
use_subtitle 0
end
ITEM
preset_date 04/08/16
preset_time 22:11:00:00
title Episode Number 880
clip TAPE_REPLACEMENT
in_src 0
out_src 12000
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 1
notes Isu utama harian dan mingguan dikupas dengan mendalam oleh ahli panel.
user_data 05_P_174282654
logo_data_0 0
channel_id 2
end
ITEM
preset_date 04/08/16
preset_time 22:19:00:00
title Awani (News) Buletin Awani Noon (Bm) Setiap Hari # 1200
clip HUUIL01HM01AI
in_src 915000
out_src 915750
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148671635
aspect_ratio 2
channel_id 2
use_subtitle 0
end
ITEM
preset_date 04/08/16
preset_time 22:19:30:00
title Sports Rio Olympics 2016 - Opening Ceremony (BM) Live Aug6 6.55am
clip HUUUY01HM01AB
in_src 904000
out_src 904750
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148668511
aspect_ratio 2
channel_id 2
use_subtitle 0
end
ITEM
preset_date 04/08/16
preset_time 22:20:00:00
title Awani (Biz News) Bisnes Awani Plus (Bm) Sabtu # 1830
clip HPVAP01HM01DU
in_src 1050000
out_src 1050750
mode 1
no_vision_trans 1
no_audio_trans 1
type 1
logo_0 2
user_data 05_I_148671638
aspect_ratio 2
channel_id 2
use_subtitle 0
end
It would be good if you share your ruby code and we can show you how to update it.
filename = 'item.txt'
contents=File.read(filename)
contents.gsub!("logo_0 2\n", '')
File.open(filename, "w") { |f| f << contents }
In case you only want to replace characters contents.gsub!("logo_0 2", '') use this statement in place of contents.gsub!("logo_0 2\n", '')

High & Low Numbers From A String (Ruby)

Good evening,
I'm trying to solve a problem on Codewars:
In this little assignment you are given a string of space separated numbers, and have to return the highest and lowest number.
Example:
high_and_low("1 2 3 4 5") # return "5 1"
high_and_low("1 2 -3 4 5") # return "5 -3"
high_and_low("1 9 3 4 -5") # return "9 -5"
Notes:
All numbers are valid Int32, no need to validate them.
There will always be at least one number in the input string.
Output string must be two numbers separated by a single space, and highest number is first.
I came up with the following solution however I cannot figure out why the method is only returning "542" and not "-214 542". I also tried using #at, #shift and #pop, with the same result.
Is there something I am missing? I hope someone can point me in the right direction. I would like to understand why this is happening.
def high_and_low(numbers)
numberArray = numbers.split(/\s/).map(&:to_i).sort
numberArray[-1]
numberArray[0]
end
high_and_low("4 5 29 54 4 0 -214 542 -64 1 -3 6 -6")
EDIT
I also tried this and receive a failed test "Nil":
def high_and_low(numbers)
numberArray = numbers.split(/\s/).map(&:to_i).sort
puts "#{numberArray[-1]}" + " " + "#{numberArray[0]}"
end
When omitting the return statement, a function will only return the result of the last expression within its body. To return both as an Array write:
def high_and_low(numbers)
numberArray = numbers.split(/\s/).map(&:to_i).sort
return numberArray[0], numberArray[-1]
end
puts high_and_low("4 5 29 54 4 0 -214 542 -64 1 -3 6 -6")
# => [-214, 542]
Using sort would be inefficient for big arrays. Instead, use Enumerable#minmax:
numbers.split.map(&:to_i).minmax
# => [-214, 542]
Or use Enumerable#minmax_by if you like result to remain strings:
numbers.split.minmax_by(&:to_i)
# => ["-214", "542"]

Suggestions for data extraction Data in fortran

I use F95/90 and IBM compiler. I am trying to extract the numerical values from block and write in a file. I am facing a strange error in the output which I cannot understand. Every time I execute the program it skips the loop between 'Beta' and 'END'. I am trying to read and store the values.
The number of lines inside the Alpha- and Beta loops are not fixed. So a simple 'do loop' is of no use to me. I tried the 'do while' loop and also 'if-else' but it still skips the 'Beta' part.
Alpha Singles Amplitudes
15 3 23 4 -0.186952
15 3 26 4 0.599918
15 3 31 4 0.105048
15 3 23 4 0.186952
Beta Singles Amplitudes
15 3 23 4 0.186952
15 3 26 4 -0.599918
15 3 31 4 -0.105048
15 3 23 4 -0.186952
END `
The simple short code is :
program test_read
implicit none
integer::nop,a,b,c,d,e,i,j,k,l,m,ios
double precision::r,t,rr
character::dummy*300
character*15::du1,du2,du3
open (unit=10, file="1.txt", status='old',form='formatted')
100 read(10,'(a100)')dummy
if (dummy(1:3)=='END') goto 200
if(dummy(2:14)=='Alpha Singles') then
i=0
160 read(10,'(a4,i2,a6,i1,a4,i2,a6,i1,f12.6)')du1,b,du2,c,du3,d,du4,e,r
do while(du1.ne.' Bet')
write(*,'(a2,a4,i2,a6,i1,a4,i2,a6,i1,f12.6)')'AS',du1,b,du2,c,du3,d,du4,e,r
goto 160
end do
elseif (dummy(2:14)=='Beta Singles') then
170 read(10,'(a4,i2,a6,i1,a4,i2,a6,i1,f12.6)')du1,b,du2,c,du3,d,du4,e,r
if((du1=='END'))then
stop
else
write(*,'(a2,a4,i2,a6,i1,a4,i2,a6,i1,f12.6)')'BS',du1,b,du2,c,du3,d,du4,e,r
goto 170
end if
end if
goto 100
200 print*,'This is the end'
end program test_read
Your program never gets out of the loop which checks for Beta because when your while loop exits, it has already read the line with Beta. It then goes to 100 which reads the next line after Beta, so you never actually see Beta Singles. Try the following
character(len=2):: tag
read(10,'(a100)')dummy
do while (dummy(1:3).ne.'END')
if (dummy(2:14)=='Alpha Singles') then
tag = 'AS'
else if (dummy(2:14)=='Beta Singles') then
tag = 'BS'
else
read(dummy,'(a4,i2,a6,i1,a4,i2,a6,i1,f12.6)')du1,b,du2,c,du3,d,du4,e,r
write(*,'(a2,a4,i2,a6,i1,a4,i2,a6,i1,f12.6)')tag,du1,b,du2,c,du3,d,du4,e,r
end if
read(10, '(a100)') dummy
end do
print*,'This is the end'

Resources