public static void Run() { // ExStart:SetBorder // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Tables(); // Instantiate Document object Document doc = new Document(); // Add page to PDF document Page page = doc.Pages.Add(); // Create BorderInfo object Aspose.Pdf.BorderInfo border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All); // Specify that Top border will be double border.Top.IsDoubled = true; // Specify that bottom border will be double border.Bottom.IsDoubled = true; // Instantiate Table object Aspose.Pdf.Table table = new Aspose.Pdf.Table(); // Specify Columns width information table.ColumnWidths = "100"; // Create Row object Aspose.Pdf.Row row = table.Rows.Add(); // Add a Table cell to cells collection of row Aspose.Pdf.Cell cell = row.Cells.Add("some text"); // Set the border for cell object (double border) cell.Border = border; // Add table to paragraphs collection of Page page.Paragraphs.Add(table); dataDir = dataDir + "TableBorderTest_out_.pdf"; // Save the PDF document doc.Save(dataDir); // ExEnd:SetBorder Console.WriteLine("\nBorder setup successfully.\nFile saved at " + dataDir); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } Document doc = new Document(); PageInfo pageInfo = doc.PageInfo; Aspose.Pdf.MarginInfo marginInfo = pageInfo.Margin; marginInfo.Left = 37; marginInfo.Right = 37; marginInfo.Top = 37; marginInfo.Bottom = 37; pageInfo.IsLandscape = true; Aspose.Pdf.Table table = new Aspose.Pdf.Table(); table.ColumnWidths = "50 100"; // Added page. Page curPage = doc.Pages.Add(); for (int i = 1; i <= 120; i++) { Aspose.Pdf.Row row = table.Rows.Add(); row.FixedRowHeight = 15; Aspose.Pdf.Cell cell1 = row.Cells.Add(); cell1.Paragraphs.Add(new TextFragment("Content 1")); Aspose.Pdf.Cell cell2 = row.Cells.Add(); cell2.Paragraphs.Add(new TextFragment("HHHHH")); } Aspose.Pdf.Paragraphs paragraphs = curPage.Paragraphs; paragraphs.Add(table); /********************************************/ Aspose.Pdf.Table table1 = new Aspose.Pdf.Table(); table.ColumnWidths = "100 100"; for (int i = 1; i <= 10; i++) { Aspose.Pdf.Row row = table1.Rows.Add(); Aspose.Pdf.Cell cell1 = row.Cells.Add(); cell1.Paragraphs.Add(new TextFragment("LAAAAAAA")); Aspose.Pdf.Cell cell2 = row.Cells.Add(); cell2.Paragraphs.Add(new TextFragment("LAAGGGGGG")); } table1.IsInNewPage = true; // I want to keep table 1 to next page please... paragraphs.Add(table1); doc.Save(dataDir + "IsNewPageProperty_Test.pdf"); }
public static void Run() { // ExStart:RenderTable // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Tables(); Document doc = new Document(); PageInfo pageInfo = doc.PageInfo; Aspose.Pdf.MarginInfo marginInfo = pageInfo.Margin; marginInfo.Left = 37; marginInfo.Right = 37; marginInfo.Top = 37; marginInfo.Bottom = 37; pageInfo.IsLandscape = true; Aspose.Pdf.Table table = new Aspose.Pdf.Table(); table.ColumnWidths = "50 100"; // Added page. Page curPage = doc.Pages.Add(); for (int i = 1; i <= 120; i++) { Aspose.Pdf.Row row = table.Rows.Add(); row.FixedRowHeight = 15; Aspose.Pdf.Cell cell1 = row.Cells.Add(); cell1.Paragraphs.Add(new TextFragment("Content 1")); Aspose.Pdf.Cell cell2 = row.Cells.Add(); cell2.Paragraphs.Add(new TextFragment("HHHHH")); } Aspose.Pdf.Paragraphs paragraphs = curPage.Paragraphs; paragraphs.Add(table); /********************************************/ Aspose.Pdf.Table table1 = new Aspose.Pdf.Table(); table.ColumnWidths = "100 100"; for (int i = 1; i <= 10; i++) { Aspose.Pdf.Row row = table1.Rows.Add(); Aspose.Pdf.Cell cell1 = row.Cells.Add(); cell1.Paragraphs.Add(new TextFragment("LAAAAAAA")); Aspose.Pdf.Cell cell2 = row.Cells.Add(); cell2.Paragraphs.Add(new TextFragment("LAAGGGGGG")); } table1.IsInNewPage = true; // I want to keep table 1 to next page please... paragraphs.Add(table1); dataDir = dataDir + "IsNewPageProperty_Test_out.pdf"; doc.Save(dataDir); // ExEnd:RenderTable Console.WriteLine("\nTable render successfully on a page.\nFile saved at " + dataDir); }
public static void Run() { // ExStart:AddSVGObject // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Tables(); // Instantiate Document object Document doc = new Document(); // Create an image instance Aspose.Pdf.Image img = new Aspose.Pdf.Image(); // Set image type as SVG img.FileType = Aspose.Pdf.ImageFileType.Svg; // Path for source file img.File = dataDir + "SVGToPDF.svg"; // Set width for image instance img.FixWidth = 50; // Set height for image instance img.FixHeight = 50; // Create table instance Aspose.Pdf.Table table = new Aspose.Pdf.Table(); // Set width for table cells table.ColumnWidths = "100 100"; // Create row object and add it to table instance Aspose.Pdf.Row row = table.Rows.Add(); // Create cell object and add it to row instance Aspose.Pdf.Cell cell = row.Cells.Add(); // Add textfragment to paragraphs collection of cell object cell.Paragraphs.Add(new TextFragment("First cell")); // Add another cell to row object cell = row.Cells.Add(); // Add SVG image to paragraphs collection of recently added cell instance cell.Paragraphs.Add(img); // Create page object and add it to pages collection of document instance Page page = doc.Pages.Add(); // Add table to paragraphs collection of page object page.Paragraphs.Add(table); dataDir = dataDir + "AddSVGObject_out_.pdf"; // Save PDF file doc.Save(dataDir); // ExEnd:AddSVGObject Console.WriteLine("\nSVG image added successfully inside a table cell.\nFile saved at " + dataDir); }
public static void Run() { // ExStart:InsertPageBreak // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Tables(); // Instantiate Document instance Document doc = new Document(); // Add page to pages collection of PDF file doc.Pages.Add(); // Create table instance Aspose.Pdf.Table tab = new Aspose.Pdf.Table(); // Set border style for table tab.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.Red); // Set default border style for table with border color as Red tab.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.Red); // Specify table columsn widht tab.ColumnWidths = "100 100"; // Create a loop to add 200 rows for table for (int counter = 0; counter <= 200; counter++) { Aspose.Pdf.Row row = new Aspose.Pdf.Row(); tab.Rows.Add(row); Aspose.Pdf.Cell cell1 = new Aspose.Pdf.Cell(); cell1.Paragraphs.Add(new TextFragment("Cell " + counter + ", 0")); row.Cells.Add(cell1); Aspose.Pdf.Cell cell2 = new Aspose.Pdf.Cell(); cell2.Paragraphs.Add(new TextFragment("Cell " + counter + ", 1")); row.Cells.Add(cell2); // When 10 rows are added, render new row in new page if (counter % 10 == 0 && counter != 0) { row.IsInNewPage = true; } } // Add table to paragraphs collection of PDF file doc.Pages[1].Paragraphs.Add(tab); dataDir = dataDir + "InsertPageBreak_out_.pdf"; // Save the PDF document doc.Save(dataDir); // ExEnd:InsertPageBreak Console.WriteLine("\nPage break inserted successfully.\nFile saved at " + dataDir); }
public static void Run() { // ExStart:InsertPageBreak // The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Tables(); // Instantiate Document instance Document doc = new Document(); // Add page to pages collection of PDF file doc.Pages.Add(); // Create table instance Aspose.Pdf.Table tab = new Aspose.Pdf.Table(); // Set border style for table tab.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.Red); // Set default border style for table with border color as Red tab.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.Red); // Specify table columsn widht tab.ColumnWidths = "100 100"; // Create a loop to add 200 rows for table for (int counter = 0; counter <= 200; counter++) { Aspose.Pdf.Row row = new Aspose.Pdf.Row(); tab.Rows.Add(row); Aspose.Pdf.Cell cell1 = new Aspose.Pdf.Cell(); cell1.Paragraphs.Add(new TextFragment("Cell " + counter + ", 0")); row.Cells.Add(cell1); Aspose.Pdf.Cell cell2 = new Aspose.Pdf.Cell(); cell2.Paragraphs.Add(new TextFragment("Cell " + counter + ", 1")); row.Cells.Add(cell2); // When 10 rows are added, render new row in new page if (counter % 10 == 0 && counter != 0) row.IsInNewPage = true; } // Add table to paragraphs collection of PDF file doc.Pages[1].Paragraphs.Add(tab); dataDir = dataDir + "InsertPageBreak_out.pdf"; // Save the PDF document doc.Save(dataDir); // ExEnd:InsertPageBreak Console.WriteLine("\nPage break inserted successfully.\nFile saved at " + dataDir); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); // Create directory if it is not already present. bool IsExists = System.IO.Directory.Exists(dataDir); if (!IsExists) { System.IO.Directory.CreateDirectory(dataDir); } // instantiate Document object Document doc = new Document(); // add page to PDF document Page page = doc.Pages.Add(); // create BorderInfo object Aspose.Pdf.BorderInfo border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All); // specify that Top border will be double border.Top.IsDoubled = true; // specify that bottom border will be double border.Bottom.IsDoubled = true; // instantiate Table object Aspose.Pdf.Table table = new Aspose.Pdf.Table(); // specify Columns width information table.ColumnWidths = "100"; // create Row object Aspose.Pdf.Row row = table.Rows.Add(); // add a Table cell to cells collection of row Aspose.Pdf.Cell cell = row.Cells.Add("some text"); // set the border for cell object (double border) cell.Border = border; // add table to paragraphs collection of Page page.Paragraphs.Add(table); // save the PDF document doc.Save(dataDir + "TableBorderTest.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>"; } }