gpt4 book ai didi

linux - 覆盖两个 postscript 文件(命令行方法)?

转载 作者:行者123 更新时间:2023-12-02 18:31:03 25 4
gpt4 key购买 nike

我知道之前已经在这里回答了类似的问题:

  • postscript - overlay one pdf or ps file on top of another - Stack Overflow
  • overlay - Overlaying or merging multiple .ps files - Stack Overflow

  • ...但是,由于他们没有直接回答我的具体问题,我会再试一次。

    我想知道,如何覆盖两个 postscript 文件:一个 - 一个标志:
  • logo.ps

  • ... 在另一个之上 - 图形背景:
  • tmp-Front.ps

  • .... 在 Linux 中使用命令行方法。

    重要的是,图形背景尽可能地保留其原始内容。因此,如果我能以某种方式将两个原始 postscript 文件内容保持不变(见下文),我可能会最高兴 - 但除此之外,我想知道像 ghostscript 这样的命令行工具是如何工作的。可以用于此目的。

    问题 - PCB .ps 打印输出顶部的徽标

    这是更详细的问题 - 我想在 PCB 板打印品的顶部添加一个标志。我用 kicad开发PCB打印;完成后,我会导出带有各个图层的 postscript 文档。通常,我想让前面的铜层“镜像”;我经常尝试将 .ps 输出加载到 inkscape 中。 ,然后尝试在那里进行镜像。使用 inkscape也很方便,因为人们可以轻松地在那里添加徽标(然后将打印品和徽标镜像在一起)。

    但是,使用 inkscape处理 postscript 输出是一项昂贵的操作(因为 inkscape 需要一段时间才能加载,并进行镜像和保存)......虽然,这里的主要表现是:处理后,一些尺寸 inkscape 可能会在输出文件中稍作更改(当目标是打印小于一毫米宽的轨道时,它会产生很大的不同)。

    所以,鉴于 kicad ■ “绘图”命令有一个镜像选项——当然,对我来说,直接从 kicad“镜像”图层打印效果要好得多。 s“绘图”命令;输出又是一个 postscript 文件。 tmp-Front.ps是此类(镜像)后记文件的示例。请注意,通常情况下,“铜”部分填充为黑色 - 我基本上希望在其顶部有一个白色徽标。

    现在,由于这个打印已经“镜像”了——如果我想在它上面添加一个标志,我最好也镜像这个标志。所以我开火 inkscape ;和:
  • 为标志添加文字;
  • 通过文档属性设置:
  • 文档大小与徽标大小匹配,以及
  • 文档应该有黑色背景
  • 然后将徽标文本更改为白色填充;
  • 在徽标文本上执行对象/水平翻转;然后
  • 做文件/保存副本;
  • 选择 PostScipt (*.ps) 作为输出;
  • 在对话框中选择 PostScript 级别 2,然后
  • 导出前选择“将文本转换为路径”。

  • 就是这样 logo.ps以上链接已生成(请注意 - 对于此类小徽标:没有“文本到路径”,.ps 文件(带字体)最多可达 20 kB;而仅路径为 5 kB)。

    但是,一个问题是 postscript 并不真正支持诸如“文档背景”颜色之类的东西 - 显然您需要自己定义一个填充矩形:
  • Adobe Forums: How to change ps file page background to transparent ;
  • Re: Exporting canvas to PostScript loses background color ;

  • ... 因此,如果您打开 logo.ps ,您将看不到任何内容 - 因为它包含白色背景上的白色字母。

    观众

    如果在 logo.ps , 1 g行被替换为 0.5 g ;徽标变为灰色(并且可见),此处呈现在 evince 下, gs原始查看器和 gv :

    view-logo.png

    这是 tmp-Front.ps 的相同比较:

    view-tmp-Front.png

    值得注意的是,原始 ghostscript查看器会忽略边界框和页面方向 - 更有问题的是,如果您在上网本上使用 Ubuntu Gnome,那么顶部和底部栏可能会减少 ghostscript查看器窗口 - 足以使左下角的徽标不可见;并且由于“ ... the raw ghostscript viewer gs ... has no real user interface”,一个 gs以裁剪徽标启动的窗口,无法设置为之后显示。

    连接 .ps 文件内容以进行叠加

    通过查看这些引用资料:
  • Ghostscript overlaying concatenated postscript files - comp.lang.postscript
  • Re: Merge postscript files - comp.lang.postscript ;
  • Getting rid of pagethrow on merge - Mombu the Programming Forum

  • ...我猜,原则上,应该可以连接两个 postscript 文件的文件内容;如果只有一个 showpage合并文件中的命令 - 那么,原则上,应该获得两者的叠加(?!)。但是,我尝试过,但我无法真正让它发挥作用。

    如果这是可能的,我想以某种方式复制/粘贴 postscript 文件内容(从而避免文档尺寸/大小/分辨率的任何问题) - 然后可能使用 translate postscript 命令(参见 Postscript Editing in Gnuplot )来调整徽标的位置。在 evince 中打开“覆盖”(合并).ps , 每次出现 translate 都会刷新文档显示参数在文本编辑器中更改 - 因此以这种方式处理徽标定位应该相对容易。

    但是,我也可以预见到一些问题:首先,图形( tmp-Front.ps )包含:
    %%BoundingBox: 0 0 596 843
    %%DocumentMedia: A4 595 842 0 () ()
    ...
    0.0072 0.0072 scale
    ...
    30085 54415 moveto
    ...

    ... 而 logo.ps包含:
    %%BoundingBox: 0 0 31 13
    ...
    %%DocumentMedia: 11x4mm 31 13 0 () ()
    ...
    25.539 9.536 m(oveto) ...
    ...

    ...因此有两个主要区别:
  • 文件大小不一样
  • 比例(或者更确切地说是分辨率/坐标系)也不相同

  • 由于我根本无法将文件内容串联起来 - 我不确定这些差异是否会影响覆盖......我当然希望它们以某种方式独立呈现;和 translate只会有助于正确设置他们的相对位置:)

    那么 - 如果我想通过连接 postscript 文件内容来实现覆盖,我该怎么做?如果这太麻烦 - 我怎么能使用诸如 ghostscript 之类的工具? (或任何其他),以便设置覆盖?

    非常感谢您的任何答案,
    干杯!



    作为引用,这里是提到的 postscript 文件的副本(因为它们不是太大):

    tmp-Front.ps :
    %!PS-Adobe-3.0
    %%Creator: PCBNEW-PS
    %%CreationDate: Thu Mar 22 09:50:52 2012
    %%Title: /tmp-Front.ps
    %%Pages: 1
    %%PageOrder: Ascend
    %%BoundingBox: 0 0 596 843
    %%DocumentMedia: A4 595 842 0 () ()
    %%Orientation: Landscape
    %%EndComments
    %%Page: 1 1
    /line {
    newpath
    moveto
    lineto
    stroke
    } bind def
    /cir0 { newpath 0 360 arc stroke } bind def
    /cir1 { newpath 0 360 arc gsave fill grestore stroke } bind def
    /cir2 { newpath 0 360 arc gsave fill grestore stroke } bind def
    /arc0 { newpath arc stroke } bind def
    /arc1 { newpath 4 index 4 index moveto arc closepath gsave fill grestore stroke } bind def
    /arc2 { newpath 4 index 4 index moveto arc closepath gsave fill grestore stroke } bind def
    /poly0 { stroke } bind def
    /poly1 { closepath gsave fill grestore stroke } bind def
    /poly2 { closepath gsave fill grestore stroke } bind def
    /rect0 { rectstroke } bind def
    /rect1 { rectfill } bind def
    /rect2 { rectfill } bind def
    /linemode0 { 0 setlinecap 0 setlinejoin 0 setlinewidth } bind def
    /linemode1 { 1 setlinecap 1 setlinejoin } bind def
    /dashedline { [50 50] 0 setdash } bind def
    /solidline { [] 0 setdash } bind def
    gsave
    0.0072 0.0072 scale
    linemode1
    82670 0 translate 90 rotate
    60 setlinewidth
    60 setlinewidth
    newpath
    30085 54415 moveto
    30085 52585 lineto
    31915 52585 lineto
    31915 54415 lineto
    30085 54415 lineto
    poly1
    newpath
    87950 54930 moveto
    32094 54930 lineto
    32094 54474 lineto
    32094 54415 lineto
    32094 52525 lineto
    32071 52470 lineto
    32029 52428 lineto
    31974 52406 lineto
    31915 52406 lineto
    30025 52406 lineto
    29970 52429 lineto
    29928 52471 lineto
    29906 52526 lineto
    29906 52585 lineto
    29906 54475 lineto
    29929 54530 lineto
    29971 54572 lineto
    30026 54594 lineto
    30085 54594 lineto
    31975 54594 lineto
    32030 54571 lineto
    32072 54529 lineto
    32094 54474 lineto
    32094 54930 lineto
    28300 54930 lineto
    28300 17800 lineto
    87950 17800 lineto
    87950 54930 lineto
    poly1
    100 setlinewidth
    newpath
    87950 54930 moveto
    32094 54930 lineto
    32094 54474 lineto
    32094 54415 lineto
    32094 52525 lineto
    32071 52470 lineto
    32029 52428 lineto
    31974 52406 lineto
    31915 52406 lineto
    30025 52406 lineto
    29970 52429 lineto
    29928 52471 lineto
    29906 52526 lineto
    29906 52585 lineto
    29906 54475 lineto
    29929 54530 lineto
    29971 54572 lineto
    30026 54594 lineto
    30085 54594 lineto
    31975 54594 lineto
    32030 54571 lineto
    32072 54529 lineto
    32094 54474 lineto
    32094 54930 lineto
    28300 54930 lineto
    28300 17800 lineto
    87950 17800 lineto
    87950 54930 lineto
    poly0
    1 1 1 setrgbcolor
    60 setlinewidth
    31000 53500 170 cir1
    0 0 0 setrgbcolor
    showpage
    grestore
    %%EOF

    logo.ps :
    %!PS-Adobe-3.0
    %%Creator: cairo 1.10.2 (http://cairographics.org)
    %%CreationDate: Thu Mar 22 10:07:46 2012
    %%Pages: 1
    %%BoundingBox: 0 0 31 13
    %%DocumentData: Clean7Bit
    %%LanguageLevel: 2
    %%DocumentMedia: 11x4mm 31 13 0 () ()
    %%EndComments
    %%BeginProlog
    /languagelevel where
    { pop languagelevel } { 1 } ifelse
    2 lt { /Helvetica findfont 12 scalefont setfont 50 500 moveto
    (This print job requires a PostScript Language Level 2 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
    /pdfmark where { pop globaldict /?pdfmark /exec load put }
    { globaldict begin /?pdfmark /pop load def /pdfmark
    /cleartomark load def end } ifelse
    /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
    %%EndProlog
    %%Page: 1 1
    %%BeginPageSetup
    %%PageMedia: 11x4mm
    %%PageBoundingBox: 0 0 31 13
    %%EndPageSetup
    q 0 0 31 13 rectclip q
    1 g
    25.539 9.536 m 25.539 7.567 l 27.227 7.567 l 27.227 3.817 l 27.227
    3.055 27.211 2.606 27.18 2.473 c 27.152 2.348 27.078 2.243 26.961 2.161
    c 26.848 2.087 26.707 2.052 26.539 2.052 c 26.324 2.052 25.992 2.13
    25.555 2.286 c 25.336 0.364 l 25.922 0.118 26.574 -0.011 27.289 -0.011
    c 27.738 -0.011 28.145 0.063 28.508 0.208 c 28.863 0.36 29.125 0.559
    29.289 0.802 c 29.457 1.04 29.574 1.364 29.633 1.77 c 29.688 2.048
    29.711 2.63 29.711 3.505 c 29.711 7.567 l 30.852 7.567 l 30.852 9.536 l
    29.711 9.536 l 29.711 11.395 l 27.227 12.833 l 27.227 9.536 l h
    18.535 3.177 m 16.082 2.77 l 16.395 1.864 16.898 1.169 17.582 0.692 c
    18.262 0.223 19.117 -0.011 20.145 -0.011 c 21.77 -0.011 22.969 0.52
    23.738 1.583 c 24.355 2.434 24.66 3.509 24.66 4.802 c 24.66 6.352
    24.262 7.567 23.457 8.442 c 22.648 9.313 21.621 9.755 20.379 9.755 c
    18.996 9.755 17.902 9.294 17.098 8.38 c 16.297 7.462 15.914 6.055
    15.941 4.161 c 22.129 4.161 l 22.121 3.43 21.926 2.86 21.551 2.458 c
    21.168 2.052 20.688 1.848 20.113 1.848 c 19.73 1.848 19.406 1.95 19.145
    2.161 c 18.875 2.368 18.672 2.708 18.535 3.177 c h
    18.395 5.677 m 18.418 6.391 18.605 6.934 18.957 7.302 c 19.312 7.673
    19.742 7.864 20.238 7.864 c 20.781 7.864 21.227 7.665 21.566 7.27 c
    21.922 6.884 22.098 6.352 22.098 5.677 c h
    15.02 2.864 m 12.535 3.255 l 12.434 2.774 12.219 2.407 11.895 2.161 c
    11.574 1.911 11.125 1.786 10.551 1.786 c 9.906 1.786 9.422 1.899 9.098
    2.13 c 8.891 2.294 8.785 2.512 8.785 2.786 c 8.785 2.97 8.844 3.13
    8.957 3.255 c 9.082 3.368 9.359 3.477 9.785 3.583 c 11.777 4.016 13.039
    4.419 13.566 4.786 c 14.309 5.282 14.676 5.989 14.676 6.895 c 14.676
    7.696 14.359 8.372 13.723 8.927 c 13.078 9.477 12.09 9.755 10.754 9.755
    c 9.477 9.755 8.527 9.544 7.91 9.13 c 7.289 8.712 6.855 8.095 6.613
    7.286 c 8.941 6.848 l 9.047 7.212 9.242 7.489 9.52 7.677 c 9.793 7.872
    10.188 7.973 10.707 7.973 c 11.355 7.973 11.82 7.884 12.098 7.708 c
    12.285 7.571 12.379 7.403 12.379 7.208 c 12.379 7.028 12.297 6.876
    12.129 6.755 c 11.914 6.587 11.145 6.352 9.832 6.052 c 8.523 5.759
    7.598 5.391 7.066 4.958 c 6.559 4.52 6.301 3.907 6.301 3.13 c 6.301
    2.274 6.664 1.532 7.379 0.911 c 8.09 0.294 9.148 -0.011 10.551 -0.011 c
    11.824 -0.011 12.828 0.247 13.566 0.77 c 14.309 1.29 14.793 1.989 15.02
    2.864 c h
    0.066 9.536 m 0.066 7.567 l 1.754 7.567 l 1.754 3.817 l 1.754 3.055
    1.738 2.606 1.707 2.473 c 1.68 2.348 1.605 2.243 1.488 2.161 c 1.375
    2.087 1.234 2.052 1.066 2.052 c 0.852 2.052 0.52 2.13 0.082 2.286 c
    -0.137 0.364 l 0.449 0.118 1.102 -0.011 1.816 -0.011 c 2.266 -0.011
    2.672 0.063 3.035 0.208 c 3.391 0.36 3.652 0.559 3.816 0.802 c 3.984
    1.04 4.102 1.364 4.16 1.77 c 4.215 2.048 4.238 2.63 4.238 3.505 c 4.238
    7.567 l 5.379 7.567 l 5.379 9.536 l 4.238 9.536 l 4.238 11.395 l 1.754
    12.833 l 1.754 9.536 l h
    0.066 9.536 m f
    Q Q
    showpage
    %%Trailer
    %%EOF

    编辑:回复: luser droog的回答;如果我尝试打开 combo.psevince 中所写,我得到:
    $ evince combo.ps
    invalidfileaccess -9

    这可能与 #414002 - gs -dSAFER: /invalidfileaccess with "run" operator - Debian Bug report logs有关...如果我尝试在开始时添加 PostScript 标题“ %!”,我会得到:
    $ nano combo.ps # added %! at start
    $ evince combo.ps
    undefined -21
    undefined -21

    我也试过运行 ps2ps - 这是出来的:
    $ ps2ps combo.ps comboB.ps
    Error: /undefined in --load--
    Operand stack:
    Oldshowpage
    Execution stack:
    %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push 1910 1 3 %oparray_pop 1909 1 3 %oparray_pop 1893 1 3 %oparray_pop 1787 1 3 %oparray_pop --nostringval-- %errorexec_pop .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval--
    Dictionary stack:
    --dict:1159/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
    Current allocation mode is local
    Current file position is 30
    GPL Ghostscript 9.02: Unrecoverable error, exit code 1

    最佳答案

    为了“连接”这两个文件,您需要禁用“showpage”运算符,否则两个文件将分别发出它们的页面。但是您需要维护原始定义,以便您可以发出最终文档。一些谎言:

    /Oldshowpage showpage load def
    /showpage {} def

    ...
    file1
    ...
    ...
    file2
    ...
    Oldshowpage

    因此,如果您将重新定义保存在一个文件中,并将最终执行保存在另一个文件中,您可能会 cat 'prolog.ps file1.ps file2.ps epilog.ps'
    您的两个文件都不会执行媒体请求(您可以忽略 %% 行,这些只是注释)。

    但是,正如您所说的那样,您不希望缩放和转换在作业之间持续存在。所以你需要保存和恢复图形状态。因此,在这种情况下,您还需要一个“中间”文件。

    所以 prolog.ps包含:
    /Oldshowpage showpage load def
    /showpage {} def
    gsave
    middle.ps包含
    grestore

    epilog.ps包含
    Oldshowpage

    将所有 5 个文件放在一起,它应该可以工作。它为我做了一些明智的事情,但我也许应该提到你的“logo.ps”使用 Ghostscript 和 Adob​​e Distiller 为我生成一个空白页面。

    关于linux - 覆盖两个 postscript 文件(命令行方法)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9820646/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com