Click here to Skip to main content
13,146,014 members (43,849 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
Updated 25-Mar-13 5:11am
Maciej Los255.6K
Maciej Los 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 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 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 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 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 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 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.
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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2017
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