HTML
JPG
PDF
XML
DOCX
PDF
如何通过 Cloud Go SDK 调整 PDF 大小
为了调整 PDF 文档的大小,我们将使用 Aspose.PDF Cloud Go SDK 这个 Cloud SDK SDK 帮助 Go 程序员使用 Go 编程语言通过 Aspose.PDF REST API 开发基于云的 PDF 创建、注释、编辑和转换应用程序。请使用以下命令从包管理器控制台执行。
包管理器控制台命令
go get -u github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25
通过 Go 调整 PDF 大小的步骤
Aspose.PDF Cloud 开发人员可以仅用几行代码轻松加载和调整 PDF 大小。
- 上传 PDF。
- 将其转换为 HTML(保留结构/内容)。
- 将 HTML 转换回具有指定尺寸的新 PDF。
- 下载调整大小后的文档。
使用 Cloud Go SDK 调整 PDF 大小
package main
import (
"fmt"
"path/filepath"
asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25"
)
func resizeAllPages(pdf_api *asposepdfcloud.PdfApiService, document_name string, htmlTempDoc string, width int, height int, outputDocument string, localFolder string, tempFolder string) {
uploadFile(pdf_api, document_name)
htmlTempPath := filepath.Join(tempFolder, htmlTempDoc)
args := map[string]interface{}{
"folder": tempFolder,
"documentType": string(asposepdfcloud.HtmlDocumentTypeXhtml),
"outputFormat": string(asposepdfcloud.OutputFormatFolder),
}
_, response, err := pdf_api.PutPdfInStorageToHtml(document_name, htmlTempPath, args)
if err != nil {
fmt.Println(err.Error())
} else if response.StatusCode < 200 || response.StatusCode > 299 {
fmt.Println("resizePages(): Can't convert pdf to html!")
} else {
fmt.Println("resizePages(): temporary file '" + htmlTempDoc + "' succesfully creaated.")
}
args2 := map[string]interface{}{
"dstFolder": tempFolder,
"htmlFileName": htmlTempDoc,
"height": float64(height),
"width": float64(width),
}
_, response, err = pdf_api.PutHtmlInStorageToPdf(outputDocument, htmlTempPath, args2)
if err != nil {
fmt.Println(err.Error())
} else if response.StatusCode < 200 || response.StatusCode > 299 {
fmt.Println("resizePages(): Can't convert html to pdf!")
} else {
fmt.Println("resizePages(): Pages successfully resized.")
downloadFile(pdf_api, outputDocument, "resized_doc_")
}
}
使用我们的 Go SDK,您可以
- 添加 PDF 文档的文本或图像格式的页眉和页脚。
- 向 PDF 文档添加表格和文本或图像水印。
- 将多个 PDF 文档附加到现有文件。
- 处理 PDF 附件、注释和表单字段。
- 对 PDF 文档应用加密或解密并设置密码。
- 从页面或整个 PDF 文档中删除所有水印和表格。
- 按 ID 从 PDF 文档中删除特定的水印或表格。
- 替换 PDF 页面上或整个文档中的单个或多个文本实例。
- 广泛支持将 PDF 文档转换为各种其他文件格式。
- 提取 PDF 文件的各种元素并优化 PDF 文档。
- 您可以尝试我们的免费应用程序来测试功能。