IronPDF 사용하여 C#에서 PDF를 압축하는 방법
IronPDF는 C#의 CompressAndSaveAs 메서드를 통해 PDF를 압축하며, 포함된 이미지를 다시 인코딩하고 선택적으로 PDF 구조 트리를 제거하여 한 번의 호출로 파일 크기를 줄입니다. 이미지는 기본적으로 JPEG로 다시 인코딩되며, 선택 시 1비트 CCITT 그룹 4로 인코딩됩니다. 동반하는 CompressPdfToBytes 및 CompressPdfToStream 메서드는 메모리에서 압축을 수행합니다.
이미지는 보통 PDF 크기의 대부분을 차지하고 있으며 테이블이 많은 문서는 추가 무게를 더하는 구조 트리를 가지고 있습니다. IronPDF는 둘 다 겨냥하기 때문에 디스크에서 로드한 PDF나 메모리 스트림에서 유지된 PDF에 동일한 호출이 작동합니다.
빠른 시작: IronPDF 로 PDF 파일 압축하기PDF를 PdfDocument.FromFile으로 로드하고, CompressAndSaveAs를 호출하여 이미지의 인코딩을 변경하고, 축소된 버전을 한 단계로 작성합니다. 두 번째 인수는 JPEG 품질입니다.
-
1IronPDF를 NuGet Package Manager로 설치하십시오
-
2다음 코드 조각을 복사하여 실행하세요.
PdfDocument.FromFile("input.pdf").CompressAndSaveAs("compressed.pdf", 40);PdfDocument.FromFile("input.pdf").CompressAndSaveAs("compressed.pdf", 40)PdfDocument.FromFile("input.pdf").CompressAndSaveAs("compressed.pdf", 40) -
3실제 운영 환경에서 테스트할 수 있도록 배포하세요.
오늘 프로젝트에서 IronPDF 사용을 시작해보세요 무료 체험
최소 워크플로우 (3단계)
- NuGet에서 PDF 압축을 위한 C# 라이브러리 다운로드
- 기존 PDF 파일을 가져오거나 새 PDF 파일을 생성합니다.
CompressAndSaveAs(outputPath, quality, removeStructureTree)를 호출하여 이미지를 압축하고 선택적으로 구조 트리를 제거하며 결과를 저장하십시오.
CompressImages, CompressStructTree, 및 Compress(CompressionOptions)와 같은 압축을 위한 이전 메서드는 더 이상 사용되지 않음.PDF 파일에서 이미지를 압축하는 방법은 무엇인가요?
JPEG quality 값을 두 번째 인수로 CompressAndSaveAs에 전달하면 IronPDF는 모든 포함된 이미지를 해당 품질로 다시 인코딩합니다. 값은 0(최대 압축)에서 100(최소 손실)까지 있으며, 내부 엔진이 각 값을 출력에 어떻게 매핑할지 결정합니다. 문서에 임베디드 이미지가 포함될 때 사용할 수 있는 방법입니다.
대략적인 가이드:
- 90 이상: 높은 품질
- 80에서 90: 중간 품질
- 70에서 80: 낮은 품질
더 낮은 숫자는 더 강하게 압축하지만 눈에 보이는 아티팩트를 일으킬 수 있으며 얼마나 많은 선명도가 떨어질지는 소스 이미지에 달려 있으므로 몇 가지 설정을 자신의 콘텐츠와 비교하여 원하는 균형을 찾아보세요.
입력
using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");
// Quality 40 re-encodes every embedded image as a low-quality JPEG, which is
// where most of the file-size saving comes from in image-heavy PDFs
pdf.CompressAndSaveAs("compressed.pdf", 40);using IronPdf;
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");
// Quality 40 re-encodes every embedded image as a low-quality JPEG, which is
// where most of the file-size saving comes from in image-heavy PDFs
pdf.CompressAndSaveAs("compressed.pdf", 40);Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page")
' Quality 40 re-encodes every embedded image as a low-quality JPEG, which is
' where most of the file-size saving comes from in image-heavy PDFs
pdf.CompressAndSaveAs("compressed.pdf", 40)Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page")
' Quality 40 re-encodes every embedded image as a low-quality JPEG, which is
' where most of the file-size saving comes from in image-heavy PDFs
pdf.CompressAndSaveAs("compressed.pdf", 40)산출
이미지 압축을 통해 어떤 결과를 기대할 수 있을까요?
39.24%로 Wikipedia 렌더에서 감소됨.

PDF 트리 구조를 압축하는 방법은 무엇인가요?
Chrome 엔진이 PDF에서 작성한 트리 구조를 제거하려면 removeStructureTree: true를 세 번째 인수로 CompressAndSaveAs에 전달하십시오. 저장은 광범위한 테이블 데이터를 가진 Chrome 엔진 PDF에서 가장 큽니다. 어떤 렌더링 엔진은 제거할 수 있는 구조를 생성하지 않습니다.
트리 제거는 텍스트 강조 및 선택을 약화시킬 수 있으므로 나중에 읽기가 결과에서 텍스트와 이미지를 추출해야 하는 경우 크기 증가에 대해 이를 고려하십시오.
트리 구조 제거가 적용된 CompressAndSaveAs를 테스트하려면 이 표 데이터가 있는 PDF를 사용하세요.
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("table.pdf");
// Pass null quality to skip image compression and true to drop the structure
// tree, which is the bulk of the size in table-heavy Chrome-rendered PDFs
pdf.CompressAndSaveAs("compressedTable.pdf", null, true);using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("table.pdf");
// Pass null quality to skip image compression and true to drop the structure
// tree, which is the bulk of the size in table-heavy Chrome-rendered PDFs
pdf.CompressAndSaveAs("compressedTable.pdf", null, true);Imports IronPdf
Dim pdf As PdfDocument = PdfDocument.FromFile("table.pdf")
' Pass nothing as quality to skip image compression and True to drop the structure
' tree, which is the bulk of the size in table-heavy Chrome-rendered PDFs
pdf.CompressAndSaveAs("compressedTable.pdf", Nothing, True)Imports IronPdf
Dim pdf As PdfDocument = PdfDocument.FromFile("table.pdf")
' Pass nothing as quality to skip image compression and True to drop the structure
' tree, which is the bulk of the size in table-heavy Chrome-rendered PDFs
pdf.CompressAndSaveAs("compressedTable.pdf", Nothing, True)트리 구조 압축을 통해 파일 크기를 얼마나 줄일 수 있을까요?
67.90%로 감소됨. 표 PDF가 커짐에 따라 수치가 상승합니다.

두 가지 압축 방법을 동시에 적용하려면 어떻게 해야 할까요?
quality 값을 제공하고 같은 CompressAndSaveAs 호출에서 removeStructureTree을 true로 설정하여 두 가지 부피의 원천을 한 번에 줄이십시오. 이 조합은 차트가 있는 보고서나 임베디드 테이블이 있는 송장과 같은 이미지와 구조화된 데이터를 혼합한 문서에서 역할을 다합니다.
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Shrink both sources of bloat in one pass: re-encode images at quality 80
// and strip the structure tree (true) for the largest size reduction
pdf.CompressAndSaveAs("compressed.pdf", 80, true);using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Shrink both sources of bloat in one pass: re-encode images at quality 80
// and strip the structure tree (true) for the largest size reduction
pdf.CompressAndSaveAs("compressed.pdf", 80, true);Imports IronPdf
Dim pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Shrink both sources of bloat in one pass: re-encode images at quality 80
' and strip the structure tree (true) for the largest size reduction
pdf.CompressAndSaveAs("compressed.pdf", 80, True)Imports IronPdf
Dim pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Shrink both sources of bloat in one pass: re-encode images at quality 80
' and strip the structure tree (true) for the largest size reduction
pdf.CompressAndSaveAs("compressed.pdf", 80, True)CompressAndSaveAs가 허용하는 매개변수는 무엇입니까?
outputPath(문자열): 압축된 PDF가 작성될 파일 경로입니다.quality(정수?, 0에서 100): 각 포함된 이미지에 적용할 JPEG 품질입니다. 낮은 값은 더 작은 파일을 만듭니다.null을 전달하여 이미지 압축을 완전히 건너뜁니다.removeStructureTree(불리언, 기본값false):true일 때, PDF 구조 트리를 제거하여 파일 크기를 더 줄여줍니다. 표가 포함된 HTML로 생성된 PDF에 가장 효과적입니다.
사용 사례에 맞게 조정하세요. 보관용 복사본은 종종 크기보다 품질을 선호하고 웹 배포에서는 더 작은 파일이 유리합니다. 같은 절충안은 이미지 충실도가 우선일 수 있는 PDF/A 호환 문서를 압축할 때도 적용됩니다.
압축에 대한 세부 제어를 어떻게 얻습니까?
대부분의 문서에는 인수가 두 개인 것이 충분하지만 이미지가 많은 아카이브와 엄격한 크기 예산은 때때로 더 많은 제어가 필요합니다. AdvancedCompressionOptions 객체를 CompressAndSaveAs에 전달하여 이미지를 DPI 다운샘플링, JPEG 재인코딩 품질, 흑백 스캔을 위한 비톤 인코딩 및 zlib 압축 수준을 포함하는 압축 파이프라인을 조정합니다. 단순한 CompressAndSaveAs(outputPath, quality, removeStructureTree) 오버로드는 여전히 변경되지 않은 상태로 작동하며 이전과 같은 출력을 생성합니다.
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("input.pdf");
// Web or email: strong size reduction
pdf.CompressAndSaveAs("compressed.pdf", new AdvancedCompressionOptions
{
JpegQuality = 70,
TargetImageDpi = 150,
RemoveStructureTree = true
});
// Print quality: minimal quality loss
pdf.CompressAndSaveAs("print.pdf", new AdvancedCompressionOptions
{
JpegQuality = 90,
TargetImageDpi = 300
});using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("input.pdf");
// Web or email: strong size reduction
pdf.CompressAndSaveAs("compressed.pdf", new AdvancedCompressionOptions
{
JpegQuality = 70,
TargetImageDpi = 150,
RemoveStructureTree = true
});
// Print quality: minimal quality loss
pdf.CompressAndSaveAs("print.pdf", new AdvancedCompressionOptions
{
JpegQuality = 90,
TargetImageDpi = 300
});Imports IronPdf
Dim pdf As PdfDocument = PdfDocument.FromFile("input.pdf")
' Web or email: strong size reduction
pdf.CompressAndSaveAs("compressed.pdf", New AdvancedCompressionOptions With {
.JpegQuality = 70,
.TargetImageDpi = 150,
.RemoveStructureTree = True
})
' Print quality: minimal quality loss
pdf.CompressAndSaveAs("print.pdf", New AdvancedCompressionOptions With {
.JpegQuality = 90,
.TargetImageDpi = 300
})Imports IronPdf
Dim pdf As PdfDocument = PdfDocument.FromFile("input.pdf")
' Web or email: strong size reduction
pdf.CompressAndSaveAs("compressed.pdf", New AdvancedCompressionOptions With {
.JpegQuality = 70,
.TargetImageDpi = 150,
.RemoveStructureTree = True
})
' Print quality: minimal quality loss
pdf.CompressAndSaveAs("print.pdf", New AdvancedCompressionOptions With {
.JpegQuality = 90,
.TargetImageDpi = 300
})컬러 및 혼합 문서에서 절대적인 차이를 만드는 두 가지 속성은 JpegQuality와 TargetImageDpi입니다:
JpegQuality(정수?, 1~100, 기본null): 이 JPEG 품질로 이미지를 다시 인코딩합니다. 이미지 재인코딩을 완전히 건너뛰려면null로 남겨두세요.TargetImageDpi(정수?, 기본150): 재인코딩 전에 실제 DPI가 이 값을 초과하는 이미지를 다운샘플링합니다. 다운샘플링을 비활성화하고 원본 해상도를 유지하려면null또는0로 설정하십시오.
권장 JpegQuality 값 (설정된 경우에만 적용됨):
| 값 | 사용 사례 |
|---|---|
null (기본값) | 이미지 재인코딩 없음 |
95 | 아카이브, 최소한의 인공물 |
85 | 고품질 |
70 | 일반 용도로 적합한 균형 |
50 | 웹 또는 이메일, 가시적인 인공물이 있는 작은 파일 |
권장 TargetImageDpi 값 (손실):
| 값 | 사용 사례 |
|---|---|
300 | 인쇄 품질, 일반 거리에서 눈에 볼 수 없는 무손실 |
200 | 고해상도 및 레티나 화면에서 선명합니다 |
150 (기본값) | 화면 및 이메일에 가장 적합한 크기 및 품질 균형 |
96 | 공격적, 부드러운 텍스트지만 여전히 읽을 수 있음 |
null 또는 0 | 비활성화되며 원래의 해상도를 보존합니다 |
TargetImageDpi 다운샘플링은 손실적입니다: 이미지가 다운샘플링된 이상, 원본 해상도로 복원할 수 없습니다. 해상도 감소 또는 품질 전용 재인코딩 중 하나를 선택하고 TargetImageDpi을 적절하게 설정하십시오.흑백 스캔을 어떻게 압축합니까?
IronPDF 2026.10.1+는 비톤 압축을 도입하였습니다: AdvancedCompressionOptions은 스캔된 텍스트, 팩스 및 선화 도형을 1비트 CCITT 그룹 4로 JPEG 대신 다시 인코딩할 수 있습니다.
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("scanned-document.pdf");
// Scanned text and line art: 1-bit CCITT Group 4
pdf.CompressAndSaveAs("scan-compressed.pdf", new AdvancedCompressionOptions
{
BitonalMode = BitonalCompressionMode.Force
});
// Print-quality scan: threshold at 300 DPI instead of the 150 DPI fallback
pdf.CompressAndSaveAs("scan-300dpi.pdf", new AdvancedCompressionOptions
{
BitonalMode = BitonalCompressionMode.Force,
BitonalResolutionDpi = 300
});using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("scanned-document.pdf");
// Scanned text and line art: 1-bit CCITT Group 4
pdf.CompressAndSaveAs("scan-compressed.pdf", new AdvancedCompressionOptions
{
BitonalMode = BitonalCompressionMode.Force
});
// Print-quality scan: threshold at 300 DPI instead of the 150 DPI fallback
pdf.CompressAndSaveAs("scan-300dpi.pdf", new AdvancedCompressionOptions
{
BitonalMode = BitonalCompressionMode.Force,
BitonalResolutionDpi = 300
});Imports IronPdf
Dim pdf As PdfDocument = PdfDocument.FromFile("scanned-document.pdf")
' Scanned text and line art: 1-bit CCITT Group 4
pdf.CompressAndSaveAs("scan-compressed.pdf", New AdvancedCompressionOptions With {
.BitonalMode = BitonalCompressionMode.Force
})
' Print-quality scan: threshold at 300 DPI instead of the 150 DPI fallback
pdf.CompressAndSaveAs("scan-300dpi.pdf", New AdvancedCompressionOptions With {
.BitonalMode = BitonalCompressionMode.Force,
.BitonalResolutionDpi = 300
})Imports IronPdf
Dim pdf As PdfDocument = PdfDocument.FromFile("scanned-document.pdf")
' Scanned text and line art: 1-bit CCITT Group 4
pdf.CompressAndSaveAs("scan-compressed.pdf", New AdvancedCompressionOptions With {
.BitonalMode = BitonalCompressionMode.Force
})
' Print-quality scan: threshold at 300 DPI instead of the 150 DPI fallback
pdf.CompressAndSaveAs("scan-300dpi.pdf", New AdvancedCompressionOptions With {
.BitonalMode = BitonalCompressionMode.Force,
.BitonalResolutionDpi = 300
})| 재산 | 유형 | Default | 목적 |
|---|---|---|---|
BitonalMode | BitonalCompressionMode | Off | Force는 적격 이미지를 모두 1비트 CCITT 그룹 4로 변환합니다. Off는 JPEG 파이프라인을 유지합니다. |
BitonalResolutionDpi | int? | null | 임계값 설정 전 목표 DPI. null 또는 0는 TargetImageDpi로 대체됩니다. |
BitonalThreshold | int? | null | 1에서 255까지의 휘도 컷오프. null 는 Otsu의 방법을 사용하여 이미지마다 계산됩니다. |
TargetImageDpi는 기본적으로 150입니다, 그러므로 BitonalMode = Force 만으로도 임계값 설정 전 300 DPI 스캔을 150 DPI로 다운샘플링합니다. 스캔의 DPI에 BitonalResolutionDpi을 설정하거나 원래 해상도를 유지하려면 TargetImageDpi을 null에 설정하세요.고정된 임계값이 필요하지 않으면 BitonalThreshold를 null로 유지하십시오: 자동 임계값은 노출이 다른 일괄 스캔에 적합합니다. 값이 1에서 255 범위 밖에 있거나 0인 경우 자동 임계값이 적용되며 예외가 발생하지 않습니다.
비톤 압축을 끄는 것이 언제 적절합니까?
임계처리는 모든 픽셀을 검정 또는 흰색으로 변환합니다: 색상 및 연속 톤 세부사항은 버려집니다. 컬러 및 사진 PDF의 경우 BitonalMode을 Off으로 유지하십시오.
세 가지 경우는 변환 대신 건너뜁니다:
- 비톤 결과가 더 작지 않은 경우: 해당 이미지는 JPEG 경로에 유지됩니다. 이미지 별로 결정됩니다.
- 이미지가 마스크를 포함하는 경우: 부드러운 마스크나 스텐실 또는 색상 키 마스크는 JPEG 인코딩을 유지합니다. 마스크는 버려지거나 평면화되지 않습니다.
- 이미지가 이미 1비트인 경우: 기존의 CCITT 또는 JBIG2 스캔은 비톤 압축이 켜져 있어도 그대로 남아 있으며
TargetImageDpi은 다운샘플링하지 않습니다.
AdvancedCompressionOptions에 있습니다, 그리고 CompressAndSaveAs 오버로드만이 이를 허용합니다. 메모리에서의 방법은 CCITT 그룹 4 출력을 생성할 수 없습니다.PDF 파일을 디스크에 저장하지 않고 압축하는 방법은 무엇인가요?
API 응답, 클라우드 기능 및 이메일 첨부 파일은 거의 디스크에 압축된 PDF가 필요하지 않습니다. CompressPdfToBytes는 결과를 바이트 배열로 반환하므로, 당신은 그 바이트를 다음에 어디로 보낼지 결정할 수 있습니다.
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Return the compressed PDF as bytes so it can go straight into an HTTP
// response, a database varbinary column, or a queue message with no temp file
byte[] compressedBytes = pdf.CompressPdfToBytes();
File.WriteAllBytes("compressed.pdf", compressedBytes);using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Return the compressed PDF as bytes so it can go straight into an HTTP
// response, a database varbinary column, or a queue message with no temp file
byte[] compressedBytes = pdf.CompressPdfToBytes();
File.WriteAllBytes("compressed.pdf", compressedBytes);Imports IronPdf
Dim pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Return the compressed PDF as bytes so it can go straight into an HTTP
' response, a database varbinary column, or a queue message with no temp file
Dim compressedBytes As Byte() = pdf.CompressPdfToBytes()
File.WriteAllBytes("compressed.pdf", compressedBytes)Imports IronPdf
Dim pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Return the compressed PDF as bytes so it can go straight into an HTTP
' response, a database varbinary column, or a queue message with no temp file
Dim compressedBytes As Byte() = pdf.CompressPdfToBytes()
File.WriteAllBytes("compressed.pdf", compressedBytes)바이트 배열 대신 Stream가 필요하다면, CompressPdfToStream를 호출하고 목적지로 복사하십시오. 이것은 HTTP 응답 본문, 클라우드 저장소 업로드 또는 스트림 기반 워크플로에 출력 파이핑을 맞춥니다.
using IronPdf;
using System.IO;
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Stream output so the compressed bytes can be piped straight to an HTTP
// response or cloud upload without first buffering the whole file as byte[]
using Stream compressedStream = pdf.CompressPdfToStream();
// CompressPdfToStream returns a read-only Stream, so copy it to the destination
using FileStream fileStream = File.Create("compressed.pdf");
compressedStream.CopyTo(fileStream);using IronPdf;
using System.IO;
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// Stream output so the compressed bytes can be piped straight to an HTTP
// response or cloud upload without first buffering the whole file as byte[]
using Stream compressedStream = pdf.CompressPdfToStream();
// CompressPdfToStream returns a read-only Stream, so copy it to the destination
using FileStream fileStream = File.Create("compressed.pdf");
compressedStream.CopyTo(fileStream);Imports IronPdf
Imports System.IO
Dim pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Stream output so the compressed bytes can be piped straight to an HTTP
' response or cloud upload without first buffering the whole file as byte[]
Using compressedStream As Stream = pdf.CompressPdfToStream()
' CompressPdfToStream returns a read-only Stream, so copy it to the destination
Using fileStream As FileStream = File.Create("compressed.pdf")
compressedStream.CopyTo(fileStream)
End Using
End UsingImports IronPdf
Imports System.IO
Dim pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' Stream output so the compressed bytes can be piped straight to an HTTP
' response or cloud upload without first buffering the whole file as byte[]
Using compressedStream As Stream = pdf.CompressPdfToStream()
' CompressPdfToStream returns a read-only Stream, so copy it to the destination
Using fileStream As FileStream = File.Create("compressed.pdf")
compressedStream.CopyTo(fileStream)
End Using
End Using어떤 CompressionMode 옵션이 사용 가능합니까?
CompressPdfToBytes와 CompressPdfToStream는 모두 CompressionMode이라는 선택적 인수를 지니며, 작업이 어떻게 수행될지를 결정합니다. 배포 대상은 디스크 접근을 허용하는지 여부가 다르고, 모드는 적절한 거래를 고르게 합니다:
| 모드 | 디스크 접근 | 이미지 재샘플링 | 출력 크기 |
|---|---|---|---|
Automatic (기본값) | 디스크를 시도, 메모리로 전환 | 디스크가 가능한 경우 | 허용되는 곳에서 가장 작음 |
FastMemory | None | 아니요 | 더 크다 |
HighQuality | 임시 디렉토리 필요 | 예 | 가장 작음 |
Automatic는 먼저 HighQuality를 시도하고 임시 디렉토리가 제한될 경우 FastMemory로 떨어집니다. 아래 예시는 가장 작은 출력을 위해 HighQuality를 강제하며, 런타임시에 시스템 임시 디렉토리에 대한 쓰기 접근이 필요합니다.
using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// HighQuality resamples images using the system temp directory, so it produces
// the smallest output but needs write access to that directory at runtime
byte[] compressedBytes = pdf.CompressPdfToBytes(50, false, CompressionMode.HighQuality);
File.WriteAllBytes("compressed.pdf", compressedBytes);using IronPdf;
PdfDocument pdf = PdfDocument.FromFile("sample.pdf");
// HighQuality resamples images using the system temp directory, so it produces
// the smallest output but needs write access to that directory at runtime
byte[] compressedBytes = pdf.CompressPdfToBytes(50, false, CompressionMode.HighQuality);
File.WriteAllBytes("compressed.pdf", compressedBytes);Imports IronPdf
Dim pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' HighQuality resamples images using the system temp directory, so it produces
' the smallest output but needs write access to that directory at runtime
Dim compressedBytes As Byte() = pdf.CompressPdfToBytes(50, False, CompressionMode.HighQuality)
File.WriteAllBytes("compressed.pdf", compressedBytes)Imports IronPdf
Dim pdf As PdfDocument = PdfDocument.FromFile("sample.pdf")
' HighQuality resamples images using the system temp directory, so it produces
' the smallest output but needs write access to that directory at runtime
Dim compressedBytes As Byte() = pdf.CompressPdfToBytes(50, False, CompressionMode.HighQuality)
File.WriteAllBytes("compressed.pdf", compressedBytes)산출
CompressPdfToBytes와 CompressPdfToStream는 이제 모든 IronPDF 플랫폼에서 사용 가능하며, Java, Node.js, Python을 포함합니다.결론
이제 사진을 다시 인코딩하고 구조 트리를 제거하는 CompressAndSaveAs 메서드 하나와, 선택한 CompressionMode에서 메모리 내부에서 같은 작업을 수행하는 CompressPdfToBytes와 CompressPdfToStream가 있습니다. 다음 자연스러운 단계는 이 축소된 페이지를 PDF 래스터화를 사용하여 썸네일로 변환하는 것입니다.
자주 묻는 질문
IronPDF를 사용하여 C#에서 PDF를 어떻게 압축할 수 있나요?
IronPDF를 사용하여 C#에서 CompressAndSaveAs 메서드를 통해 PDF를 압축할 수 있습니다. 이 메서드는 JPEG로 이미지 내장을 다시 인코딩하고 경우에 따라 PDF 구조 트리를 제거하여 파일 크기를 줄입니다.
IronPDF가 메모리 내 PDF 압축을 위해 제공하는 방법은 무엇인가요?
IronPDF는 메모리에서 PDF를 압축하기 위한 CompressPdfToBytes 및 CompressPdfToStream 메서드를 제공합니다. 이러한 메서드는 디스크에 저장할 필요 없이 PDF를 처리할 수 있게 해줍니다.
IronPDF는 PDF의 이미지 압축을 어떻게 처리하나요?
IronPDF는 PDF의 이미지를 지정된 품질의 JPEG로 다시 인코딩하여 압축합니다. 압축 수준을 조정하려면 JPEG quality 값을 CompressAndSaveAs 메서드에 전달할 수 있습니다.
IronPDF에서 `removeStructureTree` 매개변수는 무엇을 하나요?
IronPDF의 CompressAndSaveAs 메서드에서 removeStructureTree 매개변수를 사용하여 PDF의 구조 트리를 제거할 수 있습니다. 특히 테이블이 많은 문서의 경우 파일 크기를 크게 줄일 수 있습니다.
IronPDF가 디스크를 건드리지 않고도 PDF를 압축할 수 있나요?
네, IronPDF는 CompressPdfToBytes 및 CompressPdfToStream 메서드를 사용하여 디스크에 쓰지 않고 PDF를 압축할 수 있습니다. 이러한 메서드는 압축된 PDF를 바이트 배열 또는 스트림 형태로 반환하여 클라우드 또는 API 워크플로에 적합합니다.
IronPDF에서 JPEG 품질이 PDF 크기에 미치는 영향은 무엇인가요?
IronPDF에서 낮은 JPEG 품질 값은 압축을 증가시켜 PDF 크기를 작게 하지만, 가시적인 아티팩트를 유발할 수 있습니다. 다양한 수준을 테스트하여 크기와 품질 사이의 적절한 균형을 찾을 수 있습니다.
IronPDF에서 이미지 및 구조 트리 압축을 함께 사용하는 방법은 무엇인가요?
JPEG quality를 전달하고 removeStructureTree를 true로 설정하여 IronPDF에서 이미지 및 구조 트리 압축을 모두 결합할 수 있습니다. 이 방법은 이미지와 구조화된 데이터가 모두 포함된 문서를 대상으로 합니다.
`CompressionMode`가 IronPDF의 PDF 압축에 미치는 영향은 무엇인가요?
IronPDF의 CompressionMode 옵션을 사용하여 디스크 접근 및 출력 크기에 따라 압축을 조정할 수 있습니다. Automatic, FastMemory 및 HighQuality 모드를 포함하며, 각각 다른 수준의 디스크 사용과 압축 품질을 제공합니다.
IronPDF를 사용하여 기대할 수 있는 파일 크기 감소는 어느 정도인가요?
IronPDF에서의 파일 크기 감소는 콘텐츠에 따라 다릅니다. 예를 들어, 위키피디아 렌더를 압축하면 약 39.24%의 크기 감소가 가능하며, 표가 많은 PDF에서 구조 트리를 제거하면 67.90%의 감소를 이끌어낼 수 있습니다.
IronPDF에서 세밀한 PDF 압축 제어를 달성하는 방법은 무엇인가요?
세분화된 제어를 위해 IronPDF는 AdvancedCompressionOptions 객체를 CompressAndSaveAs 메서드에 전달하여 JPEG 품질, 이미지 DPI 다운샘플링 및 zlib 압축 수준을 조정할 수 있도록 합니다.
IronPDF에서 흑백 스캔을 어떻게 압축하나요?
AdvancedCompressionOptions 객체에서 BitonalMode를 BitonalCompressionMode.Force로 설정하고 CompressAndSaveAs에 전달하십시오. IronPDF는 적격한 각 이미지를 1비트로 임계값을 적용하고 CCITT Group 4로 인코딩하여 결과가 작을 때만 유지합니다. 기본적으로 꺼져 있으며 컬러 또는 사진 콘텐츠가 아닌 텍스트 스캔, 팩스 및 선화에 사용하도록 설계되었습니다.
왜 내 스캔이 BitonalMode를 Force로 설정한 후 더 부드러워 보이나요?
BitonalResolutionDpi는 기본적으로 null이며, 이는 TargetImageDpi로 대체되며 TargetImageDpi는 기본적으로 150입니다. 따라서 BitonalMode만 설정하면 300 DPI 스캔이 임계값 적용 전에 150 DPI로 다운샘플링됩니다. 임계값 적용 시 원래 해상도로 설정하려면 BitonalResolutionDpi를 명시적으로 설정하거나 TargetImageDpi를 null로 설정하십시오.
IronPDF에서 BitonalThreshold는 무엇을 하나요?
BitonalThreshold는 픽셀이 검은색 또는 흰색이 될지 여부를 결정하는 1에서 255까지의 밝기 임계값입니다. 기본값인 null로 두면 IronPDF가 Otsu의 방법을 사용하여 각 이미지에 임계값을 계산합니다. 이는 노출이 다른 스캔을 처리합니다. 0이거나 1에서 255 사이가 아닌 값은 자동 임계값으로 되돌아갑니다.
CompressPdfToBytes 또는 CompressPdfToStream 메서드와 함께 이중 화소 압축을 사용할 수 있나요?
아니요. 이중 화소 압축은 AdvancedCompressionOptions 객체를 받는 CompressAndSaveAs 오버로드를 통해서만 사용할 수 있습니다. CompressPdfToBytes와 CompressPdfToStream은 대신 JPEG 품질 값을 받으므로 메모리 내 경로는 CCITT Group 4 출력을 만들 수 없습니다.
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.