【问题标题】:Taking notes: print two pages per sheet, one blank做笔记:每张打印两页,一张空白
【发布时间】:2015-12-24 08:04:31
【问题描述】:

我需要 PDF 自动化,它是每张纸多页的变体。在这种情况下,我不需要一个简单的每张两页的解决方案,这很容易。我需要手写笔记并排在页面上。所以,就这样吧:

给定一个 PDF,我想每张打印两页,但是,一页必须为空白,如下所示:

+-------+-------+
|  P.1  | white |
|       |       |
|       |       |
+-------+-------+

+-------+-------+
|  P.2  | white |
|       |       |
|       |       |
+-------+-------+

etc.

有没有人想编写一个可以自动执行此操作的脚本?

PS。我知道如何在 LaTeX 中做到这一点,但我想避免使用大枪......

【问题讨论】:

    标签: bash pdf


    【解决方案1】:

    如果避免使用 LaTeX 并不意味着避免使用任何依赖它的工具,那么 PDFJam(Debian 软件包是 texlive-extra-utils)可能会有所帮助,请参阅 q/a:Gluing (Imposition) PDF documents

    否则你可能最好用一个小脚本将 .pdf 文件页面转换为图像,然后将它们与空白图像合并,ImageMagick 能够做这些事情。

    【讨论】:

      【解决方案2】:

      使用 Ubuntu:

      # install packages
      sudo apt-get install enscript ghostscript pdfjam pdftk
      
      source="source.pdf"
      output="output.pdf"
      
      # create ps with one blank page
      echo -n | enscript -p blank.ps
      
      # convert p2 to pdf
      ps2pdf blank.ps blank.pdf
      
      # get number of pages of $source
      num=$(pdftk "$source" dump_data | grep -Po 'NumberOfPages: \K.*')
      
      # create string with new page numbers
      for ((i=1;i<=$num;i++)); do pages="$pages A$i-$i B1-1"; done
      
      # create pdf with white pages
      pdftk A="$source" B=blank.pdf cat $pages output tmp.pdf
      
      # create pdf with two pages on one side
      pdfjam tmp.pdf --nup 2x1 --landscape --outfile "$output"
      
      # clean up
      rm blank.ps blank.pdf tmp.pdf
      

      【讨论】:

        【解决方案3】:

        我有一个解决方案,它不能完全打印您想要的布局,而是打印以横向工作表为中心的页面,如下所示:

        +---+-------+----+
        |   |  P.1  |    |
        |   |       |    |
        |   |       |    |
        +---+-------+----+
        
        +---+-------+----+
        |   |  P.2  |    |
        |   |       |    |
        |   |       |    |
        +---+-------+----+
        

        如果您的目标是为手写注释创建可用空间,则此布局可能会更好,因为它可以让您将注释写得更接近打印文本。

        以下脚本依赖于pdfjam,它在后台使用 LaTeX。为pdfjam 添加更多命令行参数可能会得到您正在寻找的内容。

        #!/bin/bash
        if [ "$#" -ne 1 ]; then
            echo "usage: $0 PDF_filename..."
            echo
            echo "This script takes a PDF file as command line arguments,"
            echo "and generates a new, landscape-formatted PDF file, where every "
            echo "page has very large margins which may be useful for editorial notes"
            echo
            echo "Requires: pdfjam, which is installed by the apt-get package texlive-extra-utils"
            exit 1
        fi
        command -v pdfjam >/dev/null 2>&1 || { echo >&2 "I require pdfjam but it's not installed.  Do an apt install of texlive-extra-utils to get it on Ubuntu. Aborting."; exit 1; }
        pdfjam --batch --nup 1x1 --suffix widemargin --landscape "$@"
        

        【讨论】:

        • 您可以使用--offset将页面向左移动。
        猜你喜欢
        • 2015-06-10
        • 1970-01-01
        • 2019-06-09
        • 1970-01-01
        • 1970-01-01
        • 2014-11-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多