public static void Run() { // ExStart:IntegrateWithDatabase // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Tables(); DataTable dt = new DataTable("Employee"); dt.Columns.Add("Employee_ID", typeof(Int32)); dt.Columns.Add("Employee_Name", typeof(string)); dt.Columns.Add("Gender", typeof(string)); // Add 2 rows into the DataTable object programmatically DataRow dr = dt.NewRow(); dr[0] = 1; dr[1] = "John Smith"; dr[2] = "Male"; dt.Rows.Add(dr); dr = dt.NewRow(); dr[0] = 2; dr[1] = "Mary Miller"; dr[2] = "Female"; dt.Rows.Add(dr); // Create Document instance Document doc = new Document(); doc.Pages.Add(); // Initializes a new instance of the Table Aspose.Pdf.Table table = new Aspose.Pdf.Table(); // Set column widths of the table table.ColumnWidths = "40 100 100 100"; // Set the table border color as LightGray table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray)); // Set the border for table cells table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray)); table.ImportDataTable(dt, true, 0, 1, 3, 3); // Add table object to first page of input document doc.Pages[1].Paragraphs.Add(table); dataDir = dataDir + "DataIntegrated_out.pdf"; // Save updated document containing table object doc.Save(dataDir); // ExEnd:IntegrateWithDatabase Console.WriteLine("\nDatabase integrated successfully.\nFile saved at " + dataDir); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); /* Create a DataTable object (Employee) and add columns to it (Employee_ID, * Employee_Name, Gender). */ DataTable dt = new DataTable("Employee"); dt.Columns.Add("Employee_ID", typeof(Int32)); dt.Columns.Add("Employee_Name", typeof(string)); dt.Columns.Add("Gender", typeof(string)); //Add 2 rows into the DataTable object programmatically DataRow dr = dt.NewRow(); dr[0] = 1; dr[1] = "John Smith"; dr[2] = "Male"; dt.Rows.Add(dr); dr = dt.NewRow(); dr[0] = 2; dr[1] = "Mary Miller"; dr[2] = "Female"; dt.Rows.Add(dr); // Create Document instance Document doc = new Document(); doc.Pages.Add(); // Initializes a new instance of the Table Aspose.Pdf.Table table = new Aspose.Pdf.Table(); //Set column widths of the table table.ColumnWidths = "40 100 100 100"; // Set the table border color as LightGray table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray)); // set the border for table cells table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray)); table.ImportDataTable(dt, true, 0, 1, 3, 3); // Add table object to first page of input document doc.Pages[1].Paragraphs.Add(table); // Save updated document containing table object doc.Save(dataDir + "DataIntegrated.pdf"); }
public static void Run() { // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Tables(); /* Create a DataTable object (Employee) and add columns to it (Employee_ID, * Employee_Name, Gender). */ DataTable dt = new DataTable("Employee"); dt.Columns.Add("Employee_ID", typeof(Int32)); dt.Columns.Add("Employee_Name", typeof(string)); dt.Columns.Add("Gender", typeof(string)); //Add 2 rows into the DataTable object programmatically DataRow dr = dt.NewRow(); dr[0] = 1; dr[1] = "John Smith"; dr[2] = "Male"; dt.Rows.Add(dr); dr = dt.NewRow(); dr[0] = 2; dr[1] = "Mary Miller"; dr[2] = "Female"; dt.Rows.Add(dr); // Create Document instance Document doc = new Document(); doc.Pages.Add(); // Initializes a new instance of the Table Aspose.Pdf.Table table = new Aspose.Pdf.Table(); //Set column widths of the table table.ColumnWidths = "40 100 100 100"; // Set the table border color as LightGray table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray)); // set the border for table cells table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray)); table.ImportDataTable(dt, true, 0, 1, 3, 3); // Add table object to first page of input document doc.Pages[1].Paragraphs.Add(table); // Save updated document containing table object doc.Save(dataDir+ "DataIntegrated.pdf"); }
protected void btnSave_Click(object sender, EventArgs e) { try { //Creating new document Document doc = new Document(); //add a new page in the document... Aspose.Pdf.Page page = doc.Pages.Add(); //add header and footer in the document AddHeaderFooter(doc, "Online Application Form - Dated: " + DateTime.Now.Date.ToString("MM-dd-yyyy"), ""); //crearing new table Aspose.Pdf.Table table = new Aspose.Pdf.Table(); page.Paragraphs.Add(table); table.Alignment = Aspose.Pdf.HorizontalAlignment.Center; table.DefaultColumnWidth = "500"; //create a new row in the table... Aspose.Pdf.Row row = new Aspose.Pdf.Row(); table.Rows.Add(row); //create a new cell in the row... Aspose.Pdf.Cell cell = new Aspose.Pdf.Cell(); row.Cells.Add(cell); cell.Alignment = Aspose.Pdf.HorizontalAlignment.Center; //create main heading of the page TextFragment txtFragmanet = new TextFragment("Online Application Form"); txtFragmanet.TextState.FontSize = 15; txtFragmanet.TextState.FontStyle = FontStyles.Bold; cell.Paragraphs.Add(txtFragmanet); //============================ Section of personal information Starts====================== // Add a new heading ... AddHeading(page, "Applied for Position: " + txtPosition.Text, 8, false); // Add a new heading ... AddHeading(page, "Personal Information:", 10, true); // create table for personal information Aspose.Pdf.Table tblPersonalInfo = new Aspose.Pdf.Table(); page.Paragraphs.Add(tblPersonalInfo); tblPersonalInfo.DefaultCellTextState.FontSize = 6; //set columns width... tblPersonalInfo.ColumnWidths = "100 400"; //adding personal details ... AddRow(tblPersonalInfo, "Name:", txtName.Text); AddRow(tblPersonalInfo, "Date of Birth:", txtDOB.Text); AddRow(tblPersonalInfo, "Email:", txtEmail.Text); AddRow(tblPersonalInfo, "Phone:", txtPhone.Text); AddRow(tblPersonalInfo, "Address:", txtAddress.Text); foreach (Aspose.Pdf.Row rw in tblPersonalInfo.Rows) { rw.MinRowHeight = 20; } //=========================== End of Personal Information Section ================================================ //=========================== Skills Starts =============================================================== //add new heading... AddHeading(page, "Skills:", 10, true); // add text fragment... TextFragment txtFragSkills = new TextFragment(); txtFragSkills.TextState.Font = FontRepository.FindFont("Calibri"); txtFragSkills.TextState.FontSize = 8; txtFragSkills.Text = txtSkills.Text; txtFragSkills.TextState.LineSpacing = 5; //add text fragment in pagae paragraph... page.Paragraphs.Add(txtFragSkills); //=========================== End of Objective Statement Section ==================================================== //============================ Section of Educational information Starts====================== // Add a new heading ... AddHeading(page, "Educational Details:", 10, true); //create datatable... DataTable dtEducationalDetails = new DataTable(); dtEducationalDetails.Columns.Add("Degree", typeof(string)); dtEducationalDetails.Columns.Add("Total Marks/GPA", typeof(string)); dtEducationalDetails.Columns.Add("Obtained Marks/CGPA", typeof(string)); dtEducationalDetails.Columns.Add("Institute", typeof(string)); //get data from the gridview and store in datatable... foreach (GridViewRow grow in gvEducationalDetails.Rows) { TextBox txtDegree = grow.FindControl("txtDegree") as TextBox; TextBox txtTotalMarks = grow.FindControl("txtTotalMarks") as TextBox; TextBox txtObtainedMarks = grow.FindControl("txtObtainedMarks") as TextBox; TextBox txtInstitute = grow.FindControl("txtInstitute") as TextBox; if (txtDegree.Text.Trim() != "" && txtTotalMarks.Text.Trim() != "" && txtObtainedMarks.Text.Trim() != "" && txtInstitute.Text.Trim() != "") { DataRow drow = dtEducationalDetails.NewRow(); drow[0] = txtDegree.Text; drow[1] = txtTotalMarks.Text; drow[2] = txtObtainedMarks.Text; drow[3] = txtInstitute.Text; dtEducationalDetails.Rows.Add(drow); } } //create table for personal information Aspose.Pdf.Table tblEducationalInfo = new Aspose.Pdf.Table(); tblEducationalInfo.ColumnWidths = "100 100 100 100"; //add table to the dataset DataSet ds = new DataSet(); ds.Tables.Add(dtEducationalDetails); tblEducationalInfo.DefaultCellTextState.FontSize = 8; tblEducationalInfo.DefaultCellTextState.Font = FontRepository.FindFont("Calibri"); //Set the border style of the table... tblEducationalInfo.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black)); // Set default cell border... tblEducationalInfo.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black)); // Set data source of the table... tblEducationalInfo.ImportDataTable(ds.Tables[0], true, 0, 0, ds.Tables[0].Rows.Count, 4); //Add table in paragraph... page.Paragraphs.Add(tblEducationalInfo); // Set the style of head row of the table... tblEducationalInfo.Rows[0].DefaultCellTextState.FontStyle = FontStyles.Bold; tblEducationalInfo.Rows[0].BackgroundColor = Aspose.Pdf.Color.LightGray; //set the min height of the rows... foreach (Aspose.Pdf.Row rw in tblEducationalInfo.Rows) { rw.Cells[3].IsWordWrapped = false; rw.MinRowHeight = 15; } //=========================== End of Educational Information Section ================================================ //============================ Section of Professional Experience Starts====================== // Add a new heading ... AddHeading(page, "Employment History:", 10, true); //create a new datatbale to store the data... DataTable dtExperience = new DataTable(); dtExperience.Columns.Add("Designation", typeof(string)); dtExperience.Columns.Add("Duration", typeof(string)); dtExperience.Columns.Add("Organization", typeof(string)); // get the data from the grid view into datatable... foreach (GridViewRow grow in gvExperience.Rows) { TextBox txtDesignation = grow.FindControl("txtDesignation") as TextBox; TextBox txtDuration = grow.FindControl("txtDuration") as TextBox; TextBox txtOrganization = grow.FindControl("txtOrganization") as TextBox; if (txtDesignation.Text.Trim() != "" && txtDuration.Text.Trim() != "" && txtOrganization.Text.Trim() != "") { DataRow drow = dtExperience.NewRow(); drow[0] = txtDesignation.Text; drow[1] = txtDuration.Text; drow[2] = txtOrganization.Text; dtExperience.Rows.Add(drow); } } //create table for personal information Aspose.Pdf.Table tblExperience = new Aspose.Pdf.Table(); //set width of the columns... tblExperience.ColumnWidths = "100 100 200"; //add table to the dataset ds = new DataSet(); ds.Tables.Add(dtExperience); //set the font properties... tblExperience.DefaultCellTextState.FontSize = 8; tblExperience.DefaultCellTextState.Font = FontRepository.FindFont("Calibri"); //Set the border style of the table... tblExperience.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black)); // Set default cell border... tblExperience.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black)); // Set data source of the table... tblExperience.ImportDataTable(ds.Tables[0], true, 0, 0, ds.Tables[0].Rows.Count, 3); //Add table in paragraph... page.Paragraphs.Add(tblExperience); // Set the style of head row of the table... tblExperience.Rows[0].DefaultCellTextState.FontStyle = FontStyles.Bold; tblExperience.Rows[0].BackgroundColor = Aspose.Pdf.Color.LightGray; foreach (Aspose.Pdf.Row rw in tblExperience.Rows) { rw.Cells[2].IsWordWrapped = false; rw.MinRowHeight = 15; } //=========================== End of Professional Experience Section ================================================ //=========================== Cover Letter Starts =============================================================== AddHeading(page, "Cover Letter:", 10, true); TextFragment txtFragCoverLetter = new TextFragment(); txtFragCoverLetter.TextState.Font = FontRepository.FindFont("Calibri"); txtFragCoverLetter.TextState.FontSize = 8; txtFragCoverLetter.Text = txtCoverLetter.Text; txtFragCoverLetter.TextState.LineSpacing = 5; page.Paragraphs.Add(txtFragCoverLetter); //=========================== End of Cover Letter Section ==================================================== //Add watermark in the document... foreach (Aspose.Pdf.Page pg in doc.Pages) { AddWaterMark(pg); } string path = Server.MapPath("~/Uploads/Application_" + DateTime.Now.ToString("dd_MM_yy HH_mm_ss") + ".pdf"); doc.Save(path); msg.Text = "<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>Your application has been submitted successfully.</div>"; //show message "Your application has been submitted successfully." } catch(Exception exp) { msg.Text = "<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>Exception Occured:" + exp.Message + "</div>"; } }