1. 제품
  2.   PDF
  3.   Node.js
  4.   Files2PDF
 
  

무료 Node.js 라이브러리를 통해 Office Word 및 PowerPoint를 PDF로 변환

Office Word 및 PowerPoint 파일을 PDF로 읽고 변환하기 위한 오픈 소스 Node.js PDF 변환기 API로, 배치 문서 변환을 지원합니다.

Files2PDF란 무엇인가요?

문서 관리 분야에서 파일을 PDF로 변환하는 것은 일상적인 필요입니다. 오래된 프레젠테이션을 보관하든 계약서를 최종 확정하든, 안정적이고 편집이 불가능한 형식에 대한 필요는 보편적입니다. 그러나 수백 개의 파일을 수동으로 변환하는 것은 악몽과 같습니다. 여기서 Files2Pdf가 등장합니다—이 경량이면서 강력한 Node.js 패키지는 바로 이 과정을 자동화하도록 설계되었습니다. 라이브러리에는 대량/배치 문서 처리, 다양한 문서 형식 지원, 이중 사용 모드, 스마트 오류 처리, 디렉터리 자동화 등 여러 중요한 기능이 포함되어 있습니다.

Files2Pdf는 사무 문서—특히 Microsoft Word 및 PowerPoint 파일—를 PDF 형식으로 변환하는 과정을 단순화하는 가벼운 Node.js 패키지입니다. 무거운 설정이 필요한 복잡한 엔터프라이즈 솔루션과 달리, Files2Pdf는 한 가지 일을 탁월하게 수행하는 데 집중합니다: 문서 전체 폴더를 처리하고 깔끔하고 바로 공유할 수 있는 PDF를 출력합니다. 이 라이브러리는 디렉터리에서 지원되는 파일을 자동으로 식별하고 호환되지 않는 파일은 건너뛰어 배치 작업 중 충돌이나 오류를 방지합니다.

Previous Next

Files2Pdf 시작하기

Files2PDF 모듈을 설치하는 가장 좋은 방법은 npm을 이용하는 것입니다. 다음 명령어를 사용하여 API를 설치하십시오.

npm을 통해 Files2PDF 라이브러리 설치

npm install files2pdf

GibHub을 통해 Files2PDF 라이브러리 설치

git clone "https://github.com/An4s0/Files2Pdf.git" 

배치 처리 기능

오픈 소스 Files2PDF 라이브러리는 여러 파일을 동시에 PDF 문서로 변환하는 다양한 기능을 포함하고 있습니다. 눈에 띄는 기능 중 하나는 전체 폴더의 문서를 한 번에 처리할 수 있다는 점입니다. 파일을 하나씩 변환하는 대신, 여러 문서가 들어 있는 디렉터리를 Files2PDF에 지정하면 지원되는 각 파일을 체계적으로 PDF 형식으로 변환합니다.

Node.js 애플리케이션에서 여러 문서를 PDF 파일로 변환하는 방법은?

const { processFolder } = require('files2pdf');
const path = require('path');
const fs = require('fs').promises;

async function convertDocuments(inputPath, outputPath) {
  try {
    // Verify input folder exists
    await fs.access(inputPath);
    
    console.log(`Starting conversion process...`);
    console.log(`Input folder: ${inputPath}`);
    console.log(`Output folder: ${outputPath}`);
    
    // Process all files in the folder
    await processFolder(inputPath, outputPath);
    
    console.log('Conversion completed successfully!');
    return { success: true, message: 'All documents converted' };
  } catch (error) {
    console.error('Conversion failed:', error.message);
    return { success: false, error: error.message };
  }
}

// Usage example
const inputDir = path.resolve(__dirname, 'documents');
const outputDir = path.resolve(__dirname, 'pdfs');

convertDocuments(inputDir, outputDir)
  .then(result => {
    if (result.success) {
      console.log('Success:', result.message);
    } else {
      console.log('Failed:', result.error);
    }
  });

다중 형식 지원

Files2PDF는 레거시 및 최신 Microsoft Office 형식을 모두 원활하게 처리합니다. 이 패키지는 .ppt 및 .pptx 형식의 PowerPoint 파일과 .doc 및 .docx 형식의 Word 문서를 지원합니다. 이러한 포괄적인 형식 지원은 다양한 버전의 Microsoft Office에서 만든 문서와의 호환성을 보장합니다. 다음 코드 예제는 파일 모니터링 시스템을 적용하여 새 파일을 감시하고 자동으로 변환하는 자동 문서 변환 시스템을 만드는 방법을 보여줍니다.

Node.js에서 디렉터리에 새로 로드된 파일을 변환하기 위한 파일 모니터링 시스템을 만드는 방법은?

const { processFolder } = require('files2pdf');
const chokidar = require('chokidar');
const path = require('path');
const fs = require('fs').promises;

class DocumentConverter {
  constructor(watchDir, outputDir) {
    this.watchDir = path.resolve(watchDir);
    this.outputDir = path.resolve(outputDir);
    this.processing = new Set();
  }

  async initialize() {
    // Ensure output directory exists
    await fs.mkdir(this.outputDir, { recursive: true });
    
    // Set up file watcher
    const watcher = chokidar.watch(this.watchDir, {
      ignored: /(^|[\/\\])\../, // ignore dotfiles
      persistent: true,
      ignoreInitial: false
    });

    watcher.on('add', async (filePath) => {
      await this.handleNewFile(filePath);
    });

    console.log(`Watching ${this.watchDir} for new documents...`);
  }

  async handleNewFile(filePath) {
    const ext = path.extname(filePath).toLowerCase();
    const supportedFormats = ['.ppt', '.pptx', '.doc', '.docx'];

    if (!supportedFormats.includes(ext)) {
      return; // Skip unsupported files
    }

    if (this.processing.has(filePath)) {
      return; // Already processing this file
    }

    this.processing.add(filePath);
    console.log(`New file detected: ${path.basename(filePath)}`);

    try {
      await processFolder(path.dirname(filePath), this.outputDir);
      console.log(`Successfully converted: ${path.basename(filePath)}`);
    } catch (error) {
      console.error(`Error converting ${path.basename(filePath)}:`, error.message);
    } finally {
      this.processing.delete(filePath);
    }
  }
}

// Initialize the converter
const converter = new DocumentConverter('./watched-folder', './converted-pdfs');
converter.initialize();

맞춤형 페이지 크기 및 방향

모든 PDF에 일괄 적용하는 방식은 통하지 않습니다. 스크린샷은 가로 방향이 가장 적합할 수 있고, 텍스트 문서는 세로 방향이 더 좋습니다. Files2PDF를 사용하면 전체 출력 PDF에 대해 페이지 크기(예: A4, Letter)와 방향(세로 또는 가로)을 정의할 수 있어 콘텐츠가 올바르게 표시됩니다.

지능형 파일 필터링

오픈 소스 Files2PDF 라이브러리는 소프트웨어 개발자가 지원되는 파일 유형만 자동으로 식별하고 처리하도록 쉽게 해주며, 오류를 발생시키지 않고 지원되지 않는 형식을 우아하게 건너뛰게 합니다. 이 지능형 필터링 메커니즘은 혼합된 파일 유형이 포함된 폴더를 작업할 때도 원활한 작동을 보장합니다.

 한국인