PDF पेज आयाम .NET - चौड़ाई और ऊँचाई निकालें C# के साथ

परिचय

क्या आप कभी अपने .NET एप्लिकेशन में PDF दस्तावेज़ों के साथ जूझते हुए हर पेज के लिए get pdf page size प्राप्त करने की आवश्यकता महसूस करते हैं? आप अकेले नहीं हैं। चाहे आप एक दस्तावेज़ दर्शक बना रहे हों, प्रिंट लेआउट तैयार कर रहे हों, या फ़ॉर्म प्रोसेस कर रहे हों, सटीक पेज आयाम एक परिष्कृत उपयोगकर्ता अनुभव की रीढ़ होते हैं।

इस व्यापक गाइड में, हम आपको GroupDocs.Annotation for .NET का उपयोग करके PDF पेज आयाम निकालने की प्रक्रिया से गुजरेंगे—यह कार्य के लिए सबसे विश्वसनीय लाइब्रेरीज़ में से एक है। अंत तक, आपके पास कार्यशील कोड होगा जो किसी भी PDF दस्तावेज़ से चौड़ाई, ऊँचाई और अन्य आवश्यक मेटाडेटा प्राप्त करता है।

त्वरित उत्तर

  • .NET में pdf पेज आकार कैसे प्राप्त करें? Use Annotator.GetDocumentInfo() and read PageInfo.Width / PageInfo.Height.
  • pdf पेज चौड़ाई ऊँचाई निष्कर्षण को कौन सी लाइब्रेरी समर्थन करती है? GroupDocs.Annotation for .NET (v25.4.0+).
  • बुनियादी आयाम निष्कर्षण के लिए क्या मुझे लाइसेंस चाहिए? A free trial works; a commercial license is required for production.
  • कौन से इकाइयाँ लौटाई जाती हैं? Points (1/72 inch); convert to inches or millimeters as needed.
  • क्या मैं बड़े PDFs को कुशलतापूर्वक प्रोसेस कर सकता हूँ? Yes—GroupDocs.Annotation reads metadata without loading the full file into memory.

get pdf page size क्या है?

Get pdf page size का अर्थ है PDF पेज की चौड़ाई और ऊँचाई का प्रोग्रामेटिक रूप से प्राप्त करना। यह ऑपरेशन लेआउट गणनाओं, प्रिंट तैयारी, और .NET एप्लिकेशनों में फ़ॉर्म फ़ील्ड पोजिशनिंग के लिए आवश्यक है।

.NET विकास में PDF पेज आयाम क्यों महत्वपूर्ण हैं

कोड में कूदने से पहले, चलिए देखते हैं कि pdf page width height को जानना क्यों महत्वपूर्ण है। ये संख्याएँ केवल जानकारी नहीं हैं—वे वास्तविक‑दुनिया की कार्यक्षमता को संचालित करती हैं:

  • लेआउट प्रबंधन – रिस्पॉन्सिव व्यूअर्स सटीक पेज आकार के आधार पर स्वतः स्केल कर सकते हैं, जिससे अजीब स्क्रॉलबार समाप्त हो जाते हैं।
  • प्रिंट अनुकूलन – सटीक आयाम कागज़ की बर्बादी और व्यावसायिक वर्कफ़्लो में गलत संरेखित प्रिंट को रोकते हैं।
  • फ़ॉर्म प्रोसेसिंग – एक्सट्रैक्शन कॉर्डिनेट्स सटीक पेज आकार पर निर्भर होते हैं; 2 mm की त्रुटि डेटा कैप्चर को बिगाड़ सकती है।
  • संसाधन योजना – बड़े, मिश्रित‑आकार PDFs को विभिन्न मेमोरी रणनीतियों की आवश्यकता होती है; प्रारंभिक आकार जानकारी अधिक समझदार बैचिंग को सक्षम करती है।

पूर्वापेक्षाएँ

आवश्यक लाइब्रेरी और संस्करण

  • GroupDocs.Annotation for .NET (संस्करण 25.4.0 या बाद का)। यह संस्करण 50+ इनपुट और आउटपुट फ़ॉर्मेट का समर्थन करता है और पूरी फ़ाइल को मेमोरी में लोड किए बिना कई‑सौ‑पेज PDFs को संभाल सकता है।
  • .NET Framework 4.6.1+ या .NET Core 2.0+

पर्यावरण सेटअप आवश्यकताएँ

  • Visual Studio 2019 या बाद का (Community संस्करण पूरी तरह काम करता है)
  • एक परीक्षण PDF फ़ाइल (हम आपको विभिन्न प्रकारों को संभालने का तरीका दिखाएंगे)
  • C# में using स्टेटमेंट्स और ऑब्जेक्ट डिस्पोज़ल की बुनियादी परिचितता

ज्ञान पूर्वापेक्षाएँ

आपको केवल चाहिए:

  • C# मूलभूत बातें
  • NuGet पैकेज प्रबंधन की मूल बातें
  • .NET में सरल फ़ाइल I/O

सब कुछ तैयार है? बढ़िया—आइए लाइब्रेरी सेटअप करें।

GroupDocs.Annotation for .NET सेटअप करना

GroupDocs.Annotation को स्थापित करना सरल है, लेकिन आपके वर्कफ़्लो के आधार पर इसे करने के कुछ तरीके हैं।

विधि 1: NuGet पैकेज मैनेजर कंसोल का उपयोग करना

Open the Package Manager Console in Visual Studio and run:

Install-Package GroupDocs.Annotation -Version 25.4.0

विधि 2: .NET CLI का उपयोग करना

If you prefer command‑line tools:

dotnet add package GroupDocs.Annotation --version 25.4.0

विधि 3: विज़ुअल पैकेज मैनेजर

  1. Solution Explorer में अपने प्रोजेक्ट पर राइट‑क्लिक करें
  2. Manage NuGet Packages चुनें
  3. GroupDocs.Annotation खोजें
  4. Install पर क्लिक करें

लाइसेंस विकल्प (जो आपके लिए उपयुक्त हो चुनें)

  • Free Trial – कोर फीचर, जिसमें आयाम निष्कर्षण शामिल है, छोटे उपयोग सीमाओं के साथ उपलब्ध हैं—प्रूफ़‑ऑफ़‑कॉन्सेप्ट कार्य के लिए उत्तम।
  • Temporary License – मूल्यांकन के दौरान पूर्ण कार्यक्षमता के लिए 30‑दिन का अस्थायी कुंजी अनुरोध करें।
  • Commercial License – प्रोडक्शन डिप्लॉयमेंट्स के लिए आवश्यक; कीमत डेवलपर संख्या और डिप्लॉयमेंट मॉडल के अनुसार बढ़ती है।

त्वरित सेटअप सत्यापन

Here’s a simple test to confirm everything is wired correctly:

using GroupDocs.Annotation;

// This should compile without errors if installation succeeded
using (Annotator annotator = new Annotator(@"path\to\your\test.pdf"))
{
    Console.WriteLine("GroupDocs.Annotation is ready to use!");
}

यदि यह कंपाइल हो जाता है और बिना किसी अपवाद के चल जाता है, तो आप पेज आकार निकालने के लिए तैयार हैं।

Annotator क्लास क्या है?

The Annotator class is GroupDocs.Annotation’s core object that represents a PDF document in memory and provides methods to read metadata, add annotations, and extract page information. It encapsulates file handling, supports loading from streams, and ensures that all subsequent operations flow through an Annotator instance, simplifying workflow management.

GroupDocs.Annotation का उपयोग करके get pdf page size कैसे प्राप्त करें?

GetDocumentInfo() returns a DocumentInfo object containing overall PDF metadata, including page count and a collection of page details. Load your PDF with new Annotator("file.pdf") and call this method; each PageInfo in the Pages collection holds Width and Height. This two‑step approach provides dimensions in points instantly, without parsing the entire file.

चरण‑दर‑चरण कार्यान्वयन गाइड

चरण 1: अपने PDF के साथ Annotator को इनिशियलाइज़ करें

Create an Annotator instance pointing to your PDF file. Always wrap it in a using block so the file handle is released promptly.

using (Annotator annotator = new Annotator(@"YOUR_DOCUMENT_DIRECTORY\INPUT_PDF"))
{
    // All our dimension extraction magic happens here
}

प्रो टिप: उचित डिस्पोज़ल मेमोरी लीक को रोकता है, विशेष रूप से जब बैच जॉब में दर्जनों बड़े PDFs प्रोसेस किए जाते हैं।

चरण 2: दस्तावेज़ जानकारी प्राप्त करें

DocumentInfo is an object that holds overall PDF metadata such as total page count and a collection of PageInfo objects for each page.

GroupDocs.Annotation makes metadata extraction a one‑liner:

IDocumentInfo info = annotator.Document.GetDocumentInfo();

The returned DocumentInfo object gives you:

  • कुल पेज संख्या
  • फ़ाइल फ़ॉर्मेट विवरण
  • एक Pages सूची जहाँ प्रत्येक प्रविष्टि में चौड़ाई, ऊँचाई, रोटेशन, और अधिक शामिल हैं

चरण 3: प्राप्त डेटा को मान्य करें

Before you start looping over pages, confirm the document info isn’t null and that the page collection contains entries.

if (info.PagesInfo != null && info.PagesInfo.Count > 0)
{
    Console.WriteLine($"\t Document info: Type {info.FileType}, size = {info.Size}, pages = {info.PageCount}");
}
else
{
    Console.WriteLine("No page information available - check your PDF file");
    return;
}

This defensive check avoids null‑reference exceptions and provides early feedback if the PDF is corrupted.

चरण 4: प्रत्येक पेज के लिए चौड़ाई और ऊँचाई निकालें

PageInfo represents a single page’s properties, including its width, height, and rotation angle.

Iterate through the Pages collection and read Width and Height. Remember that the values are expressed in points (1 point = 1/72 inch).

foreach (var page in info.PagesInfo)
{
    Console.WriteLine($"\t\t page #{page.PageNumber}: {page.Width}x{page.Height}");
}

मुख्य बिंदु

  • चौड़ाई पहले आती है, फिर ऊँचाई।
  • पेज नंबर 1‑आधारित होते हैं, जो उपयोगकर्ता व्यूअर्स में देखते हैं।
  • यदि आपको कॉर्डिनेट्स समायोजित करने की आवश्यकता है तो रोटेशन जानकारी भी उपलब्ध है।

पूर्ण कार्यशील उदाहरण (मेथड)

You can wrap the above steps into a reusable method:

using GroupDocs.Annotation;
using System;

public void ExtractPdfPageDimensions(string pdfPath)
{
    try
    {
        using (Annotator annotator = new Annotator(pdfPath))
        {
            IDocumentInfo info = annotator.Document.GetDocumentInfo();
            
            if (info.PagesInfo != null && info.PagesInfo.Count > 0)
            {
                Console.WriteLine($"Document: {info.FileType}, {info.Size} bytes, {info.PageCount} pages");
                
                foreach (var page in info.PagesInfo)
                {
                    Console.WriteLine($"Page {page.PageNumber}: {page.Width} x {page.Height} points");
                }
            }
            else
            {
                Console.WriteLine("Could not retrieve page information");
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Error processing PDF: {ex.Message}");
    }
}

सामान्य कठिनाइयाँ और उन्हें कैसे टालें

Even with straightforward code, developers encounter predictable issues. Below are the most common traps and proven solutions.

फ़ाइल पाथ समस्याएँ

समस्या: “File not found” errors during development.
समाधान: Use absolute paths while testing and always verify the file exists before creating the Annotator.

if (!File.Exists(pdfPath))
{
    throw new FileNotFoundException($"PDF file not found: {pdfPath}");
}

अनुमति समस्याएँ

समस्या: The application lacks read access to the PDF file, especially on web servers.
समाधान: Grant the appropriate read permissions to the application pool identity or use impersonation for restricted folders.

दूषित PDF हैंडलिंग

समस्या: Some PDFs are partially damaged or use non‑standard features.
समाधान: Enclose the extraction logic in a try‑catch block and surface a clear error message. GroupDocs.Annotation will throw a DocumentException for unsupported structures.

बड़े फ़ाइलों के साथ मेमोरी लीक

समस्या: Processing many large PDFs without disposing of Annotator instances leads to out‑of‑memory crashes.
समाधान: Always employ using statements and consider processing files in smaller batches or streaming mode.

संस्करण संगतता

समस्या: Mixing different GroupDocs library versions can cause type mismatches.
समाधान: Standardize on a single version across the solution and update all related packages together.

वास्तविक‑विश्व अनुप्रयोग

Understanding retrieve pdf width height unlocks powerful scenarios:

दस्तावेज़ दर्शक अनुप्रयोग

Responsive viewers can automatically set the initial zoom level based on page dimensions, delivering a “fit‑to‑screen” experience without manual tweaking.

// Example: Calculate optimal zoom for viewport
double optimalZoom = Math.Min(viewportWidth / pageWidth, viewportHeight / pageHeight);

स्वचालित रिपोर्ट जनरेशन

When merging multiple PDFs into a single report, knowing each page’s size ensures consistent scaling and avoids unexpected page breaks.

प्रिंट प्रबंधन सिस्टम

Exact dimensions let you calculate optimal paper usage, detect portrait vs. landscape orientation, and pre‑flight documents before sending them to commercial printers.

फ़ॉर्म प्रोसेसिंग समाधान

Accurate coordinates derived from page size enable reliable extraction of checkboxes, signatures, and text fields across PDFs of varying layouts.

डिजिटल एसेट मैनेजमेंट

Tag PDFs with size metadata to facilitate quick searches (e.g., “show all A4‑sized documents”) and improve cataloging efficiency.

प्रदर्शन अनुकूलन टिप्स

When you move from a prototype to production, performance becomes critical.

बैच प्रोसेसिंग रणनीति

Group similar operations to reduce overhead. For example, read metadata for a batch of files, store the results, then process annotations in a second pass.

var results = new List<PageDimensionResult>();
foreach (var pdfFile in pdfFiles.Take(10)) // Process in batches of 10
{
    // Extract dimensions and add to results
}

अक्सर एक्सेस किए जाने वाले आयामों को कैश करना

If the same PDFs are queried repeatedly, cache their DocumentInfo objects in a thread‑safe dictionary. Remember to invalidate the cache when the source file changes.

private static readonly Dictionary<string, IDocumentInfo> _dimensionCache = 
    new Dictionary<string, IDocumentInfo>();

बड़े फ़ाइलों के लिए असिंक्रोनस प्रोसेसिंग

Leverage async/await patterns to keep UI threads responsive while GroupDocs.Annotation reads metadata in the background.

public async Task<List<PageInfo>> ExtractDimensionsAsync(string pdfPath)
{
    return await Task.Run(() => {
        // Your dimension extraction code here
    });
}

मेमोरी प्रबंधन सर्वोत्तम प्रथाएँ

  • Dispose of every Annotator instance promptly.
  • Process large collections in chunks of 20–50 files to keep memory footprints low.
  • Monitor memory usage with performance counters or profiling tools.
  • Use weak references for cached objects if you expect high turnover.

उन्नत उपयोग केस

Once you’re comfortable with basic extraction, explore these sophisticated scenarios.

मिश्रित‑आकार दस्तावेज़ों को संभालना

Some PDFs contain pages of different sizes (e.g., a cover page in A4 followed by A5 inner pages). Detect size changes by comparing consecutive PageInfo.Width/Height values and apply conditional logic.

var pageSizes = info.PagesInfo.Select(p => new { p.PageNumber, p.Width, p.Height }).ToList();
var uniqueSizes = pageSizes.Select(p => new { p.Width, p.Height }).Distinct().Count();

if (uniqueSizes > 1)
{
    Console.WriteLine("Document contains multiple page sizes");
}

अभिविन्यास पहचान

Determine portrait vs. landscape by comparing width and height. This is useful for auto‑rotating pages in viewers or for generating orientation‑aware thumbnails.

foreach (var page in info.PagesInfo)
{
    string orientation = page.Width > page.Height ? "Landscape" : "Portrait";
    Console.WriteLine($"Page {page.PageNumber}: {orientation}");
}

अन्य GroupDocs सुविधाओं के साथ एकीकरण

Combine dimension extraction with annotation APIs to place stamps precisely, or with conversion APIs to generate images that respect the original page size.

अक्सर पूछे जाने वाले प्रश्न

Q: क्या मैं लाइसेंस के बिना PDF पेज आयाम निकाल सकता हूँ?
A: हाँ। फ्री ट्रायल संस्करण बुनियादी आयाम निष्कर्षण का समर्थन करता है, हालांकि यह प्रति सत्र प्रोसेस किए जाने वाले पेजों की संख्या पर सीमा लगा सकता है।

Q: चौड़ाई और ऊँचाई माप किस इकाई में होते हैं?
A: GroupDocs.Annotation आयाम points (1 point = 1/72 inch) में लौटाता है। इंच में बदलने के लिए 72 से विभाजित करें, या मिलीमीटर में बदलने के लिए 0.352778 से गुणा करें।

Q: पासवर्ड‑सुरक्षित PDFs को कैसे संभालूँ?
A: Annotator बनाते समय LoadOptions के माध्यम से पासवर्ड पास करें: new Annotator(path, new LoadOptions { Password = "your‑password" })।

Q: क्या यह Azure या AWS जैसी क्लाउड स्टोरेज में संग्रहीत PDFs के साथ काम कर सकता है?
A: हाँ। फ़ाइल को पहले स्थानीय Stream में डाउनलोड करें, फिर स्ट्रीम‑आधारित Annotator कंस्ट्रक्टर का उपयोग करें ताकि मध्यवर्ती फ़ाइलों से बचा जा सके।

Q: बड़े PDFs से आयाम निकालने का प्रदर्शन प्रभाव क्या है?
A: GroupDocs.Annotation केवल PDF की क्रॉस‑रेफ़रेंस टेबल और पेज डिक्शनरी पढ़ता है, इसलिए अधिकांश 100 MB से छोटे PDFs को सामान्य सर्वर हार्डवेयर पर 1 सेकंड से कम समय में प्रोसेस किया जाता है।

Q: घुमाए गए पेजों को कैसे संभालूँ?
A: PageInfo.Rotation प्रॉपर्टी घुमाव कोण दर्शाती है। यदि पेज 90° या 270° घुमा है, तो प्रदर्शित आयाम प्राप्त करने के लिए चौड़ाई और ऊँचाई को स्वैप करें।

Q: क्या मैं केवल विशिष्ट पेजों के आयाम निकाल सकता हूँ?
A: हाँ। GetDocumentInfo() कॉल करने के बाद, Pages संग्रह को PageNumber द्वारा फ़िल्टर करके व्यक्तिगत पेजों को लक्षित कर सकते हैं।

Q: क्या यह PDF/A फ़ॉर्मेट दस्तावेज़ों के साथ काम करता है?
A: बिल्कुल। GroupDocs.Annotation PDF/A‑1, PDF/A‑2, और PDF/A‑3 मानकों को पूरी तरह समर्थन करता है।

Q: “Unable to load document” त्रुटियों को कैसे ट्रबलशूट करूँ?
A: फ़ाइल अनुमतियों की जाँच करें, फ़ाइल को PDF रीडर में खोलकर देखें कि वह भ्रष्ट तो नहीं है, और सुनिश्चित करें कि आप समर्थित PDF संस्करण (1.4–2.0) का उपयोग कर रहे हैं।

Q: क्या मैं आयाम पिक्सेल में प्राप्त कर सकता हूँ?
A: मैन्युअल रूप से बदलें: pixels = points * DPI / 72। सामान्य स्क्रीन DPI 96 के लिए, पॉइंट को 1.3333 से गुणा करें।

आवश्यक संसाधन


अंतिम अपडेट: 2026-06-16
परीक्षित संस्करण: GroupDocs.Annotation 25.4.0 for .NET
लेखक: GroupDocs

संबंधित ट्यूटोरियल