locked
generating pdf from datasets RRS feed

  • Question

  • I have a dataset class in my Project, How do I export the tables in the dataset to PDF using ItextSharp
    Thanks
    Thursday, January 14, 2010 1:07 AM

Answers

  • Hello capiono,

    just show SaveFileDialog when user clicks on your Export button (or whatever starts the data export), and use the filename to create pdf document

    		private void button2_Click(object sender, EventArgs e)
    		{
    			string otputPath = null;
    			SaveFileDialog dlg = null;
    			try
    			{
    				dlg = new SaveFileDialog();
    				dlg.AddExtension = true;
    				dlg.Title = "Export to PDF as";
    				dlg.DefaultExt = ".pdf";
    				dlg.Filter = "Pdf files (*.pdf)|*.pdf|All Files (*.*)|*.*";
    				//dlg.InitialDirectory = "c:\\SomeFolder";
    				if (dlg.ShowDialog() == DialogResult.OK)
    				{
    					otputPath = dlg.FileName;
    				}
    			}
    			catch (Exception ex)
    			{
    				// handle exception
    			}
    			finally
    			{
    				if (dlg != null)
    				{
    					dlg.Dispose();
    					dlg = null;
    				}
    			}
    		}
    


    Best regards,
    Vladimir


    • Marked as answer by capiono Friday, January 15, 2010 3:24 PM
    Friday, January 15, 2010 2:25 PM

All replies

  • Hello capiono,

    did you get anywhere at all with ITextSharp ?
    did you manage to create document and add some text to it ?


    Best regards,
    Vladimir
    Thursday, January 14, 2010 2:07 PM
  • Yes, but I don't know how to use data from a dataset or datatable in creating the document
    Thanks 
    Friday, January 15, 2010 12:29 AM
  • Hey Vladimir, 
    I was finally able to get the data from my dbase and add it to the document, but now my problem  now is how do I get a Save Dialog Box?
    Friday, January 15, 2010 2:00 AM
  • Hello capiono,

    just show SaveFileDialog when user clicks on your Export button (or whatever starts the data export), and use the filename to create pdf document

    		private void button2_Click(object sender, EventArgs e)
    		{
    			string otputPath = null;
    			SaveFileDialog dlg = null;
    			try
    			{
    				dlg = new SaveFileDialog();
    				dlg.AddExtension = true;
    				dlg.Title = "Export to PDF as";
    				dlg.DefaultExt = ".pdf";
    				dlg.Filter = "Pdf files (*.pdf)|*.pdf|All Files (*.*)|*.*";
    				//dlg.InitialDirectory = "c:\\SomeFolder";
    				if (dlg.ShowDialog() == DialogResult.OK)
    				{
    					otputPath = dlg.FileName;
    				}
    			}
    			catch (Exception ex)
    			{
    				// handle exception
    			}
    			finally
    			{
    				if (dlg != null)
    				{
    					dlg.Dispose();
    					dlg = null;
    				}
    			}
    		}
    


    Best regards,
    Vladimir


    • Marked as answer by capiono Friday, January 15, 2010 3:24 PM
    Friday, January 15, 2010 2:25 PM