Click here to Skip to main content
11,812,712 members (68,843 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# itextsharp
Hello Friends,

I have to print windows form using in to PDF. I used itextsharp for print gridview but This time I need to print some label.
Is Itextsharp is good or should I use another one. and how can I print labels
Please Help me.


using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;

namespace ghm_scrum
    public partial class View_Incident : Form
        private void btnPrint_Click(object sender, EventArgs e)
            using (Bitmap b = new Bitmap(this.Width, this.Height))
                using (Graphics g = Graphics.FromImage(b))
                    g.CopyFromScreen(this.Location, new Point(0, 0), this.Size);
                Document doc = new Document();
                iTextSharp.text.Image i = iTextSharp.text.Image.GetInstance(b, System.Drawing.Imaging.ImageFormat.Bmp);
                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(@"D:\output.pdf", FileMode.Create));
                doc.SetPageSize(new iTextSharp.text.Rectangle(this.Size.Width + doc.LeftMargin + doc.RightMargin, this.Size.Height + doc.TopMargin + doc.BottomMargin));
I used this code but iTs print like screen shot.

Neetesh Agarwal
Posted 25-Mar-13 5:05am
Edited 25-Mar-13 5:11am
(no name)202.9K
Maciej Los at 25-Mar-13 11:14am
iTs print like screen shot. - what you expect for, if you print an image of form to pdf?
Write text of labels to pdf.
Neetesh Agarwal at 26-Mar-13 4:50am
I have a Panel in form , My need is show print that Panel and control inside that in PDF
Neetesh Agarwal at 25-Mar-13 11:16am
Yes, I dont want full form print. Only the labels not the Button. I am trying that
Sergey Alexandrovich Kryukov at 25-Mar-13 11:49am
Why? Print data, not the form. Or do you need something like a screen shot? Why not using a bitmap then?
Neetesh Agarwal at 26-Mar-13 4:50am
I have a Panel in form , My need is show print that Panel and control inside that in PDF
Sergey Alexandrovich Kryukov at 26-Mar-13 10:03am
Print the data shown in the form, not the form. You did not explain the purpose of the print, this is the key.
Neetesh Agarwal at 28-Mar-13 3:02am
There are some button also in form which I dont want to print. I have to generate Report from the Form.
Sergey Alexandrovich Kryukov at 28-Mar-13 3:12am
That only justified what I say. It does not have to be a report, but you print data, not the form.
Any questions on printing data?
Neetesh Agarwal at 26-Mar-13 3:29am
Hello Sir,
I just want print as a Report so I need only Data. Not whole form

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Abhinav S 270
1 CHill60 180
2 KrunalRohit 154
3 Palash Mondal_ 145
4 Sergey Alexandrovich Kryukov 140
0 OriginalGriff 3,877
1 KrunalRohit 2,496
2 CPallini 2,240
3 Maciej Los 2,205
4 ppolymorphe 1,750

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100