如何将 1 页 PDF 转换为每页 2 页 PDF?

mok*_*sin 57 linux pdf conversion

我想打印一个 PDF,以便在第一页的正面是前两页,在背面是第 3 和第 4 页,依此类推。

-----------------          -----------------
|       |       |          |       |       |
|       |       |          |       |       |
|   1   |   2   |          |   3   |   4   |    . . .
|       |       |          |       |       |
|_______|_______|          |_______|_______|

 page 1 - front             page 1 - back
Run Code Online (Sandbox Code Playgroud)

因为我使用 Linux 的打印机无法支持我想的手动双面打印,也许我可以以相应的方式编辑 pdf。

但是如何?

fra*_*ous 32

除了上面提到的内容之外,PDFjam还包含一个命令行工具,pdfnup可以执行此操作。(它在下面使用了 PDFLaTeX 的 pdfpages 包,您也可以使用它。)

如果您更喜欢 GUI,jPDFtweak是另一种选择。

  • 示例用法:`pdfnup --nup 2x1 mypdf.pdf`。这将在横向视图上每张纸并排打印 2 页,然后在短边上翻转打印。有关更多详细信息,请参阅“man pdfnup”。 (4认同)
  • 实用程序脚本“pdfnup”已从“pfdjam”的发行版中删除。可以直接使用`pdfjam`,例如通过`pdfjam --nup 2x1 in.pdf --outfile out.pdf --landscape` (2认同)

小智 28

使用 pdfnup:

$ pdfnup file.pdf
Run Code Online (Sandbox Code Playgroud)

这将完全按照您的要求创建一个新的 pdf 文件。

  • 更准确地说,`pdfnup --nup 2x1 --suffix test file.pdf` 将创建一个包含 2 页的 `file-test.pdf`。 (7认同)

Gab*_*les 7

对于任何想要将 1 或 2 页 pdf 转换为 pdf 并在横向视图中并排放置 2 个副本的人(非常适合打印传单),请执行以下操作:

首先,安装texlive-extra-utils,其中包含pdfnup

sudo apt update
sudo apt install texlive-extra-utils
Run Code Online (Sandbox Code Playgroud)

然后:

  1. 将 1 或 2 pg pdf 输入转换为包含这些页面的重复副本的输出(1-pg pdf --> 2-pg pdf、2-pg pdf --> 4-pg pdf 等):
    pdfunite in.pdf in.pdf out.pdf
    
    Run Code Online (Sandbox Code Playgroud)
  2. 将复制的 pdf 合并为横向视图中每面 2 页的 pdf,用于打印传单,例如:
    pdfnup out.pdf
    
    Run Code Online (Sandbox Code Playgroud)

或者(推荐)在一行上执行这两个步骤:

pdfunite in.pdf in.pdf out.pdf && pdfnup out.pdf
Run Code Online (Sandbox Code Playgroud)

请注意,这out.pdf是的输入pdfnup。生成的输出文件pdfnup将称为“ out-nup.pdf ”。

另外,观察命令的输出pdfnup,您将看到它实际运行的命令的详细形式,这使您可以深入了解可以传递给它的选项。显然在幕后pdfnup使用,如下所示:pdfjam

  pdfjam: Effective call for this run of pdfjam:  
          /usr/bin/pdfjam --suffix nup --nup '2x1' --landscape -- out.pdf -
Run Code Online (Sandbox Code Playgroud)

输出示例:

原始 PDF(纵向视图中的 1 个常规页),“ in.pdf ”: 在此输入图像描述

最终 PDF(横向视图中并排 2 页),“ out-nup.pdf ”:

  • 现在可以从中间切成两半作为传单散发 在此输入图像描述

简单的 Bash 函数:make_flyer

新版本:从我的eRCaGuy_dotfiles存储库中获取以下脚本的更好、更新版本:make_flyer.sh。按照文件顶部注释中的安装说明进行操作。

旧版本:

将此 bash 函数复制并粘贴到文件底部~/.bashrc,以便访问简单且易于使用的命令make flyer

# Description: outputs a landscape-oriented flyer pdf
# ("my/pdf/input--flyer.pdf") for each 1 or more pg input pdf 
# ("my/pdf/input.pdf")
#   - 1-pg input PDFs are converted to a 1-sided landscape, printable flyer 
#     that you cut down the center to make 2 flyers.
#   - 2-pg input PDFs are converted to a 2-sided landscape, printable flyer 
#     (flip on short edge when printing double-sided), and also cut down the 
#     middle to make 2 flyers.
#   - **3+ pg input PDFs**: using `pdfnup` directly in this case would make 
#     more sense, since this function will otherwise unnecessarily create 2 
#     copies.
#   - 3 and 4-pg input PDFs are converted to a single piece of paper, 
#     double-sided, flipped on short edge, x 2 copies. No cutting is necessary.
#   - 5+ pg input PDFs simply require half as much paper to print is all since 
#     you get 2 pages per side of paper; they do NOT print like booklets, but 
#     rather just as a landscape-printed, flipped-on-short-edge bundle of pages
#     (like a deck of slides). You get *2 copies* per print though, so just 
#     print half of the total number of pages. 
#
# Example:
#       make_flyer "path/to/inputpdf1.pdf" "path/to/inputpdf2.pdf"
make_flyer() {
    num_args=$# # see: https://stackoverflow.com/questions/4423306/how-do-i-find-the-number-of-arguments-passed-to-a-bash-script/4423321#4423321
    suffix="flyer"

    loop_cnt=0
    for inputpdf in "$@"
    do
        ((loop_cnt++))
        echo "==== CONVERTING PDF $loop_cnt OF $num_args ===="
        echo "     INPUT:  \"$inputpdf\""

        # Strip off the .pdf extension from the input path, while retaining the rest of the path
        # - See: https://stackoverflow.com/questions/12152626/how-can-i-remove-the-extension-of-a-filename-in-a-shell-script/32584935#32584935
        input_path_base="$(echo "$inputpdf" | rev | cut -f 2- -d '.' | rev)"
        input_file_base="$(basename "$inputpdf" .pdf)"
        temp_pdf="${input_path_base}-.pdf" # is "input_path_base-.pdf"
        
        echo "     OUTPUT: \"$(pwd)/${input_file_base}--${suffix}.pdf\""

        # Convert a single 1-pg pdf into a temporary 2-pg pdf
        pdfunite "$inputpdf" "$inputpdf" "$temp_pdf"

        # Lay out the temporary 2-pg pdf into a side-by-side 1-sided flyer to print; creates "input_path_base--flyer.pdf"
        # Note that `pdfnup` places the output from this operation in the location from where you call this script
        # (ie: in your `pwd` [Present Working Directory])!--NOT the location where temp_pdf is located!
        pdfnup "$temp_pdf" --suffix $suffix

        # Delete the temporary 2-pg pdf, called "input_path_base-.pdf", thereby leaving only the original 
        # "input_path_base.pdf" and the new "input_path_base--flyer.pdf"
        rm "$temp_pdf"
    done
}
alias make_flyer_help='echo -e "Ex usage: make_flyer \"path/to/inputpdf.pdf\" - Creates a landscape-side-by-side flyer version called \"inputpdf--flyer.pdf\"\n          *in your pwd* from a 1 or 2 pg input pdf called \"path/to/inputpdf.pdf\". Accepts multiple arguments. Ex:\n          make_flyer \"path/to/inputpdf1.pdf\" \"path/to/inputpdf2.pdf\""'
Run Code Online (Sandbox Code Playgroud)

用法示例:

make_flyer "path/to/inputpdf1.pdf" "path/to/inputpdf2.pdf"
Run Code Online (Sandbox Code Playgroud)

查看帮助信息:

make_flyer_help
Run Code Online (Sandbox Code Playgroud)

输出:

$ make_flyer_help   
Ex usage: make_flyer "path/to/inputpdf.pdf" - Creates a landscape-side-by-side flyer version called "inputpdf--flyer.pdf"  
          *in your pwd* from a 1 or 2 pg input pdf called "path/to/inputpdf.pdf". Accepts multiple arguments. Ex:  
          make_flyer "path/to/inputpdf1.pdf" "path/to/inputpdf2.pdf"
Run Code Online (Sandbox Code Playgroud)

参考:

  1. https://superuser.com/a/948095/425838
  2. /sf/answers/789615361/

有关的:

  1. https://askubuntu.com/questions/214538/printing-in-booklet-format/1095789#1095789

重击参考:

  1. Bash 如何将参数传递到 bash 函数中:https ://bash.cyberciti.biz/guide/Pass_arguments_into_a_function
  2. Bash 连接字符串:https://linuxize.com/post/bash-concatenate-strings/
  3. Bash 执行存储为字符串的 cmd!/sf/ask/140363471/
  4. Bash 迭代 cmd 的所有输入:/sf/ask/17912891/#255913
  5. Bash 将参数传递给函数:/sf/ask/434855361/#6212408
  6. 如何将 1 页 pdf 转换为传单 [我自己的答案!]:如何将 1 页 PDF 转换为每张 2 页 PDF?


小智 6

这是一个足够古老的问题,以至于我们当时认为我们现在拥有的选项是不存在的,但也许它值得一个最新的解决方案。

Linux pdf 查看器通常使用打印选项/属性来设置页面布局,您可以在每张纸/面打印多页。这个想法是使用这些打印到 PDF 文件

Evince可以做到,还有qpdfview。更多在这里。


qpdfview

在此处输入图片说明

在此处输入图片说明


表明

在此处输入图片说明


PDF 工作室查看器

在此处输入图片说明

其他 pdf 查看器必须有类似的选项。