C#를 사용하여 PDF 페이지 크기 변경
PDF 페이지 크기 변경
Aspose.PDF for .NET을 사용하면 .NET 애플리케이션에서 간단한 코드 줄로 PDF 페이지 크기를 변경할 수 있습니다. 이 주제는 기존 PDF 파일의 페이지 치수(크기)를 업데이트/변경하는 방법을 설명합니다.
다음 코드 스니펫은 Aspose.PDF.Drawing 라이브러리와 함께 작동합니다.
Page 클래스에는 페이지 크기를 설정할 수 있는 SetPageSize(…) 메소드가 포함되어 있습니다. 아래의 코드 스니펫은 몇 단계로 페이지 치수를 업데이트합니다:
- 소스 PDF 파일을 로드합니다.
- PageCollection 객체로 페이지를 가져옵니다.
- 주어진 페이지를 가져옵니다.
- SetPageSize(..) 메소드를 호출하여 치수를 업데이트합니다.
- Document 클래스의 Save(..) 메소드를 호출하여 업데이트된 페이지 치수로 PDF 파일을 생성합니다.
다음 코드 스니펫은 PDF 페이지 크기를 A4 크기로 변경하는 방법을 보여줍니다.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages(); | |
// Open document | |
Document pdfDocument = new Document(dataDir + "UpdateDimensions.pdf"); | |
// Get page collection | |
PageCollection pageCollection = pdfDocument.Pages; | |
// Get particular page | |
Page pdfPage = pageCollection[1]; | |
// Set the page size as A4 (11.7 x 8.3 in) and in Aspose.Pdf, 1 inch = 72 points | |
// So A4 dimensions in points will be (842.4, 597.6) | |
pdfPage.SetPageSize(597.6, 842.4); | |
dataDir = dataDir + "UpdateDimensions_out.pdf"; | |
// Save the updated document | |
pdfDocument.Save(dataDir); |
PDF 페이지 크기 가져오기
기존 PDF 파일의 PDF 페이지 크기를 읽을 수 있습니다. 다음 코드 샘플은 C#을 사용하여 PDF 페이지 크기를 읽는 방법을 보여줍니다.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages(); | |
// Open document | |
Document pdfDocument = new Document(dataDir + "UpdateDimensions.pdf"); | |
// Adds a blank page to pdf document | |
Page page = pdfDocument.Pages.Count > 0 ? pdfDocument.Pages[1] : pdfDocument.Pages.Add(); | |
// Get page height and width information | |
Console.WriteLine(page.GetPageRect(true).Width.ToString() + ":" + page.GetPageRect(true).Height); | |
// Rotate page at 90 degree angle | |
page.Rotate = Rotation.on90; | |
// Get page height and width information | |
Console.WriteLine(page.GetPageRect(true).Width.ToString() + ":" + page.GetPageRect(true).Height); |