Click here to Skip to main content
Rate this: bad
good
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.
 

//code
 
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));
 
                doc.Open();
 
                doc.Add(i);
                doc.Close();
            }
        }
  }
 }
I used this code but iTs print like screen shot.
 
Thanks
Neetesh Agarwal
Posted 25-Mar-13 6:05am
Edited 25-Mar-13 6:11am
(no name)158.9K
v7
Comments
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?
—SA
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.
—SA
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?
—SA
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 OriginalGriff 215
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 159
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 25 Mar 2013
Copyright © CodeProject, 1999-2014
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