Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.


//code

C#
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;


C#
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));

                doc.Open();

                doc.Add(i);
                doc.Close();
            }
        }
  }
 }

I used this code but iTs print like screen shot.

Thanks
Neetesh Agarwal
Posted
Updated 25-Mar-13 5:11am
v7
Comments
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?
—SA
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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900