Altbilgi içeriğine atla
GEçIş KıLAVUZLARı

Gotenberg'den IronPDF'e C# ile Nasıl Geçilir

Gotenberg'den IronPDF'e geçiş, .NET PDF iş akışınızı HTTP API çağrıları ile Docker tabanlı mikrosite mimarisinden, yerel C# kitaplığına dönüştürür. Bu kılavuz, altyapı yükünü, ağ gecikmesini ve kap yönetim karmaşıklığını ortadan kaldıran, profesyonel .NET geliştiricileri için kapsamlı, adım adım bir geçiş yolu sağlar.

Neden Gotenberg'den IronPDF'e Geçiş Yapılmalı

Gotenberg Mimari Sorunu

Gotenberg, PDF oluşturma için Docker tabanlı bir mikro hizmet mimarisidir. Güçlü ve esnek olmasına rağmen, C# uygulamaları için önemli bir karmaşıklık getirir:

  1. Altyapı Yükü: Docker, konteynır orkestrasyonu (Kubernetes/Docker Compose), servis keşfi ve yük dengeleme gerektirir. Her dağıtım daha karmaşık hale gelir.

  2. Ağ Gecikmesi: Her PDF işlemi, başka bir servise bir HTTP çağrısı gerektirir - her istek başına 10-100ms+ eklenir. Bu gecikme, yüksek hacimli senaryolarda hızla artar.

  3. Soğuk Başlangıç Sorunları: Konteynırın başlangıcı, ilk isteklere 2-5 saniye ekleyebilir. Her pod yeniden başlatma, her ölçeklenme olayı ve her dağıtım soğuk başlangıçları tetikler.

  4. Operasyonel Karmaşıklık: Kap sağlığı, ölçekleme, günlükleme ve izleme, ana uygulamanızdan ayrı endişeler olarak yönetilmelidir.

  5. Multipart Form Verisi: Her istek, çok parçalı/form-veri yükleri oluşturmayı gerektirir - ayrıntılı, hata eğilimli ve bakımı zahmetli.

  6. Hata Noktaları: Ağ zaman aşımı, hizmetin kullanılamaması ve kap çökmeleri, sizin için taşımanız gereken sorumluluklar haline gelir.

  7. Sürüm Yönetimi:Gotenberggörüntüleri uygulamanızdan ayrı olarak güncellenir; API değişiklikleri beklenmedik şekilde entegrasyonları bozabilir.

Gotenberg ve IronPDF Karşılaştırması

Aspekt Gotenberg IronPDF
Dağıtım Docker konteyneri + orkestrasyon Tek bir NuGet paketi
Mimari Mikroservis (REST API) İşlem içi kütüphane
İstek başına gecikme 10-100ms+ (ağ gidiş-dönüş) < 1ms ek yük
Soğuk başlangıç 2-5 saniye (konteyner başlatma) Sadece ilk işleme için 1-2 saniye
Altyapı Docker, Kubernetes, yük dengeleyiciler Gerekli değil
Başarısızlık Modları Ağ, konteyner, hizmet hataları Standart .NET istisnaları
API Tarzı REST multipart/form-data Yerel C# yöntemi çağrıları
Ölçeklendirme Yatay (daha fazla konteyner) Dikey (işlem içi)
Hata Ayıklama Dağıtılmış izleme gerekti Standart hata ayıklayıcı
Sürüm Kontrolü Konteyner imaj etiketleri NuGet paket sürümleri

Güncel .NET sürümlerini hedefleyen ekipler için IronPDF, modern .NET kalıplarıyla entegre olan ve sıfır altyapı bağımlılığı ile bir temel sağlar.


Göç Karmaşıklığı Değerlendirmesi

Özelliklere Göre Tahmini Çaba

Özellik Göç Karmaşıklığı
HTML'den PDF'ye Çok Düşük
URL'yi PDF'ye çevir Çok Düşük
Özel Kağıt Boyutu Düşük
Kenar Boşlukları Düşük
PDF Birleştirme Düşük
Başlıklar/Altbilgiler Orta
Bekleme Gecikmeleri Düşük
PDF/A Dönüşümü Düşük

Paradigma Değişimi

HTTP API çağrıları ile multipart form verileri yerine yerel C# yöntem çağrıları:Gotenberggeçişindeki temel değişiklik budur:

Gotenberg: HTTP POST multipart/form-veri ile Docker konteynırına
IronPDF: C# nesneleri üzerinde doğrudan yöntem çağrıları

Başlamadan Önce

Ön Koşullar

  1. .NET Sürümü: IronPDF, .NET Framework 4.6.2+ ve .NET Core 3.1+ / .NET 5/6/7/8/9+ destekler
  2. Lisans Anahtarı:IronPDF lisans anahtarınızı ironpdf.com'dan edinin
  3. Altyapı Kaldırma Planı: Geçiş sonrası içinGotenbergkonteynırlarını belgeleyin

TümGotenbergKullanımını Belirleyin

# 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" .
# 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" .
SHELL

NuGet Paket Değişiklikleri

# RemoveGotenbergclient (if using)
dotnet remove package Gotenberg.Sharp.API.Client

# Install IronPDF
dotnet add package IronPdf
# RemoveGotenbergclient (if using)
dotnet remove package Gotenberg.Sharp.API.Client

# Install IronPDF
dotnet add package IronPdf
SHELL

Hızlı Başlangıç Göçü

Adım 1: Lisans Yapılandırmasını Güncelleyin

Önce (Gotenberg):

Gotenberg lisans gerektirmez ancak Docker altyapısını konteynır URL'leri ile gerektirir.

private readonly string _gotenbergUrl = "http://localhost:3000";
private readonly string _gotenbergUrl = "http://localhost:3000";
Private ReadOnly _gotenbergUrl As String = "http://localhost:3000"
$vbLabelText   $csharpLabel

Sonrası (IronPDF):

// Set once at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
// Set once at application startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
$vbLabelText   $csharpLabel

Adım 2: Ad Alanı İthalatlarını Güncelleyin

// 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.Rendering
$vbLabelText   $csharpLabel

Tam API Referansı

Gotenberg Uç Noktası ve IronPDF Haritalaması

Gotenberg Güzergahı IronPDF Eşdeğeri
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() ile ayarlar
GET /health Yok

Form Parametresinden RenderingOptions Eşleme

Gotenberg Parametresi IronPDF Özelliği Dönüşüm Notları
paperWidth (inç) RenderingOptions.PaperSize Enum veya özelleştirilmiş boyut kullanın
paperHeight (inç) RenderingOptions.PaperSize Enum veya özelleştirilmiş boyut kullanın
marginTop (inç) RenderingOptions.MarginTop mm için 25.4 ile çarpın
marginBottom (inç) RenderingOptions.MarginBottom mm için 25.4 ile çarpın
printBackground RenderingOptions.PrintHtmlBackgrounds Boolean
landscape RenderingOptions.PaperOrientation Landscape enum
waitDelay (ör. "3s") RenderingOptions.WaitFor.RenderDelay(ms) Dizeyi milisaniyeye çevir

Kod Göç Örnekleri

Örnek 1: Temel HTML'den PDF'ye

Önce (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
    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>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
$vbLabelText   $csharpLabel

Sonrası (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");
    }
}
Imports System
Imports IronPdf

Class IronPdfExample
    Shared 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 Class
$vbLabelText   $csharpLabel

Fark oldukça büyük: Gotenberg, bir HttpClient inşa etmeyi, MultipartFormDataContent oluşturmayı, çalışan bir Docker konteynerine asenkron bir HTTP POST yapmayı ve byte array yanıtı işlemesini gerektirir.IronPDF bunu bir ChromePdfRenderer metot çağrısıyla üç satıra indirir—ağ yükü yok, konteyner bağımlılığı yok, asenkron karmaşıklık yok. HTML'den PDF'ye belgelemeyi ek işleme seçenekleri için inceleyin.

Örnek 2: URL'den PDF'ye Dönüştürme

Önce (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 As String = "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 As HttpResponseMessage = Await client.PostAsync(gotenbergUrl, content)
                Dim pdfBytes As Byte() = 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
$vbLabelText   $csharpLabel

Sonrası (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");
    }
}
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
$vbLabelText   $csharpLabel

Gotenberg yaklaşımı farklı bir uç nokta (/forms/chromium/convert/url) gerektirir, URL'yi bir form alanı olarak çok parçalı içerik oluşturmayı ve asenkron HTTP yanıtlarını işlemesini içerir. IronPDF'nin RenderUrlAsPdf() metodu URL'yi doğrudan kabul eder ve senkron olarak bir PdfDocument nesnesi döndürür. URL'den PDF'e dönüştürme hakkında daha fazla bilgi edinin.

Örnek 3: Özel Kağıt Boyutu ve Marjlar

Önce (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 Class
$vbLabelText   $csharpLabel

Sonrası (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");
    }
}
Imports System
Imports IronPdf
Imports IronPdf.Rendering

Module IronPdfCustomSize

    Sub Main()
        Dim renderer As New ChromePdfRenderer()

        renderer.RenderingOptions.PaperSize = PdfPaperSize.Letter
        renderer.RenderingOptions.MarginTop = 50
        renderer.RenderingOptions.MarginBottom = 50

        Dim html As String = "<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 Module
$vbLabelText   $csharpLabel

Gotenberg, çok parçalı form verilerine eklenen dize tabanlı parametreler ("8.5", "11", "0.5") gerektirir—tip güvenliği yok, IntelliSense yok, yazım hatası yapması kolay. IronPDF, PdfPaperSize enum'ları ve sayısal marj değerleri ile güçlü şekilde tiplenen özellikler sağlar.IronPDF marjlarının milimetre biriminde olduğunu ve Gotenberg'in inç kullandığını unutmayın (50 mm ≈ 2 inç).


Kritik Taşıma Notları

Birim Dönüşümleri

BuGotenberggeçişindeki en önemli dönüşüm marj birimleridir:

// 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
$vbLabelText   $csharpLabel

Dönüşüm formülü: millimeters = inches × 25.4

Senkron ve Asenkron

Gotenberg, HTTP iletişimi nedeniyle asenkron işlemler gerektirir:

// 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))
$vbLabelText   $csharpLabel

Hata Yönetimi

// 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 Try
$vbLabelText   $csharpLabel

Altyapının Kaldırılması

Geçişten sonra altyapınızdan Gotenberg'i kaldırın:

# REMOVE from docker-compose.yml:
# services:
#   gotenberg:
#     image: gotenberg/gotenberg:8
#     ports:
#       - "3000:3000"
#     deploy:
#       resources:
#         limits:
#           memory: 2G
# REMOVE from docker-compose.yml:
# services:
#   gotenberg:
#     image: gotenberg/gotenberg:8
#     ports:
#       - "3000:3000"
#     deploy:
#       resources:
#         limits:
#           memory: 2G
YAML

Performans Dikkat Edilecek Hususlar

Gecikme Karşılaştırması

İşlem Gotenberg(Sıcak) Gotenberg (Soğuk Başlatma) IronPDF (İlk İşleme) IronPDF (Sonraki)
Basit HTML 150-300ms 2-5 saniye 1-2 saniye 50-150ms
Karmaşık HTML 500-1500ms 3-7 saniye 1.5-3 saniye 200-800ms
URL İşleme 1-5 saniye 3-10 saniye 1-5 saniye 500ms-3s

Altyapı Maliyet Eliminasyonu

Kaynak Gotenberg IronPDF
Gereken Kaplar 1-N (ölçekleme) 0
Konteynır başına bellek 512MB-2GB Yok
İstek başına ağ yükü 10-100ms 0ms
Sağlık kontrol uç noktaları Gereklidir Gerekli değil
Yük dengeleme Sıklıkla gerekli Gerekli değil

Hata Ayıklama

Sorun 1: HttpClient Modelleri Gerekli Değil

Problem: Kod hala HttpClient ve MultipartFormDataContent kullanıyor.

Çözüm: Tamamen ChromePdfRenderer ile değiştirin:

// 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)
$vbLabelText   $csharpLabel

Sorun 2: Marj Birimleri Yanlış

Problem: Geçişten sonra PDF'lerde hatalı marjlar var.

Çözüm: İnçleri milimetrelere dönüştürün:

//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
$vbLabelText   $csharpLabel

Sorun 3: Kap URL Referansları

Problem: Kod http://gotenberg:3000 veya benzer URL'ler içeriyor.

Çözüm: Tüm konteyner URL referanslarını kaldırın—IroPDF, süreç içinde çalışır:

// 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()
$vbLabelText   $csharpLabel

Geçiş Kontrol Listesi

Öncesi-Geçiş

  • Kod tabanındaki tümGotenbergHTTP çağrılarını envanterleyin.
  • GeçerliGotenbergyapılandırmasını belgeleyin (zaman aşımı, kenar boşlukları, kâğıt boyutları).
  • Tüm Docker/KubernetesGotenbergyapılandırmasını belirleyin. -IronPDF lisans anahtarını edinin
  • Altyapı kaldırmayı planlayın.

Kod Geçişi

-IronPDF NuGet paketini yükleyin: dotnet add package IronPdf -Gotenbergistemci paketlerini kaldırın.

  • Gotenberg'e yapılan tüm HTTP çağrılarınıIronPDF yöntem çağrıları ile değiştirin.
  • Kenar boşluğu birimlerini inçten milimetreye çevirin.
  • Hata işleme yöntemini güncelleyin (HTTP hataları → .NET istisnaları).
  • Başlangıçta lisans anahtarı başlatmasını ekleyin.

Altyapı Geçişi

  • Gotenberg'i Docker Compose/Kubernetes'ten kaldırın.
  • CI/CD hatlarını güncelleyin (Gotenberg imaj çekimlerini kaldırın). -Gotenbergsağlık kontrollerini kaldırın.
  • YapılandırmadanGotenbergURL'sini kaldırın.

Test Etme

  • HTML'den PDF'e dönüştürmeyi test edin
  • URL'den PDF'e dönüştürmeyi test edin
  • Kenar boşluğu ve boyut doğruluğunu doğrulayın.
  • Yük altında performans testi yapın
  • İlk-render ısınma süresini test edin.

Geçiş Sonrası

-Gotenbergkonteyner dağıtımlarını kaldırın. -Gotenbergyapılandırma dosyalarını arşivleyin.

  • Belgeleri güncelleyin
  • Uygulama bellek kullanımını izleyin.
  • Kimsesiz ağ bağlantılarının olmadığını doğrulayın.

Lütfen dikkate alınGotenberg, ilgili sahibinin tescilli markasıdır. Bu site,Gotenbergile bağlı, onaylı veya sponsorlu değildir. Tüm ürün adları, logolar ve markalar ilgili sahiplerine aittir. Karşılaştırmalar, yalnızca bilgilendirme amaçlıdır ve yazı sırasında halka açık bilgilerle alakalı olarak yansıtılmaktadır.

Curtis Chau
Teknik Yazar

Curtis Chau, Bilgisayar Bilimleri alanında Lisans Derecesine (Carleton Üniversitesi) sahip ve Node.js, TypeScript, JavaScript ve React konularında uzmanlaşmış ön uç geliştirmeyle ilgileniyor. Sezgisel ve estetik açıdan hoş kullanıcı arayüzleri oluşturma tutkunu, Curtis modern çerçevelerle çalışmayı ve iyi yapı...

Daha Fazla Oku

Iron Destek Ekibi

Haftada 5 gün, 24 saat çevrimiçiyiz.
Sohbet
E-posta
Beni Ara