強力なドキュメント組み立て機能を、GroupDocs.Assembly Cloud REST API を使用して、Node アプリケーションに統合できます。
無料トライアルを開始GroupDocs.Assembly Cloud は、完全にマネージドされた REST ベースのサービスで、開発者が再利用可能なテンプレートと外部データソースからリッチな書式設定が施された印刷対応ドキュメントを作成できるようにします。
このプラットフォームは、さまざまなソースおよびターゲット形式に対応しています – クラシックな Microsoft Office ファイル(DOCX、XLSX、PPTX)から PDF、HTML、OpenDocument、多数の画像形式まで – サーバーにサードパーティ製ソフトウェアをインストールせずに、契約書、請求書、レポート、マーケティングブローシャ、または任意のカスタムドキュメントを生成できます。テンプレートの解析、データバインディング、画像レンダリング、バーコード生成、数式評価、ファイル変換といった重い処理はすべてクラウドで実行され、OS間で一貫した結果を保証し、インフラコストを削減します。
Node.js SDK を使用する理由
Node.js アプリケーションの典型的なワークフロー
uploadFile メソッドを使用して GroupDocs Cloud Storage にアップロードします。AssembleOptions の設定 – テンプレートパス、データソース、希望する出力形式(PDF、DOCX、HTML など)および追加設定(例:バーコード生成、背景色)を指定します。assembleDocument の呼び出し – SDK が単一の HTTP リクエストを送信し、サーバー上で組み立てプロセスを起動します。以下の例(More Feature セクションに掲載)は、これらの手順をコンパクトで本番環境対応のコードスニペットで示しています。
以下のスニペットは、テンプレートのアップロード、JSON データファイルの読み取り、アセンブリ要求の設定、そして組み立てられたドキュメントの受信という完全なフローを示します。
Steps
AssembleOptions – 出力形式を選択し、データをバインドします。assembleDocument を使用してレポートを生成します。// Replace with your App SID and App Key
const { AssemblyApi, AssembleDocumentRequest, AssembleOptions, TemplateFileInfo, model } = require("groupdocs-assembly-cloud");
const fs = require("fs");
const path = require("path");
// Authorization placeholder
const assemblyApi = new AssemblyApi("####-####-####-####-####", "##################");
// 1️⃣ Upload the template file
const templatePath = "Input1.docx";
const uploadRequest = new model.UploadFileRequest({
fileContent: fs.createReadStream(templatePath),
path: templatePath
});
await assemblyApi.uploadFile(uploadRequest);
// 2️⃣ Read the data source (JSON)
const dataPath = "Input2.docx";
const reportData = fs.readFileSync(dataPath, "utf8");
// 3️⃣ Set assembly options
const assembleOptions = new AssembleOptions({
saveFormat: "pdf",
reportData: reportData,
templateFileInfo: new TemplateFileInfo({ filePath: templatePath })
});
// 4️⃣ Create and send the assemble request
const request = new AssembleDocumentRequest({ assembleOptions });
const result = await assemblyApi.assembleDocument(request);
// 5️⃣ Save the resulting document
const outputPath = path.join(__dirname, "GeneratedReport.pdf");
fs.writeFileSync(outputPath, result.body);
console.log("Report generated successfully:", outputPath);