फ़्री Node.js लाइब्रेरी के माध्यम से Office Word और PowerPoint को PDF में बदलें

ओपन सोर्स Node.js PDF कन्वर्टर API जो Office Word और PowerPoint फ़ाइलों को PDF में पढ़ने और परिवर्तित करने के लिए बैच दस्तावेज़ रूपांतरण समर्थन के साथ है।

Files2PDF क्या है?

दस्तावेज़ प्रबंधन की दुनिया में, फ़ाइलों को PDF में बदलना एक दैनिक आवश्यकता है। चाहे आप पुराने प्रस्तुतियों को संग्रहित कर रहे हों या अनुबंधों को अंतिम रूप दे रहे हों, एक स्थिर, अपरिवर्तनीय फ़ॉर्मेट की आवश्यकता सार्वभौमिक है। हालांकि, सैकड़ों फ़ाइलों को मैन्युअल रूप से करना एक दुःस्वप्न है। यहाँ आता है Files2Pdf—एक हल्का, शक्तिशाली Node.js पैकेज जो इस प्रक्रिया को स्वचालित करने के लिए बनाया गया है। लाइब्रेरी में कई महत्वपूर्ण विशेषताएँ शामिल हैं, जैसे कि बल्क/बैच दस्तावेज़ प्रोसेसिंग, कई दस्तावेज़ फ़ॉर्मेट के साथ काम करना, दोहरी उपयोग मोड, स्मार्ट एरर हैंडलिंग, डायरेक्टरी ऑटोमेशन, आदि।

Files2Pdf एक हल्का Node.js पैकेज है जो ऑफिस दस्तावेज़ों—विशेष रूप से Microsoft Word और PowerPoint फ़ाइलों—को PDF फ़ॉर्मेट में बदलने को सरल बनाता है। जटिल एंटरप्राइज़ समाधान जो भारी कॉन्फ़िगरेशन की मांग करते हैं, उनके विपरीत, 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 फ़ॉर्मेट्स को सहजता से संभालता है। यह पैकेज PowerPoint फ़ाइलों को .ppt और .pptx दोनों फ़ॉर्मेट में, साथ ही Word दस्तावेज़ों को .doc और .docx फ़ॉर्मेट में समर्थन देता है। यह व्यापक फ़ॉर्मेट समर्थन विभिन्न 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();

कस्टमाइज़ेबल पेज आकार और अभिविन्यास

एक ही आकार सभी PDFs पर लागू नहीं होता। एक स्क्रीनशॉट लैंडस्केप में बेहतर हो सकता है, जबकि टेक्स्ट दस्तावेज़ पोर्ट्रेट में बेहतर रहता है। Files2PDF आपको पूरे आउटपुट PDF के लिए पेज आकार (जैसे, A4, Letter) और अभिविन्यास (Portrait या Landscape) निर्धारित करने की अनुमति देता है, जिससे आपका कंटेंट सही तरीके से प्रदर्शित हो।

बुद्धिमान फ़ाइल फ़िल्टरिंग

ओपन सोर्स Files2PDF लाइब्रेरी सॉफ़्टवेयर डेवलपर्स के लिए केवल समर्थित फ़ाइल प्रकारों को स्वचालित रूप से पहचानना और प्रोसेस करना आसान बनाती है, असमर्थित फ़ॉर्मेट्स को बिना त्रुटियों के सहजता से छोड़ देती है। यह बुद्धिमान फ़िल्टरिंग तंत्र मिश्रित फ़ाइल प्रकारों वाले फ़ोल्डरों के साथ काम करते समय भी सुगम संचालन सुनिश्चित करता है।

 हिन्दी