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 요청을 전송하여 서버에서 조립 프로세스를 시작합니다.다음 예제(More Feature 섹션에 표시)는 이러한 단계들을 간결하고 프로덕션 준비된 코드 스니펫으로 보여줍니다.
아래 스니펫은 전체 흐름을 보여줍니다: 템플릿을 업로드하고, 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);