1

I am trying to create a pdf document in my windows forms application, in the application I have forms and user controls with several controls inside like textbox, richtexbox, label, button, radiobutton and etc...

I want to create the pdf with the data present in those forms and users controls, the pdf should look like the content in those forms and users controls, the button, textbox, labels, etc, similar like a picture from those forms and users controls.

Sorry if i was not clear, I want to add what the user see in the form like it was a picture, but not do a screen shot, is like do something like this:

pdfDocument.Add(Button);
pdfDocument.Add(textBox);

Maybe this question is not right, but I am new to generate PDF.

Community
  • 1
  • 1
Jack1987
  • 727
  • 1
  • 14
  • 26
  • Similar question was asked here http://stackoverflow.com/questions/9229548/a-good-guide-book-or-api-doc-for-itextsharp/9229627#9229627 – Huske Feb 15 '12 at 14:39
  • This just sounds.. so.. very wrong. If this was a real requirement I was given by the business I would argue against it till I was blue in the face. There would have to be some seriously powerful justification for doing this over building a report or something else.. – Shane Courtrille Feb 15 '12 at 14:47
  • I have made some edit to the question, add some aclarations lines – Jack1987 Feb 15 '12 at 16:09

2 Answers2

3

To do the screenshot method, you could do something like this:

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(@"C:\Temp\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();
}
John Koerner
  • 37,428
  • 8
  • 84
  • 134
1

Easy way - screenshot your application on click of a button and embed that image into a PDF using itextsharp.

Hard (but possibly better way) - write some code using i-textsharp to generate a PDF, passing in your data...

Paddy
  • 33,309
  • 15
  • 79
  • 114