GroupDocs.Assembly Cloud REST API を使用して、強力なドキュメント アセンブリ機能を Node アプリケーションに統合します。
無料トライアルを開始GroupDocs.Assembly Cloud は、開発者が再利用可能なテンプレートや外部データソースから、リッチフォーマットで印刷可能なドキュメントを作成できる、フルマネージドの REST ベースサービスです。
このプラットフォームは、従来の Microsoft Office ファイル (DOCX、XLSX、PPTX) から PDF、HTML、OpenDocument、そして多くのグラフィック形式まで、幅広いソースおよびターゲット形式をサポートしているため、自社サーバーにサードパーティ製ソフトウェアをインストールすることなく、契約書、請求書、レポート、マーケティングパンフレット、その他あらゆるカスタムドキュメントを作成できます。テンプレート解析、データバインディング、画像レンダリング、バーコード生成、数式評価、ファイル変換といった面倒な処理はすべてクラウドで実行されるため、オペレーティングシステム間で一貫した結果が得られ、インフラストラクチャコストを削減できます。
Node.js SDK を使用する理由
Node.jsアプリケーションの一般的なワークフロー
uploadFile メソッドを使用して、テンプレートを GroupDocs Cloud Storage にアップロード します。AssembleOptions を構成します – テンプレートのパス、データソース、希望する出力形式(PDF、DOCX、HTML など)、および追加の設定(バーコード生成、背景色など)を指定します。assembleDocument を呼び出します – SDK は、サーバー上でアセンブリ プロセスをトリガーする単一の HTTP リクエストを送信します。次の例(その他の機能 セクションに表示)は、これらの各ステップを、コンパクトで本番環境に対応したコード スニペットで示しています。
以下のスニペットは、テンプレートのアップロード、JSON データファイルの読み取り、アセンブリリクエストの設定、そしてアセンブリされたドキュメントの受信という、一連のフロー全体を示しています。
手順
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);