Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
edc849b
misc: add question about proxy when init nuxt and View_Transitions_API
Linhieng Aug 26, 2024
d050c4f
misc: add note about nvm download issue
Linhieng Aug 28, 2024
b8e6139
misc: the solution about window reinstall
Linhieng Sep 4, 2024
5942396
misc: add note about cmd and powershell command
Linhieng Sep 20, 2024
9eab002
misc: add method about timing mute in win10
Linhieng Sep 26, 2024
11319a2
misc: window cmd `net user`
Linhieng Oct 9, 2024
4a72a4a
misc: add note about vscode settings
Linhieng Oct 21, 2024
c211fb0
misc: about command 'cd' in window
Linhieng Oct 21, 2024
4171fb2
misc: add note about pnpm store
Linhieng Nov 1, 2024
65db29a
misc: note about pdf2word
Linhieng Nov 3, 2024
d65a209
misc: notes about VBA of Microsoft
Linhieng Nov 14, 2024
50314a6
misc: quick start of electron
Linhieng Nov 15, 2024
0865c8f
misc: docs
Linhieng Nov 15, 2024
0419b29
misc: notes about js `import()` and __dirname
Linhieng Nov 17, 2024
0bedf17
misc: add VBA method to assign shortcut for specific command in Word
Linhieng Nov 25, 2024
afdee1f
docs(misc): add tips for Windows 11 installation and activation
Linhieng Nov 29, 2024
ea6c243
docs(misc): update README with new information and tips
Linhieng Jan 3, 2025
d00b474
docs(misc): 添加使用 Python 和 Selenium 爬取动态页面的指南
Linhieng Jan 3, 2025
9099fdc
docs(misc): add various Python tips and tricks
Linhieng Feb 18, 2025
44bc999
docs(misc): add PyInstaller packaging instructions for Flask-SocketIO
Linhieng Apr 10, 2025
04327c6
backup
Linhieng Apr 11, 2025
9056683
docs(misc): update subprocess example in README
Linhieng Apr 15, 2025
f892486
docs(misc): add information about Python subprocess and threading
Linhieng Apr 16, 2025
ba1f47a
docs(misc): 整合 PDF 命令行工具笔记
Linhieng May 14, 2025
e3a23ba
docs/misc: add example for merging multiple PDF files
Linhieng May 20, 2025
a4765aa
backup
Linhieng Aug 7, 2025
11d5b16
backup
Linhieng Aug 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions misc/PDF命令行工具.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
## [poppler-windows](https://github.com/oschwartz10612/poppler-windows/releases)

### 作用

- PDF转图片

### 案例:PDF转图片

```sh
pdftoppm -progress -png -r 300 -sep "_" input.pdf output
```

- `-progress`:显示转换进度。
- `-png`:输出为PNG格式。
- `-r 300`:设置图片分辨率。
- `-sep "_"`:指定输出文件名分隔符,默认为 `-`。
- `input.pdf`:待转换文件。
- `output`:输出文件名。

### 案例:转换指定页面为图片

```sh
pdftoppm -progress -png -r 300 -f 2 -l 4 input.pdf output
```

- `-f 2 -l 4`:指定转换的页面范围,从第2页到第4页(均包含)。

### 案例:只转换首页为图片

```sh
pdftoppm -png -r 300 -singlefile input.pdf output
```

- `-singlefile`:添加了该参数后,只转换首页,而且输出文件名不会添加序号后缀。

## [PDFtk Server](https://www.pdflabs.com/tools/pdftk-server/)

### 作用

- 旋转PDF
- 合并PDF

### 案例:所有页面旋转 180°

```sh
pdftk input.pdf cat 1-endsouth output rotated.pdf
```
- `1-end`:表示所有页面(第1页到最后一页)。
- `south`:表示旋转 180°。
- 注意 end 和 south 之间没有空格


**PDFtk 旋转参数对照表**

| **旋转角度** | **可用关键字** | **示例命令** |
| ------------------------- | ---------------- | --------------------------------------------------- |
| **90° 顺时针** | `east` / `right` | `pdftk a.pdf cat 1-endeast output rotated_90.pdf` |
| **180°** | `south` / `down` | `pdftk a.pdf cat 1-endsouth output upside_down.pdf` |
| **90° 逆时针** | `west` / `left` | `pdftk a.pdf cat 1-endwest output rotated_270.pdf`

### 案例:只旋转第4-6页

```sh
pdftk input.pdf cat 1-3 4-6left 7-end output rotated.pdf
```

- 注意数字和方向之间没有空格。


### 案例:将页面倒序,并翻转

```sh
pdftk input.pdf cat end-1down output rotated-reversed.pdf
```

- 核心就是 `cat end-1down`


### 案例:合并扫描件的单双页

```sh
pdftk A=1.pdf B=2.pdf shuffle A B output merged.pdf
```

- `1.pdf` 是奇数页,`2.pdf` 是偶数页,merged.pdf 是这两份PDF按序合并后的结果
- `shuffle` 作用是交替合并多个 PDF 文件页面


### 案例:合并指定内容,并翻转特定页

```sh
pdftk A=1.pdf B=2.pdf cat A1 B1down A2 B2 output merged.pdf
```

- 顾名思义,提取 `A1 B1down A2 B2` 然后合并为一份文档,其中 `B1` 被翻转
- 前面的 `shuffle A B` 就相当于 `cat A1 B1 A2 B2 A3 B3 ....`

## 案例:合并多个 PDF 文件

新建一个文件夹,把 PDF 文件放在里面,然后执行下面代码。注意,需要文件名有序。

```sh
pdftk *.pdf cat output merged.pdf
```

## python 环境工具

### img2pdf

将图片转换为 PDF

```sh
img2pdf -o output.pdf images/*.jpg
img2pdf --pagesize A4 -o output.pdf *.png
```
旋转图片?
- `images/*.jpg` 支持通配符,指定图片路径。也可以指定图片顺序,图片路径写在最后,用空格分隔
- `-o output.pdf` 指定输出文件名
- `--pagesize A4` 添加该参数将自适应页面大小为 A4

### PDF 转 word

```sh
pdf2docx convert input.pdf output.docx
```
Loading