我想以编程方式优化(即“另存为缩小尺寸的PDF”在Acrobat Pro 10)一系列的PDF文件。如果可能的话,我更喜欢在python 2.7.5中完成这项工作,如果不是在python中,那么也许可以在VBA Word中完成,而我的最后一个偏好是从另一种编程机制中完成这项工作。
想法?
发布于 2014-04-24 11:27:39
一个建议是看看pdfsizeopt。
Python程序旨在充当PDF文件大小优化器。它可用于将较大的pdf转换为较小的pdf,并支持您可以调用的命令行界面。
详细信息:
PDF pdfsizeopt是一个用于将大型
文件转换为小型文件的程序。更具体地说,pdfsizeopt是一个免费的、跨平台的命令行应用程序(适用于Linux、Mac、Windows和Unix)和一组优化PDF文件大小的最佳实践,重点是从TeX和LaTeX文档创建的PDF文件。pdfsizeopt是用Python语言编写的,所以它有点慢,但它将一些繁重的工作卸载到更快的(C,C++和Java)依赖项上。pdfsizeopt是在Linux系统上开发的,它依赖于现有的工具,如Python2.4、Ghostscrip8.50、jbig2enc (可选)、sam2p、pngtopnm、pngout (可选)和用Java语言编写的多价PDF压缩器(可选)。
参考资料:
http://code.google.com/p/pdfsizeopt/
发布于 2021-03-31 14:16:21
另一个选项可以是Aspose.PDF Cloud SDK for Python。它是一个付费的REST API,但每月提供150个免费的API调用。目前,它从云存储(Aspose默认存储/AmazonS3/Google Drive/ Azure存储/ Dropbox/ FTP存储)压缩PDF文档。在不久的将来,我们计划支持从请求体(流)压缩PDF。
import os
import asposepdfcloud
from asposepdfcloud.apis.pdf_api import PdfApi
from shutil import copyfile
# Get App key and App SID from https://cloud.aspose.com
pdf_api_client = asposepdfcloud.api_client.ApiClient(
app_key='xxxxxxxxxxxxxxxxxxxxxxxxxx',
app_sid='xxxxx-xxxx-xxxx-xxxx-xxxxxxxx')
pdf_api = PdfApi(pdf_api_client)
temp_folder="Temp"
#upload PDF file to storage
data_file = "C:/Temp/02_pages.pdf"
remote_name="02_pages.pdf"
result_name="02_pages_compressed.pdf"
pdf_api.upload_file(temp_folder + '/' + remote_name,data_file)
optimize_options = asposepdfcloud.models.OptimizeOptions(
allow_reuse_page_content=False,
compress_images=True,
image_quality=100,
link_duplcate_streams=True,
remove_unused_objects=True,
remove_unused_streams=True,
unembed_fonts=True)
opts = {
"options" : optimize_options,
"folder" : temp_folder
}
response = pdf_api.post_optimize_document(remote_name, **opts)
#download PDF file from storage
response_download = pdf_api.download_file(temp_folder + '/' + remote_name)
copyfile(response_download, 'C:/Temp/' + result_name)
print(response)附言:我是Aspose的开发者布道者。
发布于 2021-04-24 04:47:52
我正在使用Ghostscript批处理pdf。此VBA适用于Word和Excel。它请求一个源目录和一个目标目录。.bat文件被创建并存储在源文件夹中,然后您就可以执行它了。我可能会让这个脚本更健壮,当我这样做的时候会在这里更新。
Sub gsPDF_Bat()
'Summary of -dPDFSETTINGS:
'-dPDFSETTINGS=/screen lower quality, smaller size. (72 dpi)
'-dPDFSETTINGS=/ebook for better quality, but slightly larger pdfs. (150 dpi)
'-dPDFSETTINGS=/prepress output similar to Acrobat Distiller "Prepress Optimized" setting (300 dpi)
'-dPDFSETTINGS=/printer selects output similar to the Acrobat Distiller "Print Optimized" setting (300 dpi)
'-dPDFSETTINGS=/default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file
Dim ProofsFolder As String
Dim CompressFolder As String
Dim exePath As String
exePath = "C:\Program Files\gs\gs9.54.0\bin\"
' Open the select folder prompt
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then ' if OK is pressed
ProofsFolder = .SelectedItems(1)
End If
End With
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then ' if OK is pressed
CompressFolder = .SelectedItems(1)
End If
End With
Dim fso As Object
Dim folder As Object
Dim CurrFile As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(ProofsFolder)
Open ProofsFolder & "\gsPDF-Compress.bat" For Output As #1
For Each CurrFile In folder.Files
FName = CurrFile.Name
CurrFileExt = Right(FName, 4)
Debug.Print CurrFileExt
If CurrFileExt = ".pdf" Then
backNum = InStrRev(CurrFile, "\", -1)
FName = Mid(CurrFile, (backNum + 1))
Print #1, exePath & "gswin64 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dAutoRotatePages=/None -r300 -dUseCIEColor -sOutputFile=""" & CompressFolder & "\" & FName & """ """ & CurrFile & """"
End If
Next
Close #1
Set fso = Nothing
Set folder = Nothing
End Subhttps://stackoverflow.com/questions/23257191
复制相似问题