
C#에서 비밀번호와 권한으로 PDF 파일을 보호하는 방법
Gotenberg에서 IronPDF로의 마이그레이션은 Docker 기반의 마이크로서비스 아키텍처에서 HTTP API 호출을 통해 진행되는 .NET PDF 워크플로를 프로세스 내의 네이티브 C# 라이브러리로 변환합니다. 이 가이드는 인프라 오버헤드, 네트워크 지연 및 컨테이너 관리의 복잡성을 제거하는 포괄적이고 단계적인 마이그레이션 경로를 제공하여 전문 .NET 개발자를 위한 것입니다.
Gotenberg에서 IronPDF로 마이그레이션하는 이유
Gotenberg아키텍처 문제
Gotenberg는 PDF 생성을 위한 Docker 기반 마이크로서비스 아키텍처입니다. 강력하고 유연하지만 C# 애플리케이션에 상당한 복잡성을 초래합니다:
-
인프라 오버헤드: Docker, 컨테이너 오케스트레이션(Kubernetes/Docker Compose), 서비스 검색 및 로드 밸런싱이 필요합니다. 모든 배포는 더 복잡해집니다.
-
네트워크 지연: 모든 PDF 작업은 별도의 서비스로 HTTP 요청을 필요로 하며, 요청당10-100ms이상의 추가 지연이 발생합니다. 이 지연은 대량 처리 시 빠르게 누적됩니다.
-
콜드 스타트 문제: 컨테이너 시작은 첫 요청에 2-5초를 추가할 수 있습니다. 모든 포드 재시작, 모든 스케일업 이벤트 및 모든 배포는 콜드 스타트를 유발합니다.
-
운영 복잡성: 컨테이너의 상태, 스케일링, 로깅 및 모니터링을 주 애플리케이션과 별도로 관리해야 합니다.
-
멀티파트 양식 데이터: 각 요청은 멀티파트/양식 데이터 페이로드를 구성해야 하며, 이는 장황하고 오류가 발생하기 쉬우며 유지 관리가 번거롭습니다.
-
고장 지점: 네트워크 시간 초과, 서비스 불가 및 컨테이너 충돌이 발생할 경우 이를 처리하는 책임은 사용자에게 있습니다.
-
**버전 관리:**Gotenberg이미지는 애플리케이션과 별도로 업데이트됩니다; API 변경 사항이 예상치 못하게 통합을 깨뜨릴 수 있습니다.
Gotenberg대IronPDF비교
| 측면 | Gotenberg | IronPDF |
|---|---|---|
| 배포 | Docker 컨테이너 + 오케스트레이션 | 단일 NuGet 패키지 |
| 아키텍처 | 마이크로서비스 (REST API) | 프로세스 내 라이브러리 |
| 요청당 지연 | 10-100ms+ (네트워크 왕복) | < 1ms 오버헤드 |
| 콜드 스타트 | 2-5초 (컨테이너 초기화) | 1-2초 (첫 렌더링만) |
| 인프라 | Docker, Kubernetes, 로드 밸런서 | 필요 없음 |
| 고장 모드 | 네트워크, 컨테이너, 서비스 오류 | 표준 .NET 예외 |
| API 스타일 | REST multipart/form-data | 네이티브 C# 메서드 호출 |
| 스케일링 | 수평 확장 (더 많은 컨테이너) | 수직 확장 (프로세스 내) |
| 디버깅 | 분산 추적 필요 | 표준 디버거 |
| 버전 제어 | 컨테이너 이미지 태그 | NuGet 패키지 버전 |
.NET 최신 버전을 목표로 하는 팀은 IronPDF가 현대적인 .NET 패턴과 네이티브로 통합되는 제로 인프라 종속성을 제공합니다.
마이그레이션 복잡성 평가
기능별 예상 노력
| 기능 | 마이그레이션 복잡성 |
|---|---|
| HTML to PDF | 매우 낮음 |
| URL을 PDF로 변환 | 매우 낮음 |
| 맞춤 용지 크기 | 낮음 |
| 여백 | 낮음 |
| PDF 병합 | 낮음 |
| 헤더/푸터 | 중간 |
| 지연 대기 | 낮음 |
| PDF/A 변환 | 낮음 |
패러다임 전환
이Gotenberg마이그레이션의 근본적인 변화는 멀티파트 양식 데이터를 포함한 HTTP API 호출에서 네이티브 C# 메서드 호출로의 이동입니다:
Gotenberg: Docker 컨테이너에 HTTP POST 멀티파트/양식 데이터
IronPDF: C# 객체에 직접 메서드 호출
시작하기 전에
필수 조건
- .NET 버전: IronPDF는 .NET Framework 4.6.2+ 및 .NET Core 3.1+ / .NET 5/6/7/8/9+를 지원합니다.
- 라이선스 키: ironpdf.com에서IronPDF라이선스 키를 얻으세요.
- 인프라 제거 계획: 마이그레이션 후Gotenberg컨테이너를 폐기하기 위해 문서화합니다.
모든Gotenberg사용 식별
# Find direct HTTP calls to Gotenberg
grep -r "gotenberg\|/forms/chromium\|/forms/libreoffice\|/forms/pdfengines" --include="*.cs" .
# Find GotenbergSharpApiClient usage
grep -r "GotenbergSharpClient\|Gotenberg.Sharp\|ChromiumRequest" --include="*.cs" .
# Find Docker/KubernetesGotenbergconfiguration
grep -r "gotenberg/gotenberg\|gotenberg:" --include="*.yml" --include="*.yaml" .
NuGet 패키지 변경 사항
# RemoveGotenbergclient (if using)
dotnet remove package Gotenberg.Sharp.API.Client
# Install IronPDF
dotnet add package IronPdf
빠른 시작 마이그레이션
1단계: 라이선스 구성 업데이트
이전 (Gotenberg):
Gotenberg는 라이선스를 필요로 하지 않지만 컨테이너 URL을 사용하여 Docker 인프라를 필요로 합니다.
private readonly string _gotenbergUrl = "http://localhost:3000";Private ReadOnly _gotenbergUrl As String = "http://localhost:3000"Private ReadOnly _gotenbergUrl As String = "http://localhost:3000"이후 (IronPDF):
// Set once at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";// Set once at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";netnet2단계: 네임스페이스 가져오기 업데이트
// Before (Gotenberg)
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
// After (IronPDF)
using IronPdf;
using IronPdf.Rendering;// Before (Gotenberg)
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
// After (IronPDF)
using IronPdf;
using IronPdf.Rendering;Imports System.Net.Http
Imports System.Threading.Tasks
Imports System.IO
Imports IronPdf
Imports IronPdf.RenderingImports System.Net.Http
Imports System.Threading.Tasks
Imports System.IO
Imports IronPdf
Imports IronPdf.Rendering완전한 API 참조
Gotenberg엔드포인트에서IronPDF매핑
| Gotenberg 라우트 | IronPDF 동등 |
|---|---|
POST /forms/chromium/convert/html | ChromePdfRenderer.RenderHtmlAsPdf() |
POST /forms/chromium/convert/url | ChromePdfRenderer.RenderUrlAsPdf() |
POST /forms/pdfengines/merge | PdfDocument.Merge() |
POST /forms/pdfengines/convert | pdf.SaveAs() 설정과 함께 |
GET /health | 해당 없음 |
양식 매개변수에서 RenderingOptions 매핑
| Gotenberg 매개변수 | IronPDF 속성 | 변환 참고사항 |
|---|---|---|
paperWidth (인치) | RenderingOptions.PaperSize | 열거형 또는 사용자 지정 크기 사용 |
paperHeight (인치) | RenderingOptions.PaperSize | 열거형 또는 사용자 지정 크기 사용 |
marginTop (인치) | RenderingOptions.MarginTop | 밀리미터로 변환하기 위해 25.4를 곱하십시오. |
marginBottom (인치) | RenderingOptions.MarginBottom | 밀리미터로 변환하기 위해 25.4를 곱하십시오. |
printBackground | RenderingOptions.PrintHtmlBackgrounds | Boolean |
landscape | RenderingOptions.PaperOrientation | Landscape 열거형 |
waitDelay (예: "3s") | RenderingOptions.WaitFor.RenderDelay(ms) | 문자열을 밀리초로 변환 |
코드 마이그레이션 예제
예제 1: 기본 HTML에서 PDF로
이전 (Gotenberg):
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
class GotenbergExample
{
static async Task Main()
{
var gotenbergUrl = "http://localhost:3000/forms/chromium/convert/html";
using var client = new HttpClient();
using var content = new MultipartFormDataContent();
var html = "<html><body><h1>Hello from Gotenberg</h1></body></html>";
content.Add(new StringContent(html), "files", "index.html");
var response = await client.PostAsync(gotenbergUrl, content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("output.pdf", pdfBytes);
Console.WriteLine("PDF generated successfully");
}
}using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
class GotenbergExample
{
static async Task Main()
{
var gotenbergUrl = "http://localhost:3000/forms/chromium/convert/html";
using var client = new HttpClient();
using var content = new MultipartFormDataContent();
var html = "<html><body><h1>Hello from Gotenberg</h1></body></html>";
content.Add(new StringContent(html), "files", "index.html");
var response = await client.PostAsync(gotenbergUrl, content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("output.pdf", pdfBytes);
Console.WriteLine("PDF generated successfully");
}
}Imports System
Imports System.Net.Http
Imports System.Threading.Tasks
Imports System.IO
Module GotenbergExample
Sub Main()
MainAsync().GetAwaiter().GetResult()
End Sub
Private Async Function MainAsync() As Task
Dim gotenbergUrl = "http://localhost:3000/forms/chromium/convert/html"
Using client As New HttpClient()
Using content As New MultipartFormDataContent()
Dim html = "<html><body><h1>Hello from Gotenberg</h1></body></html>"
content.Add(New StringContent(html), "files", "index.html")
Dim response = Await client.PostAsync(gotenbergUrl, content)
Dim pdfBytes = Await response.Content.ReadAsByteArrayAsync()
Await File.WriteAllBytesAsync("output.pdf", pdfBytes)
Console.WriteLine("PDF generated successfully")
End Using
End Using
End Function
End ModuleImports System
Imports System.Net.Http
Imports System.Threading.Tasks
Imports System.IO
Module GotenbergExample
Sub Main()
MainAsync().GetAwaiter().GetResult()
End Sub
Private Async Function MainAsync() As Task
Dim gotenbergUrl = "http://localhost:3000/forms/chromium/convert/html"
Using client As New HttpClient()
Using content As New MultipartFormDataContent()
Dim html = "<html><body><h1>Hello from Gotenberg</h1></body></html>"
content.Add(New StringContent(html), "files", "index.html")
Dim response = Await client.PostAsync(gotenbergUrl, content)
Dim pdfBytes = Await response.Content.ReadAsByteArrayAsync()
Await File.WriteAllBytesAsync("output.pdf", pdfBytes)
Console.WriteLine("PDF generated successfully")
End Using
End Using
End Function
End Module이후 (IronPDF):
// NuGet: Install-Package IronPdf
using System;
using IronPdf;
class IronPdfExample
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var html = "<html><body><h1>Hello from IronPDF</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF generated successfully");
}
}// NuGet: Install-Package IronPdf
using System;
using IronPdf;
class IronPdfExample
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var html = "<html><body><h1>Hello from IronPDF</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
Console.WriteLine("PDF generated successfully");
}
}' NuGet: Install-Package IronPdf
Imports System
Imports IronPdf
Module IronPdfExample
Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim html = "<html><body><h1>Hello from IronPDF</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
Console.WriteLine("PDF generated successfully")
End Sub
End Module' NuGet: Install-Package IronPdf
Imports System
Imports IronPdf
Module IronPdfExample
Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim html = "<html><body><h1>Hello from IronPDF</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
Console.WriteLine("PDF generated successfully")
End Sub
End Module차이점은 현저합니다: Gotenberg는 HttpClient를 구성하고, MultipartFormDataContent를 빌드하고, 실행 중인 Docker 컨테이너에 비동기 HTTP POST를 수행하며, 바이트 배열 응답을 처리해야 합니다. IronPDF는 ChromePdfRenderer 메서드 호출을 통해 세 줄로 이를 줄여줍니다 - 네트워크 오버헤드, 컨테이너 의존성, 비동기 복잡성이 없습니다. HTML to PDF 문서에서 추가 렌더링 옵션을 참조하십시오.
예제 2: URL에서 PDF로 변환
이전 (Gotenberg):
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
class GotenbergUrlToPdf
{
static async Task Main()
{
var gotenbergUrl = "http://localhost:3000/forms/chromium/convert/url";
using var client = new HttpClient();
using var content = new MultipartFormDataContent();
content.Add(new StringContent("https://example.com"), "url");
var response = await client.PostAsync(gotenbergUrl, content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("webpage.pdf", pdfBytes);
Console.WriteLine("PDF from URL generated successfully");
}
}using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
class GotenbergUrlToPdf
{
static async Task Main()
{
var gotenbergUrl = "http://localhost:3000/forms/chromium/convert/url";
using var client = new HttpClient();
using var content = new MultipartFormDataContent();
content.Add(new StringContent("https://example.com"), "url");
var response = await client.PostAsync(gotenbergUrl, content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("webpage.pdf", pdfBytes);
Console.WriteLine("PDF from URL generated successfully");
}
}Imports System
Imports System.Net.Http
Imports System.Threading.Tasks
Imports System.IO
Module GotenbergUrlToPdf
Async Function Main() As Task
Dim gotenbergUrl = "http://localhost:3000/forms/chromium/convert/url"
Using client As New HttpClient()
Using content As New MultipartFormDataContent()
content.Add(New StringContent("https://example.com"), "url")
Dim response = Await client.PostAsync(gotenbergUrl, content)
Dim pdfBytes = Await response.Content.ReadAsByteArrayAsync()
Await File.WriteAllBytesAsync("webpage.pdf", pdfBytes)
Console.WriteLine("PDF from URL generated successfully")
End Using
End Using
End Function
End ModuleImports System
Imports System.Net.Http
Imports System.Threading.Tasks
Imports System.IO
Module GotenbergUrlToPdf
Async Function Main() As Task
Dim gotenbergUrl = "http://localhost:3000/forms/chromium/convert/url"
Using client As New HttpClient()
Using content As New MultipartFormDataContent()
content.Add(New StringContent("https://example.com"), "url")
Dim response = Await client.PostAsync(gotenbergUrl, content)
Dim pdfBytes = Await response.Content.ReadAsByteArrayAsync()
Await File.WriteAllBytesAsync("webpage.pdf", pdfBytes)
Console.WriteLine("PDF from URL generated successfully")
End Using
End Using
End Function
End Module이후 (IronPDF):
// NuGet: Install-Package IronPdf
using System;
using IronPdf;
class IronPdfUrlToPdf
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("webpage.pdf");
Console.WriteLine("PDF from URL generated successfully");
}
}// NuGet: Install-Package IronPdf
using System;
using IronPdf;
class IronPdfUrlToPdf
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("webpage.pdf");
Console.WriteLine("PDF from URL generated successfully");
}
}' NuGet: Install-Package IronPdf
Imports System
Imports IronPdf
Class IronPdfUrlToPdf
Shared Sub Main()
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderUrlAsPdf("https://example.com")
pdf.SaveAs("webpage.pdf")
Console.WriteLine("PDF from URL generated successfully")
End Sub
End Class' NuGet: Install-Package IronPdf
Imports System
Imports IronPdf
Class IronPdfUrlToPdf
Shared Sub Main()
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderUrlAsPdf("https://example.com")
pdf.SaveAs("webpage.pdf")
Console.WriteLine("PDF from URL generated successfully")
End Sub
End ClassGotenberg 접근 방식은 다른 엔드포인트가 필요하며 (/forms/chromium/convert/url), 멀티파트 콘텐츠를 URL을 폼 필드로 사용하여 빌드하고, 비동기 HTTP 응답을 처리해야 합니다. IronPDF의 RenderUrlAsPdf() 메서드는 URL을 직접 수용하고 PdfDocument 객체를 동기적으로 반환합니다. URL을 PDF로 변환에 대해 더 알아보세요.
예제 3: 사용자 지정 용지 크기 및 여백
이전 (Gotenberg):
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
class GotenbergCustomSize
{
static async Task Main()
{
var gotenbergUrl = "http://localhost:3000/forms/chromium/convert/html";
using var client = new HttpClient();
using var content = new MultipartFormDataContent();
var html = "<html><body><h1>Custom Size PDF</h1></body></html>";
content.Add(new StringContent(html), "files", "index.html");
content.Add(new StringContent("8.5"), "paperWidth");
content.Add(new StringContent("11"), "paperHeight");
content.Add(new StringContent("0.5"), "marginTop");
content.Add(new StringContent("0.5"), "marginBottom");
var response = await client.PostAsync(gotenbergUrl, content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("custom-size.pdf", pdfBytes);
Console.WriteLine("Custom size PDF generated successfully");
}
}using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
class GotenbergCustomSize
{
static async Task Main()
{
var gotenbergUrl = "http://localhost:3000/forms/chromium/convert/html";
using var client = new HttpClient();
using var content = new MultipartFormDataContent();
var html = "<html><body><h1>Custom Size PDF</h1></body></html>";
content.Add(new StringContent(html), "files", "index.html");
content.Add(new StringContent("8.5"), "paperWidth");
content.Add(new StringContent("11"), "paperHeight");
content.Add(new StringContent("0.5"), "marginTop");
content.Add(new StringContent("0.5"), "marginBottom");
var response = await client.PostAsync(gotenbergUrl, content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync("custom-size.pdf", pdfBytes);
Console.WriteLine("Custom size PDF generated successfully");
}
}Imports System
Imports System.Net.Http
Imports System.Threading.Tasks
Imports System.IO
Class GotenbergCustomSize
Shared Async Function Main() As Task
Dim gotenbergUrl = "http://localhost:3000/forms/chromium/convert/html"
Using client As New HttpClient()
Using content As New MultipartFormDataContent()
Dim html = "<html><body><h1>Custom Size PDF</h1></body></html>"
content.Add(New StringContent(html), "files", "index.html")
content.Add(New StringContent("8.5"), "paperWidth")
content.Add(New StringContent("11"), "paperHeight")
content.Add(New StringContent("0.5"), "marginTop")
content.Add(New StringContent("0.5"), "marginBottom")
Dim response = Await client.PostAsync(gotenbergUrl, content)
Dim pdfBytes = Await response.Content.ReadAsByteArrayAsync()
Await File.WriteAllBytesAsync("custom-size.pdf", pdfBytes)
Console.WriteLine("Custom size PDF generated successfully")
End Using
End Using
End Function
End ClassImports System
Imports System.Net.Http
Imports System.Threading.Tasks
Imports System.IO
Class GotenbergCustomSize
Shared Async Function Main() As Task
Dim gotenbergUrl = "http://localhost:3000/forms/chromium/convert/html"
Using client As New HttpClient()
Using content As New MultipartFormDataContent()
Dim html = "<html><body><h1>Custom Size PDF</h1></body></html>"
content.Add(New StringContent(html), "files", "index.html")
content.Add(New StringContent("8.5"), "paperWidth")
content.Add(New StringContent("11"), "paperHeight")
content.Add(New StringContent("0.5"), "marginTop")
content.Add(New StringContent("0.5"), "marginBottom")
Dim response = Await client.PostAsync(gotenbergUrl, content)
Dim pdfBytes = Await response.Content.ReadAsByteArrayAsync()
Await File.WriteAllBytesAsync("custom-size.pdf", pdfBytes)
Console.WriteLine("Custom size PDF generated successfully")
End Using
End Using
End Function
End Class이후 (IronPDF):
// NuGet: Install-Package IronPdf
using System;
using IronPdf;
using IronPdf.Rendering;
class IronPdfCustomSize
{
static void Main()
{
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.PaperSize = PdfPaperSize.Letter;
renderer.RenderingOptions.MarginTop = 50;
renderer.RenderingOptions.MarginBottom = 50;
var html = "<html><body><h1>Custom Size PDF</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("custom-size.pdf");
Console.WriteLine("Custom size PDF generated successfully");
}
}// NuGet: Install-Package IronPdf
using System;
using IronPdf;
using IronPdf.Rendering;
class IronPdfCustomSize
{
static void Main()
{
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.PaperSize = PdfPaperSize.Letter;
renderer.RenderingOptions.MarginTop = 50;
renderer.RenderingOptions.MarginBottom = 50;
var html = "<html><body><h1>Custom Size PDF</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("custom-size.pdf");
Console.WriteLine("Custom size PDF generated successfully");
}
}' NuGet: Install-Package IronPdf
Imports System
Imports IronPdf
Imports IronPdf.Rendering
Class IronPdfCustomSize
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.PaperSize = PdfPaperSize.Letter
renderer.RenderingOptions.MarginTop = 50
renderer.RenderingOptions.MarginBottom = 50
Dim html = "<html><body><h1>Custom Size PDF</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("custom-size.pdf")
Console.WriteLine("Custom size PDF generated successfully")
End Sub
End Class' NuGet: Install-Package IronPdf
Imports System
Imports IronPdf
Imports IronPdf.Rendering
Class IronPdfCustomSize
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.PaperSize = PdfPaperSize.Letter
renderer.RenderingOptions.MarginTop = 50
renderer.RenderingOptions.MarginBottom = 50
Dim html = "<html><body><h1>Custom Size PDF</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("custom-size.pdf")
Console.WriteLine("Custom size PDF generated successfully")
End Sub
End ClassGotenberg는 문자열 기반 매개변수 ("8.5", "11", "0.5")를 멀티파트 폼 데이터에 추가해야 하며 - 형식 안전성과 IntelliSense가 없고 잘못 입력하기 쉬움. IronPDF는 PdfPaperSize 열거형과 숫자형 마진 값을 통해 강력한 타입의 속성을 제공합니다.IronPDF여백은 밀리미터로 표시되며 (50mm ≈ 2인치), Gotenberg는 인치를 사용한다는 점에 유의하십시오.
중요한 마이그레이션 노트
단위 변환
이번Gotenberg마이그레이션에서 가장 중요한 변환은 여백 단위입니다:
// Gotenberg: margins in inches
content.Add(new StringContent("0.5"), "marginTop"); // 0.5 inches
content.Add(new StringContent("1"), "marginBottom"); // 1 inch
// IronPDF: margins in millimeters
renderer.RenderingOptions.MarginTop = 12.7; // 0.5 inches × 25.4 = 12.7mm
renderer.RenderingOptions.MarginBottom = 25.4; // 1 inch × 25.4 = 25.4mm// Gotenberg: margins in inches
content.Add(new StringContent("0.5"), "marginTop"); // 0.5 inches
content.Add(new StringContent("1"), "marginBottom"); // 1 inch
// IronPDF: margins in millimeters
renderer.RenderingOptions.MarginTop = 12.7; // 0.5 inches × 25.4 = 12.7mm
renderer.RenderingOptions.MarginBottom = 25.4; // 1 inch × 25.4 = 25.4mm' Gotenberg: margins in inches
content.Add(New StringContent("0.5"), "marginTop") ' 0.5 inches
content.Add(New StringContent("1"), "marginBottom") ' 1 inch
' IronPDF: margins in millimeters
renderer.RenderingOptions.MarginTop = 12.7 ' 0.5 inches × 25.4 = 12.7mm
renderer.RenderingOptions.MarginBottom = 25.4 ' 1 inch × 25.4 = 25.4mm' Gotenberg: margins in inches
content.Add(New StringContent("0.5"), "marginTop") ' 0.5 inches
content.Add(New StringContent("1"), "marginBottom") ' 1 inch
' IronPDF: margins in millimeters
renderer.RenderingOptions.MarginTop = 12.7 ' 0.5 inches × 25.4 = 12.7mm
renderer.RenderingOptions.MarginBottom = 25.4 ' 1 inch × 25.4 = 25.4mm변환 공식: millimeters = inches × 25.4
동기 대 비동기
Gotenberg는 HTTP 통신으로 인해 비동기 작업이 필요합니다:
// Gotenberg: Forced async due to network calls
var response = await client.PostAsync(gotenbergUrl, content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
// IronPDF: Synchronous in-process execution
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
// IronPDF: Async wrapper if needed
var pdf = await Task.Run(() => renderer.RenderHtmlAsPdf(html));// Gotenberg: Forced async due to network calls
var response = await client.PostAsync(gotenbergUrl, content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
// IronPDF: Synchronous in-process execution
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
// IronPDF: Async wrapper if needed
var pdf = await Task.Run(() => renderer.RenderHtmlAsPdf(html));Imports System.Net.Http
' Gotenberg: Forced async due to network calls
Dim response = Await client.PostAsync(gotenbergUrl, content)
Dim pdfBytes = Await response.Content.ReadAsByteArrayAsync()
' IronPDF: Synchronous in-process execution
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
' IronPDF: Async wrapper if needed
Dim pdf = Await Task.Run(Function() renderer.RenderHtmlAsPdf(html))Imports System.Net.Http
' Gotenberg: Forced async due to network calls
Dim response = Await client.PostAsync(gotenbergUrl, content)
Dim pdfBytes = Await response.Content.ReadAsByteArrayAsync()
' IronPDF: Synchronous in-process execution
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
' IronPDF: Async wrapper if needed
Dim pdf = Await Task.Run(Function() renderer.RenderHtmlAsPdf(html))오류 처리
// Gotenberg: HTTP error handling
try
{
var response = await client.PostAsync(gotenbergUrl, content);
response.EnsureSuccessStatusCode(); // What if 500? 503? Timeout?
}
catch (HttpRequestException ex) { /* Network error */ }
catch (TaskCanceledException ex) { /* Timeout */ }
// IronPDF: Standard .NET exceptions
try
{
var pdf = renderer.RenderHtmlAsPdf(html);
}
catch (Exception ex)
{
Console.WriteLine($"PDF generation failed: {ex.Message}");
}// Gotenberg: HTTP error handling
try
{
var response = await client.PostAsync(gotenbergUrl, content);
response.EnsureSuccessStatusCode(); // What if 500? 503? Timeout?
}
catch (HttpRequestException ex) { /* Network error */ }
catch (TaskCanceledException ex) { /* Timeout */ }
// IronPDF: Standard .NET exceptions
try
{
var pdf = renderer.RenderHtmlAsPdf(html);
}
catch (Exception ex)
{
Console.WriteLine($"PDF generation failed: {ex.Message}");
}Imports System
Imports System.Net.Http
Imports System.Threading.Tasks
' Gotenberg: HTTP error handling
Try
Dim response = Await client.PostAsync(gotenbergUrl, content)
response.EnsureSuccessStatusCode() ' What if 500? 503? Timeout?
Catch ex As HttpRequestException
' Network error
Catch ex As TaskCanceledException
' Timeout
End Try
' IronPDF: Standard .NET exceptions
Try
Dim pdf = renderer.RenderHtmlAsPdf(html)
Catch ex As Exception
Console.WriteLine($"PDF generation failed: {ex.Message}")
End TryImports System
Imports System.Net.Http
Imports System.Threading.Tasks
' Gotenberg: HTTP error handling
Try
Dim response = Await client.PostAsync(gotenbergUrl, content)
response.EnsureSuccessStatusCode() ' What if 500? 503? Timeout?
Catch ex As HttpRequestException
' Network error
Catch ex As TaskCanceledException
' Timeout
End Try
' IronPDF: Standard .NET exceptions
Try
Dim pdf = renderer.RenderHtmlAsPdf(html)
Catch ex As Exception
Console.WriteLine($"PDF generation failed: {ex.Message}")
End Try인프라 제거
마이그레이션 후 인프라에서 Gotenberg를 제거하십시오:
# REMOVE from docker-compose.yml:
# services:
# gotenberg:
# image: gotenberg/gotenberg:8
# ports:
# - "3000:3000"
# deploy:
# resources:
# limits:
# memory: 2G
성능 고려 사항
지연 시간 비교
| 작업 | Gotenberg (웜) | Gotenberg (콜드 스타트) | IronPDF (첫 번째 렌더) | IronPDF (후속) |
|---|---|---|---|---|
| 간단한 HTML | 150-300ms | 2-5초 | 1-2초 | 50-150ms |
| 복잡한 HTML | 500-1500ms | 3-7초 | 1.5-3초 | 200-800ms |
| URL 렌더링 | 1-5초 | 3-10초 | 1-5초 | 500ms-3s |
인프라 비용 제거
| 의지 | Gotenberg | IronPDF |
|---|---|---|
| 필요한 컨테이너 | 1-N (확장) | 0 |
| 컨테이너별 메모리 | 512MB-2GB | 해당 없음 |
| 요청당 네트워크 오버헤드 | 10-100ms | 0ms |
| 상태 검사 엔드포인트 | 필요함 | 필요 없음 |
| 로드 밸런서 | 자주 필요 | 필요 없음 |
문제 해결
문제 1: HttpClient 패턴 불필요
문제: 코드가 여전히 HttpClient 및 MultipartFormDataContent를 사용하고 있습니다.
해결책: ChromePdfRenderer으로 완전히 교체하십시오:
// Remove all of this:
// using var client = new HttpClient();
// using var content = new MultipartFormDataContent();
// content.Add(new StringContent(html), "files", "index.html");
// var response = await client.PostAsync(url, content);
// Replace with:
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);// Remove all of this:
// using var client = new HttpClient();
// using var content = new MultipartFormDataContent();
// content.Add(new StringContent(html), "files", "index.html");
// var response = await client.PostAsync(url, content);
// Replace with:
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(html)Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(html)문제 2: 여백 단위 오류
문제: 마이그레이션 후 PDF의 여백이 잘못되었습니다.
해결책: 인치를 밀리미터로 변환:
//Gotenbergused inches: "0.5"
//IronPDF uses millimeters: 0.5 × 25.4 = 12.7
renderer.RenderingOptions.MarginTop = 12.7;//Gotenbergused inches: "0.5"
//IronPDF uses millimeters: 0.5 × 25.4 = 12.7
renderer.RenderingOptions.MarginTop = 12.7;' Gotenbergused inches: "0.5"
' IronPDF uses millimeters: 0.5 × 25.4 = 12.7
renderer.RenderingOptions.MarginTop = 12.7' Gotenbergused inches: "0.5"
' IronPDF uses millimeters: 0.5 × 25.4 = 12.7
renderer.RenderingOptions.MarginTop = 12.7문제 3: 컨테이너 URL 참조
문제: 코드에 http://gotenberg:3000 또는 비슷한 URL이 포함되어 있습니다.
해결책: 모든 컨테이너 URL 참조를 제거하십시오. IronPDF는 프로세스 내에서 실행됩니다:
// Remove:
// private readonly string _gotenbergUrl = "http://gotenberg:3000";
//IronPDF needs no URL - it's in-process
var renderer = new ChromePdfRenderer();// Remove:
// private readonly string _gotenbergUrl = "http://gotenberg:3000";
//IronPDF needs no URL - it's in-process
var renderer = new ChromePdfRenderer();' Remove:
' Private ReadOnly _gotenbergUrl As String = "http://gotenberg:3000"
' IronPDF needs no URL - it's in-process
Dim renderer As New ChromePdfRenderer()' Remove:
' Private ReadOnly _gotenbergUrl As String = "http://gotenberg:3000"
' IronPDF needs no URL - it's in-process
Dim renderer As New ChromePdfRenderer()마이그레이션 체크리스트
사전 마이그레이션
- 코드베이스의 모든GotenbergHTTP 호출 인벤토리
- 현재Gotenberg구성 문서화 (타임아웃, 여백, 용지 크기)
- 모든 Docker/KubernetesGotenberg구성 식별 -IronPDF라이센스 키를 받으세요
- 인프라 폐기 계획
코드 마이그레이션
-IronPDF NuGet Install-Package: dotnet add package IronPdf
-Gotenberg클라이언트 패키지 제거
- 모든 Gotenberg에 대한 HTTP 호출을IronPDF메소드 호출로 대체
- 여백 단위를 인치에서 밀리미터로 변환
- 오류 처리 업데이트 (HTTP 오류 → .NET 예외)
- 시작 시 라이선스 키 초기화 추가
인프라 마이그레이션
- Docker Compose / Kubernetes에서Gotenberg제거
- CI/CD 파이프라인 업데이트 (Gotenberg 이미지 풀 제거) -Gotenberg상태 검사 제거
- 구성에서GotenbergURL 제거
테스트
- HTML을 PDF로 변환 테스트
- URL을 PDF로 변환 테스트
- 여백 및 크기 정확성 확인
- 부하 조건에서 성능 테스트
- 첫 렌더링 워밍업 시간 테스트
마이그레이션 이후
-Gotenberg컨테이너 배포 제거 -Gotenberg구성 파일 아카이브
- 문서 업데이트
- 애플리케이션 메모리 사용 모니터링
- 고립된 네트워크 연결 확인
커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.
관련 기사


