使用pstools将大型PDF图像拆分为多个页面

使用pstools将大型PDF图像拆分为多个页面,pdf,graphviz,ghostscript,postscript,Pdf,Graphviz,Ghostscript,Postscript,对于一个相当大规模的项目,我们需要使用创建输入文件的工具来呈现调用图。当前,命令行: dot -T pdf -Granksep=1.42 -Nfontsize=8 input.dot -o output.pdf 呈现一个37803x2078分的单页pdf图像,该图像比一个A3页面上的图像稍大,并且仍然可读 我已经知道工具海报打印机,但不幸的是,在这个限制性环境中,我手头只有graphviz、ghostscript和其他常见的ps/pdf命令行程序 我曾尝试在点文件中设置“page”指令,但这给

对于一个相当大规模的项目,我们需要使用创建输入文件的工具来呈现调用图。当前,命令行:

dot -T pdf -Granksep=1.42 -Nfontsize=8 input.dot -o output.pdf
呈现一个37803x2078分的单页pdf图像,该图像比一个A3页面上的图像稍大,并且仍然可读

我已经知道工具海报打印机,但不幸的是,在这个限制性环境中,我手头只有graphviz、ghostscript和其他常见的ps/pdf命令行程序

我曾尝试在点文件中设置“page”指令,但这给了我一个200页的postscript文件,没有明显的页面顺序,因此该选项当前不可用


我更喜欢的是一个gs命令行,在该命令行中,我将巨大的ps/pdf文件拆分为预定义的页数,比如5x2,或者一种控制graphviz输出缩放以适应5x2页面的方法。

不久前,我为一个想要剪切2x2 PowerPoint风格幻灯片的人写了这篇文章。我不知道它是否仍然有效,但你可以试试。注意,这只适用于Ghostscript

%!PS
% Copyright (C) 2011 Artifex Software, Inc.  All rights reserved.
% 
% This software is provided AS-IS with no warranty, either express or
% implied.
% 
% This software is distributed under license and may not be copied,
% modified or distributed except as expressly authorized under the terms
% of the license contained in the file LICENSE in this distribution.
% 
% For more information about licensing, please refer to
% http://www.ghostscript.com/licensing/. For information on
% commercial licensing, go to http://www.artifex.com/licensing/ or
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
% San Rafael, CA  94903, U.S.A., +1(415)492-9861.
%
% Slice up a PDF file
%
% usage: gs -sFile=____.pdf  -dSubPagesX= -dSubPagesY= [-dSubPageOrder=] [-dVerbose=]pdf_slice.ps
%
% SubPageOrder is a bit field;
% Default = 0
% Bit 0 - 0 = top to bottom
%         1 = bottom to top
% Bit 1 - 0 = left to right
%         1 = right to left
% Bit 3 - 0 = increase x then y
%       - 1 = increase y then x
% 
% 0 - page 1 at top left, increasing left to right, top to bottom
% 1 - page 1 at bottom left increasing left to right, bottom to top
% 2 - page 1 at top right, increasing right to left, top to bottom
% 3 - page 1 at bottom right increasing right to left, bottom to top
% 4 - page 1 at top left, increasing top to bottom, left to right
% 5 - page 1 at bottom left increasing bottom to top, left to right
% 6 - page 1 at top right, increasing top to bottom, right to left 
% 7 - page 1 at bottom right increasing bottom to top, right to left

%
% Check the parameters to see they are present and of the correct type
%
/Usage {
  (  usage: gs -dNODISPLAY -q -sFile=____.pdf \n) =
  (     -dSubPagesX= -dSubPagesY= [-dSubPageOrder=] pdf_slice.ps \n) =
  (Please see comments in pdf_slice.ps for more details) =
  flush
  quit
} bind def

/Verbose where not {
  /Verbose false def
}{
  pop /Verbose true def
} ifelse

/File where not {
  (\n   *** Missing source file. \(use -sFile=____.pdf\)\n) =
  Usage
} {
  pop
}ifelse

/SubPagesX where not {
  (\n   *** SubPagesX not integer! \(use -dSubPagesX=\)\n) =
  Usage
} {
  Verbose { (SubPagesX ) print } if 
  SubPagesX type 
  Verbose { dup == } if
  /integertype eq not {
    (\n   *** SubPagesX not integer! \(use -dSubPagesX=\)\n) =
    Usage
  }
  pop 
}ifelse

/SubPagesY where not {
  (\n   *** SubPagesY not integer! \(use -dSubPagesY=\)\n) =
  Usage
} {
  Verbose { (SubPagesY ) print } if
  SubPagesY type 
  Verbose { dup == } if
  /integertype eq not {
    (\n   *** SubPagesY not integer! \(use -dSubPagesY=\)\n) =
    Usage
  }
  pop 
}ifelse

/SubPageOrder where not {
  /SubPageOrder 0 def
} {
  Verbose { (SubPageOrder ) print } if
  SubPageOrder type 
  Verbose { dup == } if
  dup == 
  /integertype eq not {
    (\n   *** SubPageOrder not integer! \(use -dSubPageOrder=\)\n) =
    Usage
  }
  pop 
}ifelse

% 
% Turns off most messages
%
/QUIET true def     % in case they forgot

%() =

%
% Open the PDF file and tell the PDF interpreter to start dealing with it
%
File dup (r) file runpdfbegin pop
/PDFPageCount pdfpagecount def

%
% Set up our bookkeeping
%
% First get the size of the page from page 1 of the PDF file
% We assume that all PDF pages are the same size.
%
1 pdfgetpage currentpagedevice
1 index get_any_box 
exch pop dup 2 get exch 3 get
/PDFHeight exch def
/PDFWidth exch def

%
% Now get the page size of the current device. We are assuming that
% this is the size of the individual sub-pages in the original PDF. NB
% This assumes no margins between sub-pages, all sub-pages the same size.
%
currentpagedevice /PageSize get
dup 0 get /SubPageWidth exch def
1 get /SubPageHeight exch def

% 
% Calculate the margins. This is the margin between the page border and
% the enclosed group of sub-pages, we assume there are no borders
% between sub pages.
%
/TopMargin PDFHeight SubPageHeight SubPagesY mul sub 2 div def
/LeftMargin PDFWidth SubPageWidth SubPagesX mul sub 2 div def

Verbose {
  (PDFHeight = ) print PDFHeight ==
  (PDFWidth = ) print PDFWidth ==
  (SubPageHeight = ) print SubPageHeight ==
  (SubPageWidth = ) print SubPageWidth ==
  (TopMargin = ) print TopMargin ==
  (LeftMmargin = ) print LeftMargin ==
} if

%
% This rouitne calculates and sets the PageOffset in the page device
% dictionary for each subpage, so that the PDF page is 'moved' in such 
% a way that the required sub page is under the 'window' which is the current
% page being imaged.
%
/NextPage {
    SubPageOrder 2 mod 0 eq {
        /H SubPagesY SubPageY sub SubPageHeight mul TopMargin add def
    }{
        /H SubPageY 1 sub SubPageHeight mul TopMargin add def
    } ifelse
    SubPageOrder 2 div floor cvi 2 mod 0 eq {
        /W SubPageX 1 sub SubPageWidth mul LeftMargin add def
    }{
        /W SubPagesX SubPageX sub SubPageWidth mul LeftMargin add def
    } ifelse
    << /PageOffset [W neg H neg]>> setpagedevice

Verbose {
  (SubPageX ) print SubPageX ==
  (SubPageY ) print SubPageY ==
  (X Offset ) print W ==
  (Y Offset ) print H == flush
} if

    PDFPage
} bind def

%
% The main loop
% For every page in the original PDF file
%
1 1 PDFPageCount 
{
    /PDFPage exch def

    % Do the gross ordering here rather than in
    % NextPage. We eiither process rows and then 
    % columns, or columns then rows, depending on
    % Bit 3 of SubPageorder
    SubPageOrder 3 le {
        1 1 SubPagesY {
            /SubPageY exch def
            1 1 SubPagesX {
                /SubPageX exch def
                NextPage
                pdfgetpage
                pdfshowpage
            } for
        } for
    } {
        1 1 SubPagesX {
            /SubPageX exch def
            1 1 SubPagesY {
                /SubPageY exch def
                NextPage
                pdfgetpage
                pdfshowpage
            } for
        } for
    } ifelse
} for
%!附言
%版权所有(C)2011 Artifex Software,Inc.保留所有权利。
% 
%本软件按原样提供,不提供任何明示或明示担保
%暗示。
% 
%本软件根据许可证分发,不得复制,
%修改或分发,除非根据条款明确授权
%此发行版的文件许可证中包含的许可证的。
% 
%有关许可的更多信息,请参阅
% http://www.ghostscript.com/licensing/. 有关
%商业许可,请访问http://www.artifex.com/licensing/ 或
%联系Artifex软件公司,地址:110号卢卡斯谷路101号,
%美国加利福尼亚州圣拉斐尔94903,+1(415)492-9861。
%
%将PDF文件切片
%
%用法:gs-sFile=\\\\\.pdf-dSubPagesX=-dSubPagesY=[-dSubPageOrder=][-dVerbose=]pdf\u slice.ps
%
%子页面顺序是一个位字段;
%默认值=0
%位0-0=从上到下
%1=从下到上
%位1-0=从左到右
%1=从右向左
%位3-0=先增加x,然后增加y
%-1=增加y,然后增加x
% 
%0-第1页在左上角,从左到右递增,从上到下递增
%1-第1页左下角,从左到右,从下到上递增
%2-第1页右上角,从右到左,从上到下递增
%3-第1页,右下角,从右到左,从下到上递增
%4-第1页左上角,从上到下,从左到右递增
%5-第1页左下角,从下到上、从左到右递增
%6-第1页右上角,从上到下,从右到左递增
%7-第1页,右下角,从下到上,从右到左递增
%
%检查参数是否存在且类型是否正确
%
/用法{
(用法:gs-dNODISPLAY-q-sFile=__.pdf\n)=
(-dSubPagesX=-dSubPagesY=[-dSubPageOrder=-pdf\u slice.ps\n)=
(详情请参见pdf_slice.ps中的评论)=
脸红
退出
}绑定def
/冗长的{
/冗长的假定义
}{
pop/Verbose真定义
}如果有
/不在哪里归档{
(\n***缺少源文件。\(使用-sFile=\uuu.pdf\)\n)=
用法
} {
流行音乐
}如果有
/子页面X,其中没有{
(\n***子页面X不是整数!\(使用-dSubPagesX=\)\n)=
用法
} {
详细{(子页面X)打印}如果
子页面X类型
详细{dup=}如果
/整数类型eq不是{
(\n***子页面X不是整数!\(使用-dSubPagesX=\)\n)=
用法
}
流行音乐
}如果有
/子页面哪里没有{
(\n***子页面不是整数!\(使用-dSubPagesY=\)\n)=
用法
} {
详细{(子页面)打印}如果
亚页型
详细{dup=}如果
/整数类型eq不是{
(\n***子页面不是整数!\(使用-dSubPagesY=\)\n)=
用法
}
流行音乐
}如果有
/子页面顺序,如果没有{
/子页面顺序0 def
} {
详细{(子页面顺序)打印}如果
子页面订单类型
详细{dup=}如果
dup==
/整数类型eq不是{
(\n***子页面顺序不是整数!\(使用-dSubPageOrder=\)\n)=
用法
}
流行音乐
}如果有
% 
%关闭大多数邮件
%
/安静的真实def%,以防他们忘记
%() =
%
%打开PDF文件,告诉PDF解释器开始处理它
%
文件dup(r)文件runpdfbegin pop
/PDFPageCount PDFPageCount def
%
%设置我们的簿记
%
%首先从PDF文件的第1页获取页面大小
%我们假设所有PDF页面的大小都相同。
%
1 pdfgetpage当前页面设备
1索引获取任意框
exch pop dup 2获取exch 3获取
/PDFH8 exch def
/PDFWidth exch def
%
%现在获取当前设备的页面大小。我们假设
%这是原始PDF中单个子页面的大小。铌
%这假设子页面之间没有边距,所有子页面大小相同。
%
currentpagedevice/PageSize获取
dup 0获取/子页面宽度exch def
1获取/子页面高度exch def
% 
%计算利润率。这是页面边框和边框之间的边距
%在所附的子页面组中,我们假设没有边框
%在子页面之间。
%
/TopMargin PDFH八个子页面高度子页面SY mul sub 2分区def
/LeftMargin PDFWidth子页面宽度子页面X mul子页面2 div def
冗长的{
(PDFHight=)打印PDFHight==
(PDFWidth=)打印PDFWidth==
(子页面高度=)打印子页面高度==
(子页面宽度=)打印子页面宽度==
(TopMargin=)打印TopMargin==
(LeftMmargin=)打印左边距==
}如果
%
%此任务计算并设置页面设备中的页面偏移量
%每个子页面的字典,以便PDF页面以这样的方式“移动”
%所需子页面位于“窗口”下的一种方式,该窗口是当前
%正在成像的页面。
%
/下一页{
子页面顺序2模0均衡器{
/H子页面SY子页面Y子页面高度mul TopMargin add def
}{
/H子页面1子页面高度mul TopMargin add def
}如果有
子页面订单2分区地板cvi 2模块0均衡器{
/W子页面x 1子页面宽度mul LeftMargin add def
}{
/W子页面X子页面X子页面宽度mul LeftMargin添加定义
}如果有
>设置页面设备
冗长的{
(a)分段
graph [bb="0,0,18866,1005"];
dot -Gpage="8,11" -Gsize="160,10" -Tps graph.dot > graph.ps