푸터 콘텐츠로 바로가기
제품 비교

바이트 배열로부터 PDF 생성 C# iTextSharp (vs IronPDF)

Full Comparison

Looking for a detailed feature-by-feature breakdown? See how IronPDF stacks up against Itext on pricing, HTML support, and licensing.

View Full Comparison

현대 .NET 애플리케이션에서는 PDF 파일을 생성하고 관리하는 것이 일반적인 요구 사항입니다—리포트, 송장, 또는 디지털 기록을 생성할 때. 개발자들은 종종 이러한 작업을 위해 타사 PDF 라이브러리에 의존하며, .NET 생태계에서 가장 인기 있는 옵션 두 가지는 IronPDFiText 7 (iTextSharp의 후속작)입니다.

각 라이브러리는 다양한 사용 사례에 대한 강력한 도구 세트를 제공합니다. 그러나 C#에서 바이트 배열에서 PDF를 생성하는 데 적합한 것은 어느 것일까요? 이 기사에서는 .NET 개발자가 올바른 선택을 할 수 있도록 비교, 코드 예제 및 통찰력을 제공하여 모든 것을 분석합니다.

Enterprise급 애플리케이션을 구축하든 작은 내부 도구를 만들든 올바른 PDF 라이브러리를 선택하면 개발 시간을 절약하고 강력한 출력을 보장할 수 있습니다. 각 라이브러리가 제공하는 것을 탐색해 봅시다.

PDF 라이브러리 소개

PDF 라이브러리는 무엇에 사용되나요?

C#의 PDF 라이브러리는 개발자가 PDF 파일을 프로그래밍 방식으로 생성, 조작 및 읽을 수 있도록 합니다. 그들은 다음과 같은 다양한 사용 사례를 제공합니다:

  • 리포트 및 송장 내보내기
  • 웹 양식에서 동적 콘텐츠 생성
  • HTML 페이지 또는 템플릿을 PDF로 변환
  • 페이지 번호, 차트, 이미지 등과 같은 시각적 요소 추가
  • 문서 병합 또는 분할
  • PDF 디지털 서명

그리고 데이터 이동성과 PDF/A와 같은 표준 아카이빙 또는 접근성 요구에 대한 준수에 중요한 역할을 합니다.

iTextSharp와 IronPDF: 최고의 경쟁자

사용 가능한 .NET PDF 라이브러리 중 iTextSharpIronPDF는 각각 고유한 강점을 가진 선도적인 솔루션으로 부상했습니다:

  • iTextSharp는 Java의 iText를 기반으로 한 성숙한 오픈 소스 라이브러리로, 가파른 학습 곡선과 라이선스 주의사항을 동반하며 강력한 PDF 제어를 제공합니다.
  • IronPDF는 현대 상용 라이브러리로, 단순성, 속도 및 웹 통합에 초점을 맞추어 HTML 및 ASP.NET 보기를 직접 PDF 파일로 변환할 수 있습니다.

올바른 라이브러리 선택이 중요한 이유

두 가지 중에서 선택하는 것은 단순한 선호의 문제가 아니라 생산성, 유지 관리, 성능, 심지어는 법적 라이선스 준수에 영향을 미칩니다. 빠른 반응 시간, 빈번한 형식 변경, 또는 HTML 템플릿에서 PDF 렌더링을 요구하는 프로젝트는 빠른 개발로 이점을 가지며, Enterprise 수준의 애플리케이션은 표준 준수와 장기적인 유지 가능성을 우선시할 수 있습니다.

기능 비교

.NET용 iText 7 (iTextSharp의 후속작)

iText 7iTextSharp의 공식 후속작이며 완전히 새롭게 설계된 아키텍처를 제공합니다. 이는 법률, 금융, 정부와 같은 규제가 많은 산업에서 PDF를 생성, 편집, 검증하는 데 적합한 강력하고 확장 가능한 라이브러리입니다. iText 7 Suite에는 PDF/A, PDF/UA, 디지털 서명, 수정 및 양식 작성에 대한 지원이 포함됩니다.

아직 AGPL 라이선스 하에서 오픈 소스로 제공되며, 상용 프로젝트에 대한 상용 라이선스도 제공됩니다.

iText 7 주요 기능

  • iTextSharp의 오래된 구조를 대체하는 현대적인 API
  • 모듈형 지원: HTML to PDF, PDF/A, 양식, 블랙아웃, 디지털 서명
  • Enterprise 애플리케이션에 대한 높은 성능
  • PDF/A, 접근성, 컴플라이언스에 탁월

핵심 PDF 작업을 위해 itext7을 사용하고 html2pdf와 같은 선택적 추가 기능을 별도로 포함할 수 있습니다.

설치 (NuGet)

PDF 생성용 iText 7의 코어 패키지를 다운로드하려면:

Install-Package itext7

iText 7을 NuGet 패키지 관리자 콘솔을 통해 설치하기

iText 7은 솔루션 화면의 패키지 관리자를 통해서도 설치할 수 있습니다. 이 작업을 수행하려면 먼저 도구 드롭다운 메뉴로 가서 'NuGet 패키지 관리자 > 솔루션용 NuGet 패키지 관리'를 찾습니다.

Visual Studio의 도구 드롭다운 메뉴

그런 다음 간단히 iText 7을 검색하고 '설치'를 클릭하면 됩니다.

iText 7 NuGet 패키지 페이지

코드 예제: iText 7을 사용하여 바이트 배열에서 PDF 문서 생성

using System.IO;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.GeneratePdfWithIText7();
        // Save the PDF to a file
        File.WriteAllBytes("output.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] GeneratePdfWithIText7()
    {
        using (var ms = new MemoryStream())
        {
            var writer = new PdfWriter(ms);
            var pdf = new iText.Kernel.Pdf.PdfDocument(writer);
            var doc = new Document(pdf);

            doc.Add(new Paragraph("Hello from iText 7 for .NET!"));

            doc.Close(); // Always close the document to finalize content  
            return ms.ToArray();
        }
    }
}
using System.IO;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.GeneratePdfWithIText7();
        // Save the PDF to a file
        File.WriteAllBytes("output.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] GeneratePdfWithIText7()
    {
        using (var ms = new MemoryStream())
        {
            var writer = new PdfWriter(ms);
            var pdf = new iText.Kernel.Pdf.PdfDocument(writer);
            var doc = new Document(pdf);

            doc.Add(new Paragraph("Hello from iText 7 for .NET!"));

            doc.Close(); // Always close the document to finalize content  
            return ms.ToArray();
        }
    }
}
Imports System.IO
Imports iText.Kernel.Pdf
Imports iText.Layout
Imports iText.Layout.Element

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		Dim pdfGenerator As New PdfGenerator()
		Dim pdfBytes() As Byte = pdfGenerator.GeneratePdfWithIText7()
		' Save the PDF to a file
		File.WriteAllBytes("output.pdf", pdfBytes)
	End Sub
End Class

Friend Class PdfGenerator
	Public Function GeneratePdfWithIText7() As Byte()
		Using ms = New MemoryStream()
			Dim writer = New PdfWriter(ms)
			Dim pdf = New iText.Kernel.Pdf.PdfDocument(writer)
			Dim doc = New Document(pdf)

			doc.Add(New Paragraph("Hello from iText 7 for .NET!"))

			doc.Close() ' Always close the document to finalize content
			Return ms.ToArray()
		End Using
	End Function
End Class
$vbLabelText   $csharpLabel

출력 PDF 파일

iText 7 PDF 출력

설명

  • PdfWriterMemoryStream에 내용을 기록합니다.
  • PdfDocument는 PDF의 내부 구조를 관리합니다.
  • Document는 고급 콘텐츠(텍스트, 이미지, 테이블)를 추가하는 데 사용됩니다.
  • doc.Close()를 호출한 후, PDF 콘텐츠가 완전히 기록되며 바이트 배열로 반환할 준비가 됩니다.

이 예제는 iTextSharp에 비해 iText 7의 더 모듈화되고 읽기 쉬운 API를 보여줍니다. 그러나 pdfhtml을 포함하지 않으면 HTML/CSS 렌더링에 대한 기본 지원이 부족합니다.

iText 7의 장단점

장점:

  • 포괄적인 PDF 제어 iText 7은 테이블, 양식, 디지털 서명과 같은 PDF 요소에 대한 완전한 제어를 제공합니다. 이는 PDF/A 또는 PDF/UA와 같은 특정 PDF 표준을 요구하는 컴플라이언스가 많은 애플리케이션에 이상적입니다.

  • 모듈형 및 확장 가능 iText 7은 모듈형으로, 필요한 특정 모듈만 설치할 수 있습니다 (예: HTML to PDF 변환을 위한 pdfhtml). 이러한 기능을 모두 사용하지 않는 경우보다 경량화된 구현이 가능합니다.

  • 복잡한 PDF 표준 지원 iText 7은 PDF/A (아카이빙), PDF/UA (접근성), PDF/X (인쇄)와 같은 ISO 표준을 지원하여, 컴플라이언스가 중요한 전문적이고 법적인 환경에 적합합니다.

  • 풍부한 문서화 및 지원 iText 7은 포괄적인 문서화와 방대한 커뮤니티를 보유하고 있습니다. 회사는 또한 전문적인 지원을 제공하여 개발자가 필요할 때 도움을 받을 수 있도록 보장합니다.

  • 무료 버전 제공 (AGPL) 개발자는 AGPL 라이선스 하에서 iText 7을 무료로 사용할 수 있으며, 이는 오픈 소스 프로젝트 또는 개인 사용에 이상적입니다.

단점:

  • 상업적 사용을 위한 AGPL 라이선스 iText 7은 무료 버전을 제공하지만, 상업 사용자는 iText 7을 사용하는 소프트웨어의 소스 코드를 공개하거나 상용 라이선스를 지불해야 하는 AGPL 라이선스를 준수해야 합니다.

  • 배우기 어려운 곡선 iText 7의 API는 더 복잡하고 기능이 많아 간단한 라이브러리인 IronPDF에 비해 학습 곡선이 더 가파를 수 있습니다. 개발자는 그 저수준의 문서 구조와 모듈 기반 아키텍처를 익히는 것이 필요합니다.

  • 단순 작업에는 너무 무겁습니다 iText 7은 기본 문서 생성 또는 기본 HTML to PDF 변환과 같은 간단한 PDF 작업에는 부담스러울 수 있으며, 프로세스를 간소화하는 IronPDF와 같은 라이브러리에 비해 부담스러울 수 있습니다.

  • HTML에서 PDF로 변환 시 외부 모듈 필요\ iText 7의 HTML에서 PDF로 변환 기능은 추가적인 pdfhtml 모듈을 통해서만 가능하며, 별도의 설치가 필요하고 IronPDF만큼 현대적인 웹 콘텐츠 처리를 매끄럽게 하지 못할 수 있습니다.

IronPDF for .NET: 강력한 PDF 라이브러리

IronPDF는 개발자 생산성에 중점을 맞춘 PDF 문서 생성을 간편하게 해주는 고급 .NET 라이브러리입니다. 특히 HTML 콘텐츠 및 스타일링 렌더링에 효과적이며, 최신 웹에서 PDF로의 워크플로우에 이상적입니다.

주요 기능:

  • 바이트 배열에서 PDF 파일을 생성하고 Adobe Reader를 설치할 필요 없이 PDF 문서를 작업합니다.
  • 전체 Chromium 엔진을 사용하여 HTML 콘텐츠로부터 PDF 문서를 생성하는 직접 HTML에서 PDF로의 렌더링
  • MVC Views, Razor Pages, 로컬/원격 URL을 지원합니다.
  • 기본적으로 이미지 파일, JavaScript, CSS 및 반응형 레이아웃을 지원합니다.
  • 사용이 간편한 구문 및 최소한의 설정만 필요합니다.
  • 영구 라이선스 및 AGPL 제한 없음

IronPDF 설치 중

IronPDF는 NuGet을 통해서도 설치할 수 있으며, NuGet 패키지 관리자 콘솔에서 다음 명령을 실행하여 설치할 수 있습니다:

Install-Package IronPdf

패키지 관리자 콘솔을 통해 IronPDF 설치하기

또한, 솔루션 화면의 NuGet 패키지 관리자를 통해 설치할 수 있습니다. "도구 > NuGet 패키지 관리자 > 솔루션용 NuGet 패키지 관리"로 이동하세요.

Visual Studio의 도구 드롭다운 메뉴

그런 다음 IronPDF를 검색하고 "설치"를 클릭하세요.

IronPDF NuGet 패키지 관리자 화면

설치 후 몇 초 안에 전체 HTML 페이지를 PDF로 렌더링할 수 있으며, 추가 모듈이 필요하지 않습니다. 추가 구성 없이 최신 CSS, JavaScript 및 심지어 대화형 웹 콘텐츠까지 지원합니다.

코드 예제: IronPDF로 바이트 배열에서 PDF 문서 생성

using IronPdf;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.GeneratePdfWithIronPdf();
        // Save the PDF to a file
        File.WriteAllBytes("output.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] GeneratePdfWithIronPdf()
    {
        var renderer = new ChromePdfRenderer();
        var pdfDoc = renderer.RenderHtmlAsPdf("<h1>Hello from IronPDF!</h1>");
        return pdfDoc.BinaryData;
    }
}
using IronPdf;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.GeneratePdfWithIronPdf();
        // Save the PDF to a file
        File.WriteAllBytes("output.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] GeneratePdfWithIronPdf()
    {
        var renderer = new ChromePdfRenderer();
        var pdfDoc = renderer.RenderHtmlAsPdf("<h1>Hello from IronPDF!</h1>");
        return pdfDoc.BinaryData;
    }
}
Imports IronPdf
Imports System.IO

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		Dim pdfGenerator As New PdfGenerator()
		Dim pdfBytes() As Byte = pdfGenerator.GeneratePdfWithIronPdf()
		' Save the PDF to a file
		File.WriteAllBytes("output.pdf", pdfBytes)
	End Sub
End Class

Friend Class PdfGenerator
	Public Function GeneratePdfWithIronPdf() As Byte()
		Dim renderer = New ChromePdfRenderer()
		Dim pdfDoc = renderer.RenderHtmlAsPdf("<h1>Hello from IronPDF!</h1>")
		Return pdfDoc.BinaryData
	End Function
End Class
$vbLabelText   $csharpLabel

출력 PDF 파일

IronPDF 출력

설명

  • using IronPdf 문은 모든 PDF 관련 클래스에 접근할 수 있도록 IronPDF 라이브러리를 가져옵니다.
  • var renderer = new ChromePdfRenderer()는 헤드리스 Chromium 엔진으로 구동되는 새로운 HTML-to-PDF 렌더러를 생성합니다.
  • renderer.RenderHtmlAsPdf(...)는 주어진 HTML 문자열을 PDF 문서로 변환합니다. 파일 경로나 URL도 전달할 수 있습니다.
  • pdfDoc.BinaryData는 최종 PDF를 바이트 배열로 반환하여, 저장, 스트리밍 또는 데이터베이스 저장이 가능합니다.

IronPDF의 장단점

장점:

  • 손쉬운 HTML에서 PDF로의 렌더링\ Bootstrap 및 사용자 정의 글꼴을 포함한 전체 스타일링과 함께 HTML, CSS 및 JavaScript 콘텐츠를 바로 PDF로 렌더링할 수 있으며, 복잡한 레이아웃 코드나 추가 모듈이 필요하지 않습니다.

  • 빠른 시작 및 직관적인 API\ 깨끗한 구문으로 몇 줄의 코드만으로 완전히 스타일링된 PDF 파일을 생성하며, .NET Core 및 .NET Framework와 완전히 호환됩니다.

  • 웹 기술에 대한 종합적 지원\ IronPDF는 JavaScript, 최신 CSS, SVG 및 미디어 쿼리를 지원하며, 대부분의 라이브러리가 무헤드 브라우저인 Chromium과 같은 것들을 사용하지 않으면 어려움을 겪습니다(내부적으로 IronPDF는 이를 사용합니다).

  • 내장 이미지 및 자산 처리\ 추가 구성 없이도 이미지, 로컬 파일을 쉽게 포함하거나 원격 URL에서 자산을 가져올 수 있습니다.

  • 영구 라이센스 및 AGPL 없음\ iText 7과 달리 IronPDF는 오픈 소스 AGPL 의무의 제한 없이 유연한 상용 라이센스를 제공합니다.

  • MVC 및 Razor Views에 뛰어남\ ASP.NET 응용 프로그램에서 .cshtml Razor Views를 인쇄 가능한 PDF로 매끄럽게 변환합니다.

단점:

  • 상업적 사용 시 라이센스 필요\ 무료 체험판이 있지만, IronPDF는 오픈 소스가 아닙니다. 예산이 빠듯한 프로젝트는 라이센스 비용을 평가해야 할 수도 있습니다.

  • 큰 초기 패키지 크기\ 무헤드 Chromium 엔진을 번들로 포함하고 있기 때문에 NuGet 패키지가 일부 대안보다 무겁습니다.

실용적인 코드 예제 비교

이 섹션의 다음 코드 예제들은 이러한 라이브러리들이 실제로 어떻게 작동하는지를 보여주며, 동일한 작업에서 IronPDFiText 7을 비교할 것입니다. 두 라이브러리는 동일한 시나리오를 거치게 됩니다: URL에서 PDF 생성, 이미지를 PDF로 렌더링, 스타일이 있는 HTML을 PDF로 변환하며, 이 모든 과정에서 PDF 콘텐츠를 처리하기 위해 바이트 배열을 사용할 것입니다. 이를 통해 개발자들이 각각의 라이브러리가 이 일반적인 사용 사례에 어떻게 접근하는지를 평가할 수 있습니다.

1. 바이트 배열을 사용하여 URL에서 간단한 PDF 생성하기

IronPDF

using IronPdf;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.GeneratePdfFromUrlWithIronPdf();

        // Save the PDF to a file
        File.WriteAllBytes("ironpdf-from-url.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] GeneratePdfFromUrlWithIronPdf()
    {
        var renderer = new ChromePdfRenderer();
        renderer.RenderingOptions.EnableJavaScript = true;
        renderer.RenderingOptions.WaitForJavaScript(5000);
        renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

        var pdf = renderer.RenderUrlAsPdf("https://www.apple.com");
        return pdf.BinaryData;
    }
}
using IronPdf;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.GeneratePdfFromUrlWithIronPdf();

        // Save the PDF to a file
        File.WriteAllBytes("ironpdf-from-url.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] GeneratePdfFromUrlWithIronPdf()
    {
        var renderer = new ChromePdfRenderer();
        renderer.RenderingOptions.EnableJavaScript = true;
        renderer.RenderingOptions.WaitForJavaScript(5000);
        renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

        var pdf = renderer.RenderUrlAsPdf("https://www.apple.com");
        return pdf.BinaryData;
    }
}
Imports IronPdf
Imports System.IO

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		Dim pdfGenerator As New PdfGenerator()
		Dim pdfBytes() As Byte = pdfGenerator.GeneratePdfFromUrlWithIronPdf()

		' Save the PDF to a file
		File.WriteAllBytes("ironpdf-from-url.pdf", pdfBytes)
	End Sub
End Class

Friend Class PdfGenerator
	Public Function GeneratePdfFromUrlWithIronPdf() As Byte()
		Dim renderer = New ChromePdfRenderer()
		renderer.RenderingOptions.EnableJavaScript = True
		renderer.RenderingOptions.WaitForJavaScript(5000)
		renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print

		Dim pdf = renderer.RenderUrlAsPdf("https://www.apple.com")
		Return pdf.BinaryData
	End Function
End Class
$vbLabelText   $csharpLabel

PDF 출력

URL을 PDF로 변환한 IronPDF 출력

IronPDF픽셀 완벽 렌더링을 위한 무경험 Chromium 엔진을 사용하여 전체 JavaScript 및 CSS 지원을 통한 웹 페이지를 렌더링합니다.

iText 7

using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using System.Net.Http;
using System.Threading.Tasks;
using iText.Html2pdf;
using System.IO;

class Program
{
    static async Task Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = await pdfGenerator.GeneratePdfFromUrlWithIText7Async();

        // Save the PDF to a file
        File.WriteAllBytes("itext7-from-url.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public async Task<byte[]> GeneratePdfFromUrlWithIText7Async()
    {
        using var httpClient = new HttpClient();
        string html = await httpClient.GetStringAsync("https://www.apple.com");

        using var stream = new MemoryStream();
        HtmlConverter.ConvertToPdf(html, stream);
        return stream.ToArray();
    }
}
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using System.Net.Http;
using System.Threading.Tasks;
using iText.Html2pdf;
using System.IO;

class Program
{
    static async Task Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = await pdfGenerator.GeneratePdfFromUrlWithIText7Async();

        // Save the PDF to a file
        File.WriteAllBytes("itext7-from-url.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public async Task<byte[]> GeneratePdfFromUrlWithIText7Async()
    {
        using var httpClient = new HttpClient();
        string html = await httpClient.GetStringAsync("https://www.apple.com");

        using var stream = new MemoryStream();
        HtmlConverter.ConvertToPdf(html, stream);
        return stream.ToArray();
    }
}
Imports iText.Kernel.Pdf
Imports iText.Layout
Imports iText.Layout.Element
Imports System.Net.Http
Imports System.Threading.Tasks
Imports iText.Html2pdf
Imports System.IO

Friend Class Program
	Shared Async Function Main(ByVal args() As String) As Task
		Dim pdfGenerator As New PdfGenerator()
		Dim pdfBytes() As Byte = Await pdfGenerator.GeneratePdfFromUrlWithIText7Async()

		' Save the PDF to a file
		File.WriteAllBytes("itext7-from-url.pdf", pdfBytes)
	End Function
End Class

Friend Class PdfGenerator
	Public Async Function GeneratePdfFromUrlWithIText7Async() As Task(Of Byte())
		Dim httpClient As New HttpClient()
		Dim html As String = Await httpClient.GetStringAsync("https://www.apple.com")

		Dim stream = New MemoryStream()
		HtmlConverter.ConvertToPdf(html, stream)
		Return stream.ToArray()
	End Function
End Class
$vbLabelText   $csharpLabel

출력

iText 7 URL을 PDF로 변환한 출력

iText 7은 HttpClient를 사용하여 원시 HTML을 가져오고 HtmlConverter를 사용하여 이를 렌더링하지만, JavaScript 실행을 지원하지 않음 (Selenium이나 JavaScript 전처리를 위한 유사 브라우저 자동화를 사용할 것을 iText의 공식 문서에서 권장) 및 제한된 CSS 스타일링을 제공합니다. iText7은 2021년 버전 7.1.15에서 부분적인 플렉스박스 지원을 추가했지만, 특히 복잡한 현대적인 레이아웃의 경우 대부분의 CSS3 속성은 여전히 지원되지 않습니다.

2. 바이트 배열을 사용하여 이미지에서 새로운 PDF 파일 생성하기

IronPDF

using IronPdf;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.CreatePdfWithImage();

        // Save the PDF to a file
        File.WriteAllBytes("ironpdf-with-image.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] CreatePdfWithImage()
    {
        var pdf = ImageToPdfConverter.ImageToPdf("example.png");
        return pdf.BinaryData;
    }
}
using IronPdf;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.CreatePdfWithImage();

        // Save the PDF to a file
        File.WriteAllBytes("ironpdf-with-image.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] CreatePdfWithImage()
    {
        var pdf = ImageToPdfConverter.ImageToPdf("example.png");
        return pdf.BinaryData;
    }
}
Imports IronPdf
Imports System.IO

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		Dim pdfGenerator As New PdfGenerator()
		Dim pdfBytes() As Byte = pdfGenerator.CreatePdfWithImage()

		' Save the PDF to a file
		File.WriteAllBytes("ironpdf-with-image.pdf", pdfBytes)
	End Sub
End Class

Friend Class PdfGenerator
	Public Function CreatePdfWithImage() As Byte()
		Dim pdf = ImageToPdfConverter.ImageToPdf("example.png")
		Return pdf.BinaryData
	End Function
End Class
$vbLabelText   $csharpLabel

출력

IronPDF 이미지를 PDF로 변환한 출력

IronPDF의 ImageToPdfConverter 도구를 사용하여 간편하게 이미지를 PDF로 생성할 수 있습니다. 이를 통해 PNG 파일이나 JPG와 같은 이미지에서 쉽게 PDF 파일을 생성할 수 있습니다.

iText 7

using iText.Kernel.Pdf;
using iText.Layout;
using iText.IO.Image;
using iText.Layout.Element;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.CreatePdfWithImage();

        // Save the PDF to a file
        File.WriteAllBytes("iText-with-image.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] CreatePdfWithImage()
    {
        using var ms = new MemoryStream();
        using var writer = new PdfWriter(ms);
        using var pdfDoc = new iText.Kernel.Pdf.PdfDocument(writer);
        var document = new Document(pdfDoc);

        var img = new Image(ImageDataFactory.Create("https://itextpdf.com/sites/default/files/2018-11/iText%207%20Product%20software%20-%20webimages_509x339px_V2_iText%207%20Core.png"));
        document.Add(img);
        document.Close();

        return ms.ToArray();
    }
}
using iText.Kernel.Pdf;
using iText.Layout;
using iText.IO.Image;
using iText.Layout.Element;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.CreatePdfWithImage();

        // Save the PDF to a file
        File.WriteAllBytes("iText-with-image.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] CreatePdfWithImage()
    {
        using var ms = new MemoryStream();
        using var writer = new PdfWriter(ms);
        using var pdfDoc = new iText.Kernel.Pdf.PdfDocument(writer);
        var document = new Document(pdfDoc);

        var img = new Image(ImageDataFactory.Create("https://itextpdf.com/sites/default/files/2018-11/iText%207%20Product%20software%20-%20webimages_509x339px_V2_iText%207%20Core.png"));
        document.Add(img);
        document.Close();

        return ms.ToArray();
    }
}
Imports iText.Kernel.Pdf
Imports iText.Layout
Imports iText.IO.Image
Imports iText.Layout.Element
Imports System.IO

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		Dim pdfGenerator As New PdfGenerator()
		Dim pdfBytes() As Byte = pdfGenerator.CreatePdfWithImage()

		' Save the PDF to a file
		File.WriteAllBytes("iText-with-image.pdf", pdfBytes)
	End Sub
End Class

Friend Class PdfGenerator
	Public Function CreatePdfWithImage() As Byte()
		Dim ms = New MemoryStream()
		Dim writer = New PdfWriter(ms)
		Dim pdfDoc = New iText.Kernel.Pdf.PdfDocument(writer)
		Dim document As New Document(pdfDoc)

		Dim img = New Image(ImageDataFactory.Create("https://itextpdf.com/sites/default/files/2018-11/iText%207%20Product%20software%20-%20webimages_509x339px_V2_iText%207%20Core.png"))
		document.Add(img)
		document.Close()

		Return ms.ToArray()
	End Function
End Class
$vbLabelText   $csharpLabel

출력

iText 7 이미지를 포함한 PDF 출력

ImageDataFactory를 사용한 문서 레이아웃 수동 생성 및 명시적 이미지 삽입.

3. 바이트 배열을 사용하여 스타일이 있는 HTML 콘텐츠를 PDF로 변환하기

IronPDF

using IronPdf;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.CreateStyledPdf();

        // Save the PDF to a file
        File.WriteAllBytes("ironpdf-styled-html.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] CreateStyledPdf()
    {
        string html = @"
        <html>
            <head>
                <style>
                    body { 
                        background-color: #f0f0f0; 
                        margin: 20px; 
                        padding: 20px; 
                        border-radius: 5px; 
                        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
                    }
                    h1 { 
                        color: navy;
                        font-size: 32px;   
                        text-align: center;
                       }
                    p { 
                        font-size: 16px; 
                        font-weight: bold;
                      }
                </style>
            </head>
            <body>
                <h1>Welcome to IronPDF</h1>
                <p>This is a simple PDF document generated using IronPDF.</p>
            </body>
        </html>";

        var pdf = new ChromePdfRenderer().RenderHtmlAsPdf(html);
        return pdf.BinaryData;
    }
}
using IronPdf;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.CreateStyledPdf();

        // Save the PDF to a file
        File.WriteAllBytes("ironpdf-styled-html.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] CreateStyledPdf()
    {
        string html = @"
        <html>
            <head>
                <style>
                    body { 
                        background-color: #f0f0f0; 
                        margin: 20px; 
                        padding: 20px; 
                        border-radius: 5px; 
                        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
                    }
                    h1 { 
                        color: navy;
                        font-size: 32px;   
                        text-align: center;
                       }
                    p { 
                        font-size: 16px; 
                        font-weight: bold;
                      }
                </style>
            </head>
            <body>
                <h1>Welcome to IronPDF</h1>
                <p>This is a simple PDF document generated using IronPDF.</p>
            </body>
        </html>";

        var pdf = new ChromePdfRenderer().RenderHtmlAsPdf(html);
        return pdf.BinaryData;
    }
}
Imports IronPdf
Imports System.IO

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		Dim pdfGenerator As New PdfGenerator()
		Dim pdfBytes() As Byte = pdfGenerator.CreateStyledPdf()

		' Save the PDF to a file
		File.WriteAllBytes("ironpdf-styled-html.pdf", pdfBytes)
	End Sub
End Class

Friend Class PdfGenerator
	Public Function CreateStyledPdf() As Byte()
		Dim html As String = "
        <html>
            <head>
                <style>
                    body { 
                        background-color: #f0f0f0; 
                        margin: 20px; 
                        padding: 20px; 
                        border-radius: 5px; 
                        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
                    }
                    h1 { 
                        color: navy;
                        font-size: 32px;   
                        text-align: center;
                       }
                    p { 
                        font-size: 16px; 
                        font-weight: bold;
                      }
                </style>
            </head>
            <body>
                <h1>Welcome to IronPDF</h1>
                <p>This is a simple PDF document generated using IronPDF.</p>
            </body>
        </html>"

		Dim pdf = (New ChromePdfRenderer()).RenderHtmlAsPdf(html)
		Return pdf.BinaryData
	End Function
End Class
$vbLabelText   $csharpLabel

출력

IronPDF 스타일이 적용된 HTML을 PDF로 변환한 출력

IronPDF는 그 Chromium 엔진 덕분에 태그나 외장 스타일시트의 CSS를 완벽하게 지원합니다.

iText 7 + pdfHTML

using iText.Kernel.Pdf;
using iText.Html2pdf;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.CreateStyledPdf();

        // Save the new document to the specified file location
        File.WriteAllBytes("iText-styled-html.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] CreateStyledPdf()
    {
        string html = @"
        <html>
            <head>
                <style>
                    body { 
                        background-color: #f0f0f0; 
                        margin: 20px; 
                        padding: 20px; 
                        border-radius: 5px; 
                        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
                    }
                    h1 { 
                        color: navy;
                        font-size: 32px;   
                        text-align: center;
                       }
                    p { 
                        font-size: 16px; 
                        font-weight: bold;
                      }
                </style>
            </head>
            <body>
                <h1>Welcome to iText 7</h1>
                <p>This is a simple PDF document generated using iText 7 and pdfHTML.</p>
            </body>
        </html>";

        using var ms = new MemoryStream();
        ConverterProperties properties = new ConverterProperties();
        HtmlConverter.ConvertToPdf(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(html)), ms, properties);
        return ms.ToArray();
    }
}
using iText.Kernel.Pdf;
using iText.Html2pdf;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var pdfGenerator = new PdfGenerator();
        byte[] pdfBytes = pdfGenerator.CreateStyledPdf();

        // Save the new document to the specified file location
        File.WriteAllBytes("iText-styled-html.pdf", pdfBytes);
    }
}

class PdfGenerator
{
    public byte[] CreateStyledPdf()
    {
        string html = @"
        <html>
            <head>
                <style>
                    body { 
                        background-color: #f0f0f0; 
                        margin: 20px; 
                        padding: 20px; 
                        border-radius: 5px; 
                        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
                    }
                    h1 { 
                        color: navy;
                        font-size: 32px;   
                        text-align: center;
                       }
                    p { 
                        font-size: 16px; 
                        font-weight: bold;
                      }
                </style>
            </head>
            <body>
                <h1>Welcome to iText 7</h1>
                <p>This is a simple PDF document generated using iText 7 and pdfHTML.</p>
            </body>
        </html>";

        using var ms = new MemoryStream();
        ConverterProperties properties = new ConverterProperties();
        HtmlConverter.ConvertToPdf(new MemoryStream(System.Text.Encoding.UTF8.GetBytes(html)), ms, properties);
        return ms.ToArray();
    }
}
Imports iText.Kernel.Pdf
Imports iText.Html2pdf
Imports System.IO

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		Dim pdfGenerator As New PdfGenerator()
		Dim pdfBytes() As Byte = pdfGenerator.CreateStyledPdf()

		' Save the new document to the specified file location
		File.WriteAllBytes("iText-styled-html.pdf", pdfBytes)
	End Sub
End Class

Friend Class PdfGenerator
	Public Function CreateStyledPdf() As Byte()
		Dim html As String = "
        <html>
            <head>
                <style>
                    body { 
                        background-color: #f0f0f0; 
                        margin: 20px; 
                        padding: 20px; 
                        border-radius: 5px; 
                        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
                    }
                    h1 { 
                        color: navy;
                        font-size: 32px;   
                        text-align: center;
                       }
                    p { 
                        font-size: 16px; 
                        font-weight: bold;
                      }
                </style>
            </head>
            <body>
                <h1>Welcome to iText 7</h1>
                <p>This is a simple PDF document generated using iText 7 and pdfHTML.</p>
            </body>
        </html>"

		Dim ms = New MemoryStream()
		Dim properties As New ConverterProperties()
		HtmlConverter.ConvertToPdf(New MemoryStream(System.Text.Encoding.UTF8.GetBytes(html)), ms, properties)
		Return ms.ToArray()
	End Function
End Class
$vbLabelText   $csharpLabel

출력

iText 7 스타일이 적용된 HTML을 PDF로 변환한 출력

HTML 변환 작업을 처리하기 위해 유료 추가 기능인 pdfHTML 설치가 필요합니다.

비교 요약

기능 IronPDF iText 7 (pdfHTML 포함)
URL을 PDF로 렌더링 전체 Chromium 렌더링 HTML 가져오기, 네이티브 JS 지원 없음
이미지 추가 HTML 및 전용 이미지 스탬핑 도구를 통한 포함 수동 이미지 팩토리
스타일이 있는 HTML 렌더링 전체 CSS 지원 pdfHTML을 통한 CSS 지원만 가능
바이트 배열 반환
설치 복잡성 간단함 보통 (수동 레이아웃)
출력 품질 픽셀 완벽 좋음, 그러나 정적

결론: 어떤 .NET 라이브러리를 선택할까요?

IronPDFiText 7 중에서 선택하는 것은 프로젝트 요구 사항에 따라 다릅니다. 그러나 개발자 경험, 사용의 용이성, 현대적 렌더링 정확도 면에서는 IronPDF가 명확히 돋보입니다.

동적 HTML 콘텐츠, 웹 렌더링 작업, 또는 전체 JavaScript 및 CSS 지원으로 PDF 파일을 URL에서 생성해야 하는 경우, IronPDF의 Chromium 기반 엔진은 뛰어난 정확성을 제공합니다. 직관적인 API와 빠른 설치 프로세스를 통해 특히 바이트 배열, 파일 스트림, 또는 웹 기반 PDF 생성을 위한 빠른 개발 및 실용적인 활용에 적합합니다.

반면, iText 7은 더욱 전통적인 레이아웃 중심 접근 방식을 채택한 강력하고 존경받는 라이브러리입니다. 문서 구조에 대한 견고한 제어를 제공하며, 세밀한 조작이 필요한 개발자에게는 훌륭하지만, 학습 곡선이 가파르고 현대적인 HTML 렌더링 기능이 부족합니다.

결론은 다음과 같습니다:

  • 현대적인 웹 콘텐츠, 스타일이 있는 HTML, 또는 빠른 프로토타이핑에서 픽셀 완벽 출력을 원하십니까? IronPDF를 선택하세요.
  • 미세 조정 제어가 가능한 로우 레벨 PDF 생성 도구가 필요하십니까? iText 7은 적합한 선택일 수 있습니다.

IronPDF로 시작할 준비가 되셨습니까? 무료 체험판을 다운로드하고 C#에서 몇 줄의 코드로 전문적인 바이트 배열 기반 PDF를 얼마나 쉽게 생성할 수 있는지 확인하세요.

참고해 주세요iText 7은 해당 소유자의 등록 상표입니다. 이 사이트는 iText 7과 관련이 없으며, 승인 받거나 후원받지 않았습니다. 모든 제품 이름, 로고 및 브랜드는 해당 소유자의 자산입니다. 비교는 정보 제공 목적으로만 사용되며, 작성 시점에 공개적으로 이용 가능한 정보를 반영합니다.

자주 묻는 질문

C#에서 바이트 배열을 PDF로 어떻게 변환할 수 있나요?

IronPDF를 사용하여 C#에서 바이트 배열을 PDF로 변환할 수 있습니다. `PdfDocument.FromBytes` 메소드를 사용하여 바이트 배열을 IronPDF 문서에 로드하면 데이터를 파싱하고 PDF 문서를 생성할 수 있습니다.

IronPDF 사용하여 HTML을 PDF로 변환할 때의 장점은 무엇인가요?

IronPDF는 최신 CSS와 JavaScript를 지원하는 헤드리스 크로미엄 엔진을 사용하여 HTML을 PDF로 변환하는 데 뛰어납니다. 이는 동적인 웹 콘텐츠를 픽셀 퍼펙트 PDF 문서로 렌더링하는데 이상적입니다.

PDF 생성에 있어 IronPDF를 iText 7보다 사용하는 주요 장점은 무엇인가요?

IronPDF는 프로젝트에서 HTML을 PDF로 변환해야 하는 경우 간단한 API와 빠른 설정을 제공하며, CSS와 JavaScript를 완벽하게 지원합니다. 이는 신속한 개발과 웹 콘텐츠 통합을 요구하는 애플리케이션에 특히 적합합니다.

iText 7은 PDF 표준 준수를 어떻게 처리하나요?

iText 7은 PDF/A, PDF/UA, PDF/X와 같은 표준을 지원하며, 규정이 엄격한 산업을 위해 설계되었습니다. 이는 PDF 생성에 대한 강력한 제어를 제공하며, 규정 준수가 중요한 애플리케이션에 적합합니다.

.NET 프로젝트에 IronPDF를 설치하는 과정은 무엇인가요?

IronPDF를 설치하려면 Visual Studio에서 NuGet 패키지 관리자를 사용할 수 있습니다. 패키지 관리자 콘솔에서 `Install-Package IronPdf` 명령어를 실행하여 프로젝트에 추가하세요.

IronPDF는 ASP.NET 보기에서 PDF를 생성할 수 있나요?

네, IronPDF는 ASP.NET 보기를 직접 PDF 문서로 렌더링할 수 있습니다. 이 기능을 통해 개발자는 복잡한 레이아웃과 스타일이 있는 웹 페이지를 쉽게 PDF로 변환할 수 있습니다.

어떤 종류의 애플리케이션이 IronPDF 사용의 가장 큰 혜택을 누리나요?

보고서나 송장과 같은 동적인 웹 콘텐츠를 PDF로 변환해야 하는 애플리케이션이 IronPDF 사용의 가장 큰 혜택을 누립니다. 빠른 설정과 웹 기술 지원은 빈번한 업데이트와 현대적 디자인이 필요한 프로젝트에 이상적입니다.

iText 7의 모듈형 아키텍처가 그 사용에 어떻게 영향을 미치나요?

iText 7의 모듈형 아키텍처는 HTML 변환이나 디지털 서명과 같은 특정 PDF 기능을 필요에 따라 추가할 수 있게 합니다. 이는 유연성을 제공하지만 각 모듈에 대한 추가 학습 및 설치가 필요할 수 있습니다.

IronPDF와 iText 7의 라이센스 차이점은 무엇인가요?

IronPDF는 AGPL 제약 없이 상업적 애플리케이션에 적합한 영구 라이센스를 제공합니다. 반면 iText 7은 오픈 소스 프로젝트를 위한 AGPL 라이센스로 제공되며, 상업적 사용에는 유료 라이센스가 필요합니다.

커티스 차우
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.

아이언 서포트 팀

저희는 주 5일, 24시간 온라인으로 운영합니다.
채팅
이메일
전화해