ASP.NET ile Pdf Oluşturma / Create Pdf with ASP.NET

Posted: March 21, 2010 in ASP.NET, Components
Tags: , ,

Merhabalar,

Hepimizin çok ihtiyacı olan bir konu sanırım. Herhangi bir dosyayı, bir URL’in içeriğini ya da içeriğini bizim belirleyebileceğimiz pdf dosyaları yapmak isteyebiliriz. Bu konu ile ilgili birkaç hazır component var. Ben de bunlardan WebSupergoo‘nun ABCpdf7 componentini kullanarak örnek yaptım.

Hello,

I think the issue is a need for all of us. We may want to create pdf files from a file, an Uri’s content or own customization. There are a few components to do that. I used WebSupergoo‘s ABCpdf7 component to creae this example.

using (WebSupergoo.ABCpdf7.Doc pdfDocument = new WebSupergoo.ABCpdf7.Doc())
{
        //theDoc.Rect.Inset(0, 0);

	pdfDocument.Page = pdfDocument.AddPage();
	int pageId = pdfDocument.AddImageUrl("http://www.google.com.tr/"); // Herhangi bir sitenin anasayfasının ekran görüntüsünü alıyorum. Ancak site içeriğinin uzunluğunu bilemeyebiliriz. O yüzden az sonra aşağıda görüntüyü sayfalara böleceğiz.
	// I want to get a screen shot from any web site. Maybe we don't have any idea about the page length that's why we seperate the picture to pages.
	while (true)
	{
		pdfDocument.FrameRect();
		if (!pdfDocument.Chainable(pageId))
		break;
		pdfDocument.Page = pdfDocument.AddPage();
		pageId = pdfDocument.AddImageToChain(pageId);
	}

    for (int i = 1; i <= pdfDocument.PageCount; i++)
	{
		pdfDocument.PageNumber = i;
		pdfDocument.Flatten();
	}

	string pdfFilePath = "testpdffile.pdf";

	pdfDocument.Save(pdfFilePath);
	pdfDocument.Clear();
}

Advertisement
Comments
  1. Aziz says:

    Dostum sen bu makale ile cennete bilet aldığının farkında mısın? :)

    • Nesim Tunç says:

      :)

  2. Ahmet says:

    ya bunu nası yapcaz kütüphaneyi bi bulup kullanamadım bir örneğini koyarmısınız?

  3. yeni says:

    örneği biraz daha açıklarmısınız
    çalıştıramadım
    (bu konu gerçekten çok önemli)

  4. Nesim Tunç says:

    İlgili siteden programı(dll’leri pc’inize kopyalayın) indirdikten sonra dll’leri projenize referans olarak ekledikten sonra yukardaki kodu kopyalarak yapabilirsiniz. Gerisi yani geliştirilmesi size kalmış.
    Kolay gelsin.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s