Download v1.0 (For single-page PDFs)
Download v2.0 (Please see the update below)
PDF (Portable Document Format) is a popular document format, which can be treated as a kind of digital paper, including contents (e.g. texts and images) and very stable / unchangeable layout. Many businessmen take it as a "safe" format, and researchers use it to compose academic documents, because many productivity softwares can export vector-graphic images in PDF [1].
However, PDF is too stable to modify it, so all we can do is "add" some notes on PDF files. Annotating is a popular feature supported by most PDF viewing softwares, such as Acrobat Reader, macOS Preview, PDF Expert and so on. In addition, these notes are always re-editable, just like that we can really "modify" the PDF files. But, adding notes is just to cover a virtual layer on the original PDF, totally different from real editing, what if you come across some softwares without annotating supports? When we import PDF files into these softwares, our notes on PDF would be totally lost. For example, the popular academic document composer LaTeX doesn't include the PDF notes in the compiled file, and Keynote doesn't support it, either.
On the other hand, sometimes we need our notes on PDF don't be modified anymore, e.g. some filled formal forms in PDF. To solve this problem, we need to merge notes into the original file content, which is called "PDF flattening".
There are many "Pro" PDF softwares supporting the "flatten" feature, such as Adobe Acrobat and PDF Expert, but they cost money. macOS builds-in very powerful PDF supports, but we cannot find any similar features in Preview. Many people have asked this question on line, but the answers are always the same (link 1、link 2): "Print to PDF" (or "Export as PDF", the same result), but....
PDF (Portable Document Format) 是一個熱門的文件格式,它也常被視為數位版的紙張,裡面夾帶著內容 (文字及圖片) 及非常穩定 / 不可修改的文件排版。很多商務人士拿它當作是一種 "安全" 的格式,而學術研究者用它來製作學術文檔,因為很多文書軟體輸出的向量圖格式是 PDF [1]。
然而,由於 PDF 穩定到不可修改,所以我們能做的就是在上面加註解。大部分 PDF 的閱讀軟體都支援註解功能,例如 Acrobat Reader,、macOS 預覽程式、PDF Expert 等等。此外,這些註解是可再次修改的,就像是我們真的可以修改 PDF 一樣。可是,加註解只是在原本的 PDF 上覆蓋一層虛擬層,跟實際的文檔編輯完全不同,如果遇到不支援註解的軟體該怎麼辦?當我們匯入 PDF 檔到這些軟體,註解將會全部消失。舉個例子,熱門學術文件排版工具 LaTeX 就不支援,其編譯出來的檔案完全不包含註解,而 Keynote 也是一個不支援的例子。
另一方面,有時我們需要我們在 PDF 裡留下的註解不會被再次修改,例如一些 PDF 格式的正式表格。為了解決此問題,我們需要將註解及原始檔案的內容融合在一起,稱為 PDF 的 "平面化" (Flatten)。
市面上有很多 "專業" 軟體能支援 "平面化" 的功能,像是 Adobe Acrobat 及 PDF Expert,但是他們都要花錢。macOS 內建強大的 PDF 支援,但是 Preview 沒有類似的功能。很多人在網上求解,但答案總是一樣 (連結 1、連結 2):"列印成 PDF" (或是 "輸出成 PDF",結果都一樣),但是 .....
Printing preview
預覽列印
預覽列印
Yes, the PDF file is flattened, but you need to crop it manually if the file is not saved in A4 size or other printing sizes, sucks. How about other thirty party tools? Some people suggest pdf2ps, ImageMagick (I tried, but failed), cups-pdf, pdftk (Windows software?), there are all a lot of hassles. Finally, I found an Automator action "New PDF from Images" which supports this feature, but it is not very user-friendly, so I built "Flatten PDF" Automator workflow.
是的,這 PDF 檔是被平面化了,但若它的尺寸不是 A4 或其他列印大小,就要手動去裁切,爛斃了。那其他第三方工具如何?有人推薦 pdf2ps, ImageMagick (我試過,失敗), cups-pdf, pdftk (Wondows 軟體?),總之都太麻煩。最後,我發現一個 Automator 動作 "New PDF from Images" 支援此功能,但不是很好用,所以我寫了 "Flatten PDF" 工作流程。
How to use
1. Drag and drop the files into "Get Specified Finder Items" action. The files in different directories are supported.
1. 將檔案拖拉到 "Get Specified Finder Items" 動作中,在不同資料夾的檔案也可以。
2. Click the upper-right "Run" button to run this workflow, and then the flattened version will show up next to the original file.
2. 按下右上角的 "Run" 按鈕以執行工作流程,而後平面化的檔案將會出現在原始檔案旁邊。
3. This workflow supports the integration with other Automator actions. If you don't like the name (original name + "_flattened"), there is no need to modify my AppleScript codes, just use "Replace Text" feature of "Rename Finder Items" action as follow:
3. 這個工作流程支援與其他 Automator 動作串連。如果不喜歡加了 "_flattened" 的檔名,無須修改我的 AppleScript 程式碼,使用 "Rename Finder Items" 中的 "Replace Text" 功能即可:
Change the filenames *_flattened to *superman
改變檔名從 *_flattened 至 *superman
改變檔名從 *_flattened 至 *superman
If there is any feedback, please leave your comment or email me, thanks!
If you tend to ask me the iOS solution with Siri Shortcut, I can tell you the answer: Not exist (
如果有任何反饋,請留言或寄信給我,多謝!
如果要問我有沒有 Siri 捷徑的 iOS 解決方案,我可以告訴你答案:"沒有" (
20190823 Update: v2.0 release. The issue for the multi-page PDF support is fixed. However, the app in this version cannot be used directly, a "shortcut" file needs to built as below:
20190823 Update: 2.0 版釋出。多頁 PDF 的支援問題已修正。然而這個版本的應用程式不能直接使用,需要製作一個 "捷徑" 檔,方法如下:
捷徑檔可以是工作流程、應用程式或服務,"Run Workflow" 是其中的重點,請依照上圖設定之。附帶一提,其他 Automator 動作仍然可以串連使用,以對輸出的檔案進行後續的處理。
20190806 Update:
Flatten PDF for iOS
Mmm.... Although I don't like it, I searched for the online solutions and got some results. Surprisedly, I found only very few websites can achieve "successful" PDF flattening [2]. Here I suggest Flatten PDF of freetoolonline.com, which built an amazing mobile website, so there is no need to make the Siri Shortcut for it. Before using it, please make sure your document is not confidential, if there is any privacy or security concern, don't use any online solution.
嗯 .....
The website is straightforward: 1. choose the PDF file you want to upload; 2. select "GhostScript" ("ImageMagick" flattens PDF by converting the file to image(raster graphics), which causes the PDF won't be a vector graphics anymore), and then click "Flatten"; 3. download the flattened version file.
網站的使用方式非常直觀:1. 選擇要上傳的 PDF 檔;2. 選擇 "GhostScript" ("ImageMagick" 是以將檔案轉為點陣圖檔的方式去實現平面化,此舉造成該 PDF 不再是向量圖檔),然後按下 "Flatten";3. 下載平面化的版本。
Notes
1. I know the symbol of vector graphics is SVG (Scalable Vector Graphics), but I hardly see anyone using it (maybe it lives in the free software community only), and many productivity softwares don't build-in SVG support. Therefore, I always use PDF.
2. Let me list the other websites I tried as below:
- https://altocompresspdf.com (it works and compress the file without the resolution loss, probably)
- https://www.pdf-online.com/osa/optimize.aspx (it works, but adds some watermark on the file)
- https://www.sejda.com/merge-pdf (fails)
- https://deftpdf.com/merge-pdf (fails)
- https://online.foxitsoftware.com/flatten-pdf (it needs to log-in and pay for service)
- https://www.pdfill.com/pdftool_form_field.html (it works, but the notes become un"text-selectable")
- https://pdfreal.com/flatten-pdf (fails)
- https://www.pdffiller.com/224173-fillable-flatten-pdf-online-form-wvsb-uscourts (it offers an online editor, not easy to use)
1. 我知道向量圖檔的代表是 SVG (Scalable Vector Graphics),但是我甚少看到任何人用它 (也許它只活在自由軟體社群裡),而且很多文書軟體都不內建支援 SVG,所以我總是用 PDF。
2. 以下是我試過的其他網站:
- https://altocompresspdf.com (成功且壓縮了檔案,畫質似乎沒有變差)
- https://www.pdf-online.com/osa/optimize.aspx (成功,但會加上浮水印)
- https://www.sejda.com/merge-pdf (失敗)
- https://deftpdf.com/merge-pdf (失敗)
- https://online.foxitsoftware.com/flatten-pdf (要登入且可能要收費)
- https://www.pdfill.com/pdftool_form_field.html (成功,但註解變成不可文字選取)
- https://pdfreal.com/flatten-pdf (失敗)
- https://www.pdffiller.com/224173-fillable-flatten-pdf-online-form-wvsb-uscourts (提供線上編輯器,太麻煩)
Hi, So it seems that since Mac OS ventura this stopped working properly. It now loses a lot of quality when running the action "New PDF from Images", can you please work on a fix? Thanks
回覆刪除Sorry about my late reply. "Flatten PDF" is an Automator application I use frequently. However, the version of Mac OS of my old Mac is Catalina (10.15), so I haven't found this issue util you gave me this feedback.
刪除Today I went to some Apple authorized reseller to check it. Yes, the quality becomes very bad after "New PDF from Images" works on that file.
Unfortunately, Automator is a system-level function, and Apple seems not to maintain its functionality, because Apple hopes Shortcut to take over its work, but Shortcut has no features to perform this function so far.
So, I will manage to use another PDF tools to approach a similar feature and integrate it to my script, but I need time.
Thank you for your reminder. I am not sure that when I could get my new M2 Mac mini (it might be the beginning of this April, based on Taiwan page of Apple.com). I will start the development to make a new one without "New PDF from Images" component, and I hope the result could be released in the near future.
Thank you again.