HTML
JPG
PDF
XML
DOCX
PDF
如何通过 Node.js SDK 调整 PDF 大小
要调整 PDF 大小,我们将使用 Aspose.PDF Cloud Node.js SDK。这个云 SDK 帮助 Node.js 程序员使用 Aspose.PDF REST API 开发基于云的 PDF 创建、注释、编辑和转换应用程序。一旦您拥有 App SID 和密钥,您就可以开始使用 Aspose.PDF Cloud Node.js SDK。
包管理器控制台命令
npm install asposepdfcloud --save
通过云端 Node.js 调整 PDF 大小的步骤
Aspose.PDF Cloud 开发人员可以轻松地在几行代码中加载和调整 PDF 大小。
- 初始化 Aspose PDF API
- 上传原始文档
- 将 PDF 转换为 HTML(XHTML 格式)并将结果存储在临时文件夹中
- 使用指定的宽度和高度将生成的 HTML 转换回调整大小的 PDF
- 如果成功,下载生成的文件
使用 Node.js 调整 PDF 大小
import { PdfChangeLayoutHelper, pdfApi } from "./changeLayoutHelper.js";
import path from 'node:path';
import { HtmlDocumentType } from "../../src/models/htmlDocumentType.js";
import { OutputFormat } from "../../src/models/outputFormat.js"
export { PdfResizePages }
const PdfResizePages = {
async resizeAllPages(document, htmlTempDoc, width, height, outputDocument, localFolder, tempFolder) {
await PdfChangeLayoutHelper.uploadDocument(document, localFolder, tempFolder)
const htmlTempPath = path.join(tempFolder, htmlTempDoc);
const html_response = await pdfApi.putPdfInStorageToHtml(
document,
htmlTempPath,
null, null, null, null,
HtmlDocumentType.Xhtml,
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
tempFolder,
null, null,
OutputFormat.Folder);
if (html_response.body.code != 200) {
console.error("resizePages(): Can't convert pdf to html!");
return;
}
else
console.log("resizePages(): temporary file '" + htmlTempDoc + "' succesfully creaated.")
const response = await pdfApi.putHtmlInStorageToPdf(
outputDocument,
htmlTempPath,
htmlTempDoc,
height,
width,
null, null, null, null, null,
tempFolder,
null);
if (response.body.code == 200) {
console.log("resizePages(): Pages successfully resized.");
await PdfChangeLayoutHelper.downloadResult(outputDocument, localFolder, tempFolder, "resized_doc_");
}
else
console.log("resizePages(): Can't convert html to pdf!")
}
}
使用我们的 Node.js 库,您可以
使用 Aspose.PDF Cloud Node.js SDK 调整 PDF 文档的大小。
- 添加 PDF 文档的文本或图像格式的页眉和页脚。
- 向 PDF 文档添加表格和印章(文本或图像)。
- 将多个 PDF 文档追加到现有文件。
- 处理 PDF 附件、注释和表单字段。
- 对 PDF 文档进行加密或解密并设置密码。
- 删除页面或整个 PDF 文档中的所有印章和表格。
- 根据 ID 删除 PDF 文档中的特定印章或表格。
- 替换 PDF 页面或整个文档中的单个或多个文本实例。
- 广泛支持将 PDF 文档转换为各种其他文件格式。
- 提取 PDF 文件的各个元素并优化 PDF 文档。
- 您可以尝试我们的免费应用来测试功能。