IronPDF kullanarak C#'ta PDF Dosyalarını Yazdırma
PDF en yaygın kullanılan dosya formatıdır. Hafiftir ve çoğu işletim sistemi tarafından desteklenir. PDF dosyaları bir cihazdan diğerine kolayca paylaşılabilir. Herhangi bir arayüz ve işletim sisteminde tamamen aynı göründükleri için okuma kolaylığı sağlarlar. PDF'ler mobil, tablet gibi tüm cihazlardan erişilebilir.
Popülariteleri, tüm C# geliştiricilerinin PDF dosyalarını C# kullanarak nasıl yazdıracaklarını bilmelerini gerektirir. Bir belge, örneğin bir fatura, maaş bordrosu, sipariş fişi veya profil gibi bir belgeyi yazdırmanız gerektiğinde karşılaşabileceğiniz bir sorun nedeniyle, C# kullanarak PDF dosyalarını nasıl yazdıracağımızı bilmemiz gerekiyor.
C#'ta PDF belgelerini yazdırmak için birden fazla kütüphane kullanılabilir. Ancak, karşılaşabileceğiniz bir sorun lisans ücreti olabilir. Çoğu ücretsiz değildir veya kullanımı zor olabilir. Ama neyse ki, endişelenmenize gerek yok. C#'ta PDF dosyalarını yazdırmanın en kolay ve basit yolunu buldum.
I will use the IronPDF Library to print PDF documents. Bana inanın, çok beğeneceksiniz!
Bu makaleden ne elde edeceksiniz?
Bu makaleyi okuduktan sonra, aşağıdaki görevleri yapabileceksiniz:
- C# ile tekli PDF belgeleri yazdırın
- C# kullanarak tek seferde birden fazla PDF dosyasını yazdırın
- Bir URL'yi PDF'ye dönüştürün ve ardından yazdırın.
Bu eğitimi daha iyi anlamak için C# programlaması hakkında temel bilgiye sahip olmalısınız.
Eğitime başlamadan önce, IronPDF'in ne olduğunu anlayalım.
IronPDF:
IronPDF, PDF dosyalarını okumanın, oluşturmanın, manipüle etmenin ve yazdırmanın en basit yolunu sağlayan bir .NET Kütüphanesidir. Bu kütüphane, C# ve VB .NET uygulamalarında kullanılabilir. Hem .NET hem de .NET core üzerinde ASP .NET, ASP .NET core, MVC, Web Formları ve Web API'leri ile kolayca çalışır. Kullanıcıların PDF dosyalarını indirmelerine, e-posta ile göndermelerine ve bulutta saklamalarına olanak tanır.
Bu bağlantıyı kullanarak IronPDF hakkında daha fazla bilgi edinebilirsiniz.
Demonstrasyona başlayalım.
Visual Studio'yu Açın
Visual Studio'yu açın. Yeni bir proje oluşturun veya mevcut yazılımınıza bu işlevselliği ekleyecekseniz, mevcut bir projeyi açın.
Bu eğitim için Konsol Uygulaması kullanıyorum; yazılım gereksinimlerinize göre istediğiniz herhangi birini kullanabilirsiniz.
Proje Oluşturuldu.
NuGet Paketi Yükleyin
Open the console by clicking on Tools > NuGet Package Manager > Package Manager Konsol from the Menu bar on the top of the window.
NuGet Paket Yöneticisi Konsolu aşağıda gösterildiği gibi açılacaktır:
NuGet Paket Yonetici Konsolu
Write the following command in the console to Install IronPdf NuGet Package and press Enter.
Install-Package IronPrint
NuGet Paketi aşağıda gösterildiği gibi yüklenecektir:
NuGet Paketini Yükleyin
Print PDF Filed in C
Şimdi, IronPDF Kütüphanesi'ni kullanarak C#'ta bir PDF dosyasını nasıl yazdırabileceğimizi göstermek için bir örnek ele alalım.
Open Program.cs dosyasini acin. IronPDF kullanmak icin Program.cs dosyasinin en ustune asagidaki namespace'i ekleyin:
using IronPdf;
using IronPdf;
Imports IronPdf
Simdi, Main fonksiyonu icine kodu yazin:
using System; // Required for Konsol operations
class Program
{
static void Main()
{
// Load the PDF document from file
using PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf");
// Print the loaded PDF document to the default printer
pdfDocument.Print();
// Print operation success message to console
Konsol.WriteLine("File Printed Successfully!");
Konsol.ReadKey();
}
}
using System; // Required for Konsol operations
class Program
{
static void Main()
{
// Load the PDF document from file
using PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf");
// Print the loaded PDF document to the default printer
pdfDocument.Print();
// Print operation success message to console
Konsol.WriteLine("File Printed Successfully!");
Konsol.ReadKey();
}
}
Imports System ' Required for Konsol operations
Class Program
Shared Sub Main()
' Load the PDF document from file
Using pdfDocument As PdfDocument = PdfDocument.FromFile("D:\Sample.pdf")
' Print the loaded PDF document to the default printer
pdfDocument.Print()
End Using
' Print operation success message to console
Konsol.WriteLine("File Printed Successfully!")
Konsol.ReadKey()
End Sub
End Class
Kodu anlayalım.
- Aşağıdaki kod satırı, PDF dosyasını belleğe yükleyecektir. "Sample.Pdf" dosya adı ve D Sürücüsü dosya konumumdur. Dosya adı ile birlikte tam bir dosya yolunu yazmalısınız.
using PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf");
using PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf");
Using pdfDocument As PdfDocument = PdfDocument.FromFile("D:\Sample.pdf")
End Using
Print()fonksiyonu, yuklu dosyayi varsıyılan yaziciniz ile yazdiracaktir.
Programı Test Edin
Programı çalıştırmak için Ctrl + F5 tuşlarına basın.
Konsol
Print Multiple PDF Documents in C
IronPDF kullanarak C# dilinde birden fazla PDF belgesi nasıl yazdırılacağını göstereceğim.
14 PDF dosyası
Bu örnekte, yazdırmam gereken 14 PDF belgem var. Onları 1 - 14 olarak numaralandırdım. Tüm dosyalarınızı bir ID ile kaydedebilir veya dosya konumunu bir veritabanında saklayabilirsiniz. Dosya Yolu ve Dosya Adını veritabanından çıkarın ve bir dizi veya liste içinde saklayın. Tüm dosyalarınızı yazdırmak için bu dizi veya listeyi yineleyin.
Asagidaki kodu Main fonksiyonu icine yazin:
using System; // Required for Konsol operations
class Program
{
static void Main()
{
// Loop through each file number and print
for (int i = 1; i <= 14; i++)
{
// Load each PDF document from file
using PdfDocument pdfDocument = PdfDocument.FromFile($@"D:\Print\{i}.pdf");
// Inform which file is being printed
Konsol.WriteLine("Printing File: {0}.pdf", i);
// Print the loaded PDF document to the default printer
pdfDocument.Print();
// Print operation success message to console
Konsol.WriteLine("{0}.pdf Printed Successfully!", i);
}
Konsol.ReadKey();
}
}
using System; // Required for Konsol operations
class Program
{
static void Main()
{
// Loop through each file number and print
for (int i = 1; i <= 14; i++)
{
// Load each PDF document from file
using PdfDocument pdfDocument = PdfDocument.FromFile($@"D:\Print\{i}.pdf");
// Inform which file is being printed
Konsol.WriteLine("Printing File: {0}.pdf", i);
// Print the loaded PDF document to the default printer
pdfDocument.Print();
// Print operation success message to console
Konsol.WriteLine("{0}.pdf Printed Successfully!", i);
}
Konsol.ReadKey();
}
}
Imports System ' Required for Konsol operations
Class Program
Shared Sub Main()
' Loop through each file number and print
For i As Integer = 1 To 14
' Load each PDF document from file
Using pdfDocument As PdfDocument = PdfDocument.FromFile($"D:\Print\{i}.pdf")
' Inform which file is being printed
Konsol.WriteLine("Printing File: {0}.pdf", i)
' Print the loaded PDF document to the default printer
pdfDocument.Print()
' Print operation success message to console
Konsol.WriteLine("{0}.pdf Printed Successfully!", i)
End Using
Next
Konsol.ReadKey()
End Sub
End Class
Dosya adlarıma göre 1'den 14'e kadar sayılar oluşturmak için bir for döngüsü kullandım.
Çözümü Çalıştırın:
Programı çalıştırmak için Ctrl + F5 tuşlarına basın.
Konsol
URL'yi PDF'ye Dönüştürün ve Yazdırın:
URL'leri IronPDF'ye çözümleyerek bir web sayfasını nasıl yazdıracağınızı göstereceğim. Kütüphane, HTML'yi çözümleyerek bir PDF dosyası oluşturacak. Yazdırma işlevini kullanarak bu PDF belgesini yazdırabiliriz. Bir örnek düşünelim.
Ana fonksiyonun içine aşağıdaki kodu yazın:
using System; // Required for Konsol operations
class Program
{
static void Main()
{
// HTML to PDF Renderer
IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
// Inform about the printing operation
Konsol.WriteLine("Printing File");
// Render URL as PDF
using PdfDocument PdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/how-to/print-pdf/#advanced-printing");
// Print the PDF document
PdfDocument.Print();
// Print operation success message to console
Konsol.WriteLine("File Printed Successfully!");
}
}
using System; // Required for Konsol operations
class Program
{
static void Main()
{
// HTML to PDF Renderer
IronPdf.HtmlToPdf Renderer = new IronPdf.HtmlToPdf();
// Inform about the printing operation
Konsol.WriteLine("Printing File");
// Render URL as PDF
using PdfDocument PdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/how-to/print-pdf/#advanced-printing");
// Print the PDF document
PdfDocument.Print();
// Print operation success message to console
Konsol.WriteLine("File Printed Successfully!");
}
}
Imports System ' Required for Konsol operations
Class Program
Shared Sub Main()
' HTML to PDF Renderer
Dim Renderer As New IronPdf.HtmlToPdf()
' Inform about the printing operation
Konsol.WriteLine("Printing File")
' Render URL as PDF
Using PdfDocument As PdfDocument = Renderer.RenderUrlAsPdf("https://ironpdf.com/how-to/print-pdf/#advanced-printing")
' Print the PDF document
PdfDocument.Print()
End Using
' Print operation success message to console
Konsol.WriteLine("File Printed Successfully!")
End Sub
End Class
Bu program https://ironpdf.com/how-to/print-pdf/#advanced-printing uzantisini PDF'e cevirir ve Print() fonksiyonu PDF'i varsıyılan yaziciyi kullanarak yazdirir.
Programı çalıştıralım.
Programı Çalıştırın:
Çözümü çalıştırmak için Ctrl + F5 tuşlarına basın.
Ekren üzerinde gösterilen çıktı
Print() fonksiyonu, belgeyi varsıyılan yaziciyi kullanarak yazdirir. Varsayılan yazıcıyı kullanmak istemediğimiz bir durum olabilir. Bu durumda, IronPDF, yazıcı adını değiştirmek için bize tek satırlık bir kod sağlar.
Yazıcı Adını Değiştirin:
Anlamak için bir örnek kullanacağız. Varsayılan yazıcıyı değiştirmek için bu kodu kullanın:
using System; // Required for Konsol operations
class Program
{
static void Main()
{
// Load the PDF document from file
PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf");
// Change to a different printer by name
pdfDocument.GetPrintDocument().PrinterSettings.PrinterName = "Microsoft Print to PDF";
// Print the PDF document
pdfDocument.Print();
// Print operation success message to console
Konsol.WriteLine("File Printed Successfully!");
}
}
using System; // Required for Konsol operations
class Program
{
static void Main()
{
// Load the PDF document from file
PdfDocument pdfDocument = PdfDocument.FromFile(@"D:\Sample.pdf");
// Change to a different printer by name
pdfDocument.GetPrintDocument().PrinterSettings.PrinterName = "Microsoft Print to PDF";
// Print the PDF document
pdfDocument.Print();
// Print operation success message to console
Konsol.WriteLine("File Printed Successfully!");
}
}
Imports System ' Required for Konsol operations
Class Program
Shared Sub Main()
' Load the PDF document from file
Dim pdfDocument As PdfDocument = PdfDocument.FromFile("D:\Sample.pdf")
' Change to a different printer by name
pdfDocument.GetPrintDocument().PrinterSettings.PrinterName = "Microsoft Print to PDF"
' Print the PDF document
pdfDocument.Print()
' Print operation success message to console
Konsol.WriteLine("File Printed Successfully!")
End Sub
End Class
Yazıcıyı belirlemek için sadece bir satır ek kod eklediğimi görebilirsiniz. Gösterim için Microsoft Print to PDF belirttim.
Programı Çalıştırın:
Ctrl + F5 tuşlarına basarak Programı çalıştırın.
Microsoft Print to PDF kullandığımız için bir dosya adı girmemizi isteyen aşağıdaki Diyalog Kutusu görünecektir.
Dosya adını belirleyin ve Kaydet butonuna tıklayın. "SamplePrint.Pdf" belirttim. Aşağıdaki konsol çıktısı görüntülenecek:
Microsoft Print to PDF, D Sürücümde bir PDF dosyası yazdırdı. Hadi bakalım.
Umarım bu eğitim sizin için faydalı, etkileşimli ve anlaşılması kolay olmuştur. Bu eğitmenlikle ilgili sorular sorabilir veya geri bildirimde bulunabilirsiniz.
Sıkça Sorulan Sorular
IronPDF kullanarak C#'ta bir PDF dosyasını nasıl yazdırırım?
C#'ta IronPDF kullanarak bir PDF dosyasını yazdırmak için, PdfDocument.FromFile metoduyla PDF belgesini yükleyin ve ardından yüklenen belge üzerinde Print metodunu çağırın.
IronPDF, birden çok PDF dosyasını sırayla yazdırmak için kullanılabilir mi?
Evet, IronPDF, bir dosya yolu koleksiyonunu döngüye sokarak ve her belge için Print metodunu çağırarak birden çok PDF dosyasını yazdırabilir.
Bir URL'yi PDF'ye nasıl dönüştürüp C#'ta yazdırabilirim?
IronPDF kullanarak, HtmlToPdf.RenderUrlAsPdf metoduyla URL'yi PDF'ye dönüştürün. Ardından, oluşturulan PDF belgesi üzerinde Print metodunu kullanarak yazdırın.
IronPDF ile PDF'leri yazdırmak üzere belirli bir yazıcı seçmek mümkün mü?
Evet, PdfDocument sınıfının GetPrintDocument metodunu kullanırken PrinterSettings nesnesi içinde PrinterName özelliğini ayarlayarak belirli bir yazıcı seçebilirsiniz.
IronPDF PDF yazdırma için hangi platformları destekler?
IronPDF, .NET Framework, .NET Core ve .NET 5 ve 6 uygulamaları üzerinde PDF yazdırmayı destekler ve Windows, macOS, Android ve iOS platformlarıyla uyumludur.
C#'ta bir .NET kütüphanesi kullanarak PDF yazdırmaya nasıl başlayabilirim?
IronPDF kullanarak PDF yazdırmaya başlamak için, Visual Studio'da NuGet Package Manager aracılığıyla kütüphaneyi kurun ve Iron Software tarafından sağlanan dokümantasyon ve örnekleri takip edin.
Doküman paylaşımı için PDF kullanmanın avantajları nelerdir?
PDF'ler hafif oldukları, farklı cihazlarda tutarlı bir format korudukları ve çoğu işletim sistemi tarafından desteklendikleri için doküman paylaşımı için avantajlıdır.
IronPDF'i yazdırmak için kullanmak için ileri düzey C# becerilerine ihtiyaçım var mı?
IronPDF'i yazdırma görevleri için kullanmak için temel C# bilgisi yeterlidir, çünkü kütüphane, geliştiricilere yardımcı olmak için basit yöntemler ve örnekler sunar.



