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.

3
  • Similar question was asked here stackoverflow.com/questions/9229548/… Commented Feb 15, 2012 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.. Commented Feb 15, 2012 at 14:47
  • I have made some edit to the question, add some aclarations lines Commented Feb 15, 2012 at 16:09

2 Answers 2

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();
}
Sign up to request clarification or add additional context in comments.

Comments

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...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.