Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.PDF for .NET는 .NET 애플리케이션에서 PDF 파일의 페이지 속성을 읽고 설정할 수 있게 해줍니다. 이 섹션에서는 PDF 파일의 페이지 수를 가져오고, 색상과 같은 PDF 페이지 속성에 대한 정보를 가져오고, 페이지 속성을 설정하는 방법을 보여줍니다. 제공된 예제는 C#로 되어 있지만 VB.NET과 같은 다른 .NET 언어를 사용하여 동일한 작업을 수행할 수 있습니다.
다음 코드 조각은 Aspose.PDF.Drawing 라이브러리와도 작동합니다.
문서 작업을 할 때, 문서에 몇 페이지가 포함되어 있는지 알고 싶어하는 경우가 많습니다. Aspose.PDF를 사용하면 두 줄의 코드로 해결할 수 있습니다.
PDF 파일의 페이지 수를 가져오려면:
다음 코드 조각은 PDF 파일의 페이지 수를 가져오는 방법을 보여줍니다.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetNumberOfPagesInAPdfFile()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "GetNumberofPages.pdf"))
{
// Get page count
System.Console.WriteLine("Page Count : {0}", document.Pages.Count);
}
}
때때로 우리는 PDF 파일을 즉석에서 생성하며, PDF 파일 생성 중에 시스템이나 스트림에 파일을 저장하지 않고 페이지 수를 가져와야 하는 요구 사항(목차 생성 등)이 발생할 수 있습니다. 이러한 요구 사항을 충족하기 위해 Document 클래스에 ProcessParagraphs 메서드가 도입되었습니다. 문서를 저장하지 않고 페이지 수를 가져오는 단계를 보여주는 다음 코드 조각을 살펴보십시오.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetPageCountWithoutSavingTheDocument()
{
// Create PDF document
using (var document = new Aspose.Pdf.Document())
{
// Add page
var page = document.Pages.Add();
// Create loop instance
for (var i = 0; i < 300; i++)
{
// Add TextFragment to paragraphs collection of page object
page.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Pages count test"));
}
// Process the paragraphs in PDF file to get accurate page count
document.ProcessParagraphs();
// Print number of pages in document
Console.WriteLine("Number of pages in document = " + document.Pages.Count);
}
}
PDF 파일의 각 페이지에는 너비, 높이, 블리드 박스, 크롭 박스 및 트림 박스와 같은 여러 속성이 있습니다. Aspose.PDF를 사용하면 이러한 속성에 접근할 수 있습니다.
자세한 내용은 이 페이지를 방문하십시오.
Page 클래스는 특정 PDF 페이지와 관련된 모든 속성을 제공합니다. PDF 파일의 모든 페이지는 Document 객체의 PageCollection 컬렉션에 포함되어 있습니다.
거기에서 인덱스를 사용하여 개별 Page 객체에 접근하거나 foreach 루프를 사용하여 컬렉션을 반복하여 모든 페이지를 가져올 수 있습니다. 개별 페이지에 접근하면 해당 속성을 가져올 수 있습니다. 다음 코드 조각은 페이지 속성을 가져오는 방법을 보여줍니다.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AccessingPageProperties()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "GetProperties.pdf"))
{
// Get page collection
var pageCollection = document.Pages;
// Get particular page
var pdfPage = pageCollection[1];
// Get page properties
System.Console.WriteLine("ArtBox : Height={0},Width={1},LLX={2},LLY={3},URX={4},URY={5}", pdfPage.ArtBox.Height, pdfPage.ArtBox.Width, pdfPage.ArtBox.LLX,
pdfPage.ArtBox.LLY, pdfPage.ArtBox.URX, pdfPage.ArtBox.URY);
System.Console.WriteLine("BleedBox : Height={0},Width={1},LLX={2},LLY={3},URX={4},URY={5}", pdfPage.BleedBox.Height, pdfPage.BleedBox.Width, pdfPage.BleedBox.LLX,
pdfPage.BleedBox.LLY, pdfPage.BleedBox.URX, pdfPage.BleedBox.URY);
System.Console.WriteLine("CropBox : Height={0},Width={1},LLX={2},LLY={3},URX={4},URY={5}", pdfPage.CropBox.Height, pdfPage.CropBox.Width, pdfPage.CropBox.LLX,
pdfPage.CropBox.LLY, pdfPage.CropBox.URX, pdfPage.CropBox.URY);
System.Console.WriteLine("MediaBox : Height={0},Width={1},LLX={2},LLY={3},URX={4},URY={5}", pdfPage.MediaBox.Height, pdfPage.MediaBox.Width, pdfPage.MediaBox.LLX,
pdfPage.MediaBox.LLY, pdfPage.MediaBox.URX, pdfPage.MediaBox.URY);
System.Console.WriteLine("TrimBox : Height={0},Width={1},LLX={2},LLY={3},URX={4},URY={5}", pdfPage.TrimBox.Height, pdfPage.TrimBox.Width, pdfPage.TrimBox.LLX,
pdfPage.TrimBox.LLY, pdfPage.TrimBox.URX, pdfPage.TrimBox.URY);
System.Console.WriteLine("Rect : Height={0},Width={1},LLX={2},LLY={3},URX={4},URY={5}", pdfPage.Rect.Height, pdfPage.Rect.Width, pdfPage.Rect.LLX, pdfPage.Rect.LLY,
pdfPage.Rect.URX, pdfPage.Rect.URY);
System.Console.WriteLine("Page Number : {0}", pdfPage.Number);
System.Console.WriteLine("Rotate : {0}", pdfPage.Rotate);
}
}
Aspose.PDF를 사용하면 PDF를 개별 페이지로 분할하고 이를 PDF 파일로 저장할 수 있습니다. PDF 파일에서 특정 페이지를 가져와 새 PDF로 저장하는 것은 매우 유사한 작업입니다: 원본 문서를 열고, 페이지에 접근하고, 새 문서를 만들고, 페이지를 추가합니다.
Document 객체의 PageCollection은 PDF 파일의 페이지를 보유합니다. 이 컬렉션에서 특정 페이지를 가져오려면:
다음 코드 조각은 PDF 파일에서 특정 페이지를 가져와 새 파일로 저장하는 방법을 보여줍니다.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void GetAParticularPageOfThePdfFile()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Get particular page
var pdfPage = document.Pages[2];
// Save the page as PDF file
using (var newDocument = new Aspose.Pdf.Document())
{
newDocument.Pages.Add(pdfPage);
// Save PDF document
newDocument.Save(dataDir + "GetParticularPage_out.pdf");
}
}
}
Page 클래스는 PDF 문서의 특정 페이지와 관련된 속성을 제공하며, 페이지가 사용하는 색상 유형 - RGB, 흑백, 그레이스케일 또는 정의되지 않음 - 을 포함합니다.
PDF 파일의 모든 페이지는 PageCollection 컬렉션에 포함되어 있습니다. ColorType 속성은 페이지의 요소 색상을 지정합니다. 특정 PDF 페이지의 색상 정보를 가져오거나 결정하려면 Page 객체의 ColorType 속성을 사용하십시오.
다음 코드 조각은 PDF 파일의 개별 페이지를 반복하여 색상 정보를 가져오는 방법을 보여줍니다.
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void DeterminePageColor()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open PDF document
using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
{
// Iterate through all the page of PDF file
for (var pageCount = 1; pageCount <= document.Pages.Count; pageCount++)
{
// Get the color type information for particular PDF page
Aspose.Pdf.ColorType pageColorType = document.Pages[pageCount].ColorType;
switch (pageColorType)
{
case Aspose.Pdf.ColorType.BlackAndWhite:
Console.WriteLine("Page # -" + pageCount + " is Black and white..");
break;
case Aspose.Pdf.ColorType.Grayscale:
Console.WriteLine("Page # -" + pageCount + " is Gray Scale...");
break;
case Aspose.Pdf.ColorType.Rgb:
Console.WriteLine("Page # -" + pageCount + " is RGB..", pageCount);
break;
case Aspose.Pdf.ColorType.Undefined:
Console.WriteLine("Page # -" + pageCount + " Color is undefined..");
break;
}
}
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.