Overlay two postscript files (command line approach)?

前端 未结 3 2058
闹比i
闹比i 2020-12-31 21:05

I\'m aware that similar questions have been answered here before:

  • postscript - overlay one pdf or ps file on top of another - Stack Overflow
  • overlay -
相关标签:
3条回答
  • 2020-12-31 21:40

    A similar approach to KenS's would be to put the "composition" code in a single file and call the component files with the run operator. It amounts to the same thing but with a little less shell-work. A limitation is that the -dSAFER option (which is ON by default in most Distiller installations) disables the run operator.

    combo.ps:

    /Oldshowpage /showpage load def
    /showpage {} def
    gsave
        (tmp-Front.ps) run
    grestore
        %additional scaling and translation to place the graphic?
        (logo.ps) run
    Oldshowpage
    
    0 讨论(0)
  • 2020-12-31 21:55

    Ok, here is what works for me, thanks to @luserdroog's answer, with unchanged files, and "directly" in evince.

    First of all, get tmp-Front.ps, logo.ps and @luserdroog combo.ps (modded below) in a directory. The first problem is that if evince encounters %%EOF, it will stop parsing whatever comes next. So, we first want to get rid of those directives in tmp-Front.ps and logo.ps:

    sed -i 's/%%EOF/% %EOF/' logo.ps
    sed -i 's/%%EOF/% %EOF/' tmp-Front.ps
    

    Second, if evince doesn't encounter %%Orientation and similar directives at the very beginning, then it will not show the document in landscape (as the original tmp-Front.ps is). Thus, we should extract these directives from tmp-Front.ps, and add them at the beginning of combo.ps - and save all that as new file, combopg.ps:

    cat <(echo '%!') <(grep '%%Pages\|%%PageOrder\|%%BoundingBox\|%%DocumentMedia\|%%Orientation' tmp-Front.ps) <(echo) combo.ps > combopg.ps
    

    Here I use the following modification of combo.ps:

    /Oldshowpage /showpage load def
    /showpage {} def
    gsave
        (tmp-Front.ps) run
    grestore
        %additional scaling and translation to place the graphic?
        1 1 scale
        300 300 translate
        0 0 moveto
    
        (logo.ps) run
    Oldshowpage
    

    Finally, since evince doesn't recognize the run directive, I use this modification of psinc, psinc.pl to "include" the contents of the files:

    cat combopg.ps | perl ./psinc.pl > combopgout.ps
    

     

    Now, you can finally open combopgout.ps in evince - and simultaneously in a text editor, where you can look for the line 300 300 translate; editing these arguments in the text editor and saving the file will cause evince to reload the .ps file and show the latest position - it would look like this for the default:

    combopgout.ps.png

    (Note the logo is rotated as per landscape orientation)

     

    Well, I guess this solves it - thanks for the answers!!

    0 讨论(0)
  • 2020-12-31 21:56

    In order to 'concatenate' the two files, you would need to disable the 'showpage' operator, as otherwise both files will emit their pages separately. But you need to maintain the original definition so that you can emit the final document. Somethign liek:

    /Oldshowpage showpage load def
    /showpage {} def
    
    ...
    file1
    ...
    ...
    file2
    ...
    Oldshowpage
    

    So if you saved the redefinitions in a file, and the final execution in another file you might cat 'prolog.ps file1.ps file2.ps epilog.ps'

    Neither of your files executes a media request (you can ignore the %% lines, those are comments only).

    However, as you rightly say you don't want scaling and transforms to persist between jobs. So you need to save and restore the graphics state. So in this case you also want a 'middle' file.

    So prolog.ps contains:

    /Oldshowpage showpage load def
    /showpage {} def
    gsave
    

    middle.ps contains

    grestore
    

    and epilog.ps contains

    Oldshowpage
    

    cat all 5 files together and it ought to work. It does something sensible for me, but I should perhaps mention that your 'logo.ps' produces an empty page for me with Ghostscript and with Adobe Distiller.

    0 讨论(0)
提交回复
热议问题