翻譯|使用教程|編輯:李顯亮|2020-05-28 09:36:59.277|閱讀 679 次
概述:在本系列教程中,將為開發者帶來Aspose.PDF for .NET的一系列使用教程,例如進行文檔間的轉換,如何標記PDF文件,如何使用表單和圖表等等。本文將介紹如何設置表格的邊框樣式,邊距和填充。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.PDF for .NET是一種高PDF處理和解析API,用于在跨平臺應用程序中執行文檔管理和操作任務。API可以輕松用于生成、修改、轉換、渲染、保護和打印PDF文檔,而無需使用Adobe Acrobat。此外,API還提供PDF壓縮選項,表格創建和操作,圖形和圖像功能,廣泛的超鏈接功能,印章和水印任務,擴展的安全控制和自定義字體處理。
在接下來的系列教程中,將為開發者帶來Aspose.PDF for .NET的一系列使用教程,例如進行文檔間的轉換,如何標記PDF文件,如何使用表單和圖表等等。本文將介紹如何設置表格的邊框樣式,邊距和填充。
>>Aspose.PDF for .NET更新至最新版v20.5,歡迎下載體驗。
Aspose.PDF for .NET允許開發人員在PDF文檔中創建表格。而且,它們可以將邊框樣式,邊距和單元格填充等效果應用于表格。在深入了解技術細節之前,重要的是要了解下圖所示的邊框,邊距和填充的概念:
邊框,邊距和填充
在上圖中,可以看到表格,行和單元格的邊界重疊。使用Aspose.PDF for .NET,表格可以具有邊距和單元格填充。要設置單元格的邊距,我們必須設置單元格填充。
邊框
要設置的邊界Table,Row和Cell對象,請使用Table.Border,Row.Border和Cell.Border性能。也可以使用Table或Row類的DefaultCellBorder屬性來設置單元格邊框。上面討論的所有與邊框相關的屬性都分配了Row該類的實例,該類是通過調用其構造函數創建的。本Row類有需要的幾乎所有以自定義邊框所需的參數很多重載。
邊距或填充
單元格填充可以使用Tableclass的DefaultCellPaddingproperty 進行管理。所有的填充相關的屬性分配的一個實例,MarginInfo大約需要的信息類Left,Right,Top和Bottom參數來創建自定義邊距。在下面的示例中,單元格邊框的寬度設置為0.1點,表邊框的寬度設置為1點,單元格填充設置為5點。
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Tables(); // Instntiate the Document object by calling its empty constructor Document doc = new Document(); Page page = doc.Pages.Add(); // Instantiate a table object Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table(); // Add the table in paragraphs collection of the desired section page.Paragraphs.Add(tab1); // Set with column widths of the table tab1.ColumnWidths = "50 50 50"; // Set default cell border using BorderInfo object tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F); // Set table border using another customized BorderInfo object tab1.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1F); // Create MarginInfo object and set its left, bottom, right and top margins Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo(); margin.Top = 5f; margin.Left = 5f; margin.Right = 5f; margin.Bottom = 5f; // Set the default cell padding to the MarginInfo object tab1.DefaultCellPadding = margin; // Create rows in the table and then cells in the rows Aspose.Pdf.Row row1 = tab1.Rows.Add(); row1.Cells.Add("col1"); row1.Cells.Add("col2"); row1.Cells.Add(); TextFragment mytext = new TextFragment("col3 with large text string"); // Row1.Cells.Add("col3 with large text string to be placed inside cell"); row1.Cells[2].Paragraphs.Add(mytext); row1.Cells[2].IsWordWrapped = false; // Row1.Cells[2].Paragraphs[0].FixedWidth= 80; Aspose.Pdf.Row row2 = tab1.Rows.Add(); row2.Cells.Add("item1"); row2.Cells.Add("item2"); row2.Cells.Add("item3"); dataDir = dataDir + "MarginsOrPadding_out.pdf"; // Save the Pdf doc.Save(dataDir);
要創建帶有圓角的表,請使用BorderInfo類的RoundedBorderRadius值并將表的角樣式設置為圓形。
// The path to the documents directory. string dataDir = RunExamples.GetDataDir_AsposePdf_Tables(); Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table(); GraphInfo graph = new GraphInfo(); graph.Color = Aspose.Pdf.Color.Red; // Create a blank BorderInfo object BorderInfo bInfo = new BorderInfo(BorderSide.All, graph); // Set the border a rounder border where radius of round is 15 bInfo.RoundedBorderRadius = 15; // Set the table Corner style as Round. tab1.CornerStyle = Aspose.Pdf.BorderCornerStyle.Round; // Set the table border information tab1.Border = bInfo;
雙邊框
如上所述,邊框可以加入Table或Cell對象。我們的用戶要求我們添加一項功能,允許他們在Table和Cell對象周圍添加雙邊框。NET 8.8.0的Aspose.PDF中添加了此功能。下面的代碼段顯示了如何實現此要求。
// 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);
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn