[Python & Unix] Combine multiple PDF files into one.


Combine multiple PDF files with serial numbers into one.

What to use

--Python (2.7.9 here, but anything is fine.) --ghostscript (GS command below) --Sequential number pdf file ――It doesn't have to be a serial number, but if it is a serial number, the configuration is easy.

What you are doing

  1. Create a list of serial numbers with the ls command
  2. Convert to a space-separated string for the arguments of the gs command.
  3. Execute the gs command

Then immediately. .. .. .. ..


#!/usr/bin/env python
import commands,os
list = commands.getoutput("ls *.pdf").split("\n")

prm = ""

for i in range(len(list)):
	prm =  prm + " " + list[i]

cmd = "gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=all.pdf"+prm
print cmd


There is a for sentence in one place, but I'm sure there is an easier way ... (End.)

How to use the commented pdftk


$ brew pull https://github.com/Homebrew/homebrew/pull/25953
$ brew install pdftk


[Reference](http://linux.just4fun.biz/?%E9%80%86%E5%BC%95%E3%81%8DUNIX%E3%82%B3%E3%83%9E%E3%83% B3% E3% 83% 89% 2F% E8% A4% 87% E6% 95% B0PDF% E3% 83% 95% E3% 82% A1% E3% 82% A4% E3% 83% AB% E3% 82% 921% E3% 81% A4% E3% 81% AEPDF% E3% 83% 95% E3% 82% A1% E3% 82% A4% E3% 83% AB% E3% 81% AB% E3% 81% BE% E3% 81% A8% E3% 82% 81% E3% 82% 8B% E6% 96% B9% E6% B3% 95% E3% 83% BBgs% E3% 82% B3% E3% 83% 9E% E3% 83% B3% E3% 83% 89)

Recommended Posts

[Python & Unix] Combine multiple PDF files into one.
Combine multiple python files into one python file
[Python] Combine multiple Excel sheets into one
Combine multiple Excel files loaded using pandas into one
Combine multiple csv files into one csv file with python (assuming only one line of header)
Combine python function arguments into one variable
Convert multiple jpg files to one PDF file
Integrate PDF files with Python
Decompress multiple compressed files (Python)
Combine accessors into one method
[Python] Send gmail with python: Send one by one with multiple image files attached
[Blender] Split Blender script into multiple files
Handle multiple python versions in one jupyter
Bulk read multiple files & combine vertically (DataFrame)
Consolidate multiple disks into one using LVM
Combine multiple CSVs and data frames into one data frame at high speed [60x speed]
Python code that removes contiguous spaces into one
Multiple graphs are displayed in one window (python)
PDF files and sites useful for learning Python 3
Convert multiple proto files at once with python
A script that combines multiple pages of a PDF file into one page without margins
Python text reading for multiple lines and one line
Python that merges a lot of excel into one excel
How to add page numbers to PDF files (in Python)
Remove headings from multiple format CSV files with python
Generate multiple HTML files at once by pouring JSON data into an HTML template with Python