HTML JPG PDF XML DOCX
  Product Family
PDF

Node.jsクラウドAPIでPDFをリサイズ

クラウドNode.js SDKを使用してサイズを変更するPDFドキュメントを操作するためのAPI

Get Started

Node.js SDKでPDFをリサイズする方法

PDFをリサイズするには、 Aspose.PDF Cloud Node.js SDKを使用します。このクラウドSDKは、Node.jsプログラマーがNode.jsプログラミング言語を使用してクラウドベースのPDF作成、注釈付け、編集、変換アプリを開発するのを支援します。App SIDとキーを取得すれば、Aspose.PDF Cloud Node.js SDKを使う準備が整います。

パッケージマネージャーコンソールコマンド


     
    npm install asposepdfcloud --save
     
     

Cloud Node.jsを介してPDFをリサイズする手順

Aspose.PDF Cloudの開発者は、数行のコードでPDFを簡単にロード&リサイズできます。

  1. Aspose PDF APIを初期化する
  2. 元のドキュメントをアップロードする
  3. PDFをHTML(XHTML形式)に変換し、結果を一時フォルダに保存する
  4. 指定された幅と高さを使用して、結果のHTMLをリサイズされたPDFに再変換する
  5. 成功した場合は結果のファイルをダウンロードする
 

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ドキュメント全体からすべてのスタンプとテーブルを削除します。
  • PDFドキュメントからIDで特定のスタンプやテーブルを削除します。
  • PDFページまたはドキュメント全体からテキストの単一または複数のインスタンスを置換します。
  • PDFドキュメントをさまざまな他のファイル形式に変換するための広範なサポート。
  • PDFファイルのさまざまな要素を抽出し、PDFドキュメントを最適化します。
  • 機能をテストするために無料アプリを試すことができます。