العمل مع الجداول في ملفات PDF المعلّمة
إنشاء جدول في PDF المعلّم
Aspose.PDF for .NET يتيح إنشاء جدول في مستندات PDF المعلّمة. للعمل مع الجداول، توفر واجهة برمجة التطبيقات TableElement class. لإنشاء جدول، يمكنك استخدام CreateTableElement() method of ITaggedContent interface. علاوة على ذلك، يمكنك استخدام CreateTHead() ، CreateTBody() و CreateTFoot() methods of TableElement class لإنشاء رأس الجدول، جسم الجدول، وتذييل الجدول على التوالي. لإنشاء صف جدول، يمكنك استخدام CreateTR() method of TableRowCollectionElement class. يمكنك أيضًا التحقق مما إذا كان مستند PDF الذي تم إنشاؤه يتوافق مع PDF/UA باستخدام Validate() method of Document class.
تعمل مقتطفات الشيفرة التالية أيضًا مع مكتبة Aspose.PDF.Drawing .
توضح مقتطفات الشيفرة التالية كيفية إنشاء جدول في مستند PDF المعلّم:
.NET Core 3.1
Copy
private static void CreateTable ( )
{
var dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
using ( var document = new Aspose . Pdf . Document ())
{
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document . TaggedContent ;
taggedContent . SetTitle ( "Example table" );
taggedContent . SetLanguage ( "en-US" );
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . TableElement tableElement = taggedContent . CreateTableElement ();
rootElement . AppendChild ( tableElement );
tableElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 1.2F , Aspose . Pdf . Color . DarkBlue );
Aspose . Pdf . LogicalStructure . TableTHeadElement tableTHeadElement = tableElement . CreateTHead ();
Aspose . Pdf . LogicalStructure . TableTBodyElement tableTBodyElement = tableElement . CreateTBody ();
Aspose . Pdf . LogicalStructure . TableTFootElement tableTFootElement = tableElement . CreateTFoot ();
int rowCount = 50 ;
int colCount = 4 ;
int rowIndex ;
int colIndex ;
Aspose . Pdf . LogicalStructure . TableTRElement headTrElement = tableTHeadElement . CreateTR ();
headTrElement . AlternativeText = "Head Row" ;
headTrElement . BackgroundColor = Aspose . Pdf . Color . LightGray ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTHElement thElement = headTrElement . CreateTH ();
thElement . SetText ( String . Format ( "Head {0}" , colIndex ));
thElement . BackgroundColor = Aspose . Pdf . Color . GreenYellow ;
thElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 4.0F , Aspose . Pdf . Color . Gray );
thElement . IsNoBorder = true ;
thElement . Margin = new Aspose . Pdf . MarginInfo ( 16.0 , 2.0 , 8.0 , 2.0 );
thElement . Alignment = Aspose . Pdf . HorizontalAlignment . Right ;
}
for ( rowIndex = 0 ; rowIndex < rowCount ; rowIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTRElement trElement = tableTBodyElement . CreateTR ();
trElement . AlternativeText = string . Format ( "Row {0}" , rowIndex );
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
int colSpan = 1 ;
int rowSpan = 1 ;
if ( colIndex == 1 && rowIndex == 1 )
{
colSpan = 2 ;
rowSpan = 2 ;
}
else if ( colIndex == 2 && ( rowIndex == 1 || rowIndex == 2 ))
{
continue ;
}
else if ( rowIndex == 2 && ( colIndex == 1 || colIndex == 2 ))
{
continue ;
}
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = trElement . CreateTD ();
tdElement . SetText ( String . Format ( "Cell [{0}, {1}]" , rowIndex , colIndex ));
tdElement . BackgroundColor = Aspose . Pdf . Color . Yellow ;
tdElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 4.0F , Aspose . Pdf . Color . Gray );
tdElement . IsNoBorder = false ;
tdElement . Margin = new Aspose . Pdf . MarginInfo ( 8.0 , 2.0 , 8.0 , 2.0 );
tdElement . Alignment = Aspose . Pdf . HorizontalAlignment . Center ;
var cellTextState = new Aspose . Pdf . Text . TextState ();
cellTextState . ForegroundColor = Aspose . Pdf . Color . DarkBlue ;
cellTextState . FontSize = 7.5F ;
cellTextState . FontStyle = Aspose . Pdf . Text . FontStyles . Bold ;
cellTextState . Font = Aspose . Pdf . Text . FontRepository . FindFont ( "Arial" );
tdElement . DefaultCellTextState = cellTextState ;
tdElement . IsWordWrapped = true ;
tdElement . VerticalAlignment = Aspose . Pdf . VerticalAlignment . Center ;
tdElement . ColSpan = colSpan ;
tdElement . RowSpan = rowSpan ;
}
}
Aspose . Pdf . LogicalStructure . TableTRElement footTrElement = tableTFootElement . CreateTR ();
footTrElement . AlternativeText = "Foot Row" ;
footTrElement . BackgroundColor = Aspose . Pdf . Color . LightSeaGreen ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = footTrElement . CreateTD ();
tdElement . SetText ( String . Format ( "Foot {0}" , colIndex ));
tdElement . Alignment = Aspose . Pdf . HorizontalAlignment . Center ;
tdElement . StructureTextState . FontSize = 7F ;
tdElement . StructureTextState . FontStyle = Aspose . Pdf . Text . FontStyles . Bold ;
}
Aspose . Pdf . LogicalStructure . StructureAttributes tableAttributes = tableElement . Attributes . GetAttributes ( Aspose . Pdf . LogicalStructure . AttributeOwnerStandard . Table );
var summaryAttribute = new Aspose . Pdf . LogicalStructure . StructureAttribute ( Aspose . Pdf . LogicalStructure . AttributeKey . Summary );
summaryAttribute . SetStringValue ( "The summary text for table" );
tableAttributes . SetAttribute ( summaryAttribute );
document . Save ( dataDir + "CreateTableElement_out.pdf" );
}
using ( var document = new Aspose . Pdf . Document ( dataDir + "CreateTableElement_out.pdf" ))
{
bool isPdfUaCompliance = document . Validate ( dataDir + "CreateTableElement_log.xml" , Aspose . Pdf . PdfFormat . PDF_UA_1 );
Console . WriteLine ( String . Format ( "PDF/UA compliance: {0}" , isPdfUaCompliance ));
}
}
.NET 8
Copy
private static void CreateTable ( )
{
var dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
using var document1 = new Aspose . Pdf . Document ();
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document1 . TaggedContent ;
taggedContent . SetTitle ( "Example table" );
taggedContent . SetLanguage ( "en-US" );
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . TableElement tableElement = taggedContent . CreateTableElement ();
rootElement . AppendChild ( tableElement );
tableElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 1.2F , Aspose . Pdf . Color . DarkBlue );
Aspose . Pdf . LogicalStructure . TableTHeadElement tableTHeadElement = tableElement . CreateTHead ();
Aspose . Pdf . LogicalStructure . TableTBodyElement tableTBodyElement = tableElement . CreateTBody ();
Aspose . Pdf . LogicalStructure . TableTFootElement tableTFootElement = tableElement . CreateTFoot ();
int rowCount = 50 ;
int colCount = 4 ;
int rowIndex ;
int colIndex ;
Aspose . Pdf . LogicalStructure . TableTRElement headTrElement = tableTHeadElement . CreateTR ();
headTrElement . AlternativeText = "Head Row" ;
headTrElement . BackgroundColor = Aspose . Pdf . Color . LightGray ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTHElement thElement = headTrElement . CreateTH ();
thElement . SetText ( String . Format ( "Head {0}" , colIndex ));
thElement . BackgroundColor = Aspose . Pdf . Color . GreenYellow ;
thElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 4.0F , Aspose . Pdf . Color . Gray );
thElement . IsNoBorder = true ;
thElement . Margin = new Aspose . Pdf . MarginInfo ( 16.0 , 2.0 , 8.0 , 2.0 );
thElement . Alignment = Aspose . Pdf . HorizontalAlignment . Right ;
}
for ( rowIndex = 0 ; rowIndex < rowCount ; rowIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTRElement trElement = tableTBodyElement . CreateTR ();
trElement . AlternativeText = string . Format ( "Row {0}" , rowIndex );
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
int colSpan = 1 ;
int rowSpan = 1 ;
if ( colIndex == 1 && rowIndex == 1 )
{
colSpan = 2 ;
rowSpan = 2 ;
}
else if ( colIndex == 2 && ( rowIndex == 1 || rowIndex == 2 ))
{
continue ;
}
else if ( rowIndex == 2 && ( colIndex == 1 || colIndex == 2 ))
{
continue ;
}
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = trElement . CreateTD ();
tdElement . SetText ( String . Format ( "Cell [{0}, {1}]" , rowIndex , colIndex ));
tdElement . BackgroundColor = Aspose . Pdf . Color . Yellow ;
tdElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 4.0F , Aspose . Pdf . Color . Gray );
tdElement . IsNoBorder = false ;
tdElement . Margin = new Aspose . Pdf . MarginInfo ( 8.0 , 2.0 , 8.0 , 2.0 );
tdElement . Alignment = Aspose . Pdf . HorizontalAlignment . Center ;
var cellTextState = new Aspose . Pdf . Text . TextState ();
cellTextState . ForegroundColor = Aspose . Pdf . Color . DarkBlue ;
cellTextState . FontSize = 7.5F ;
cellTextState . FontStyle = Aspose . Pdf . Text . FontStyles . Bold ;
cellTextState . Font = Aspose . Pdf . Text . FontRepository . FindFont ( "Arial" );
tdElement . DefaultCellTextState = cellTextState ;
tdElement . IsWordWrapped = true ;
tdElement . VerticalAlignment = Aspose . Pdf . VerticalAlignment . Center ;
tdElement . ColSpan = colSpan ;
tdElement . RowSpan = rowSpan ;
}
}
Aspose . Pdf . LogicalStructure . TableTRElement footTrElement = tableTFootElement . CreateTR ();
footTrElement . AlternativeText = "Foot Row" ;
footTrElement . BackgroundColor = Aspose . Pdf . Color . LightSeaGreen ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = footTrElement . CreateTD ();
tdElement . SetText ( String . Format ( "Foot {0}" , colIndex ));
tdElement . Alignment = Aspose . Pdf . HorizontalAlignment . Center ;
tdElement . StructureTextState . FontSize = 7F ;
tdElement . StructureTextState . FontStyle = Aspose . Pdf . Text . FontStyles . Bold ;
}
Aspose . Pdf . LogicalStructure . StructureAttributes tableAttributes = tableElement . Attributes . GetAttributes ( Aspose . Pdf . LogicalStructure . AttributeOwnerStandard . Table );
var summaryAttribute = new Aspose . Pdf . LogicalStructure . StructureAttribute ( Aspose . Pdf . LogicalStructure . AttributeKey . Summary );
summaryAttribute . SetStringValue ( "The summary text for table" );
tableAttributes . SetAttribute ( summaryAttribute );
document1 . Save ( dataDir + "CreateTableElement_out.pdf" );
using var document2 = new Aspose . Pdf . Document ( dataDir + "CreateTableElement_out.pdf" );
bool isPdfUaCompliance = document2 . Validate ( dataDir + "CreateTableElement_log.xml" , Aspose . Pdf . PdfFormat . PDF_UA_1 );
Console . WriteLine ( String . Format ( "PDF/UA compliance: {0}" , isPdfUaCompliance ));
}
تنسيق عنصر الجدول
Aspose.PDF for .NET يتيح تنسيق جدول في مستند PDF المعلّم. لتنسيق جدول، يمكنك إنشاء جدول باستخدام CreateTableElement() method of ITaggedContent interface وتعيين تنسيق الجدول باستخدام خصائص TableElement class. فيما يلي قائمة الخصائص التي يمكنك استخدامها لتنسيق جدول:
توضح مقتطفات الشيفرة التالية كيفية تنسيق جدول في مستند PDF المعلّم:
.NET Core 3.1
Copy
private static void StyleTable ( )
{
var dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
using ( var document = new Aspose . Pdf . Document ())
{
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document . TaggedContent ;
taggedContent . SetTitle ( "Example table style" );
taggedContent . SetLanguage ( "en-US" );
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . TableElement tableElement = taggedContent . CreateTableElement ();
rootElement . AppendChild ( tableElement );
tableElement . BackgroundColor = Aspose . Pdf . Color . Beige ;
tableElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 0.80F , Aspose . Pdf . Color . Gray );
tableElement . Alignment = Aspose . Pdf . HorizontalAlignment . Center ;
tableElement . Broken = Aspose . Pdf . TableBroken . Vertical ;
tableElement . ColumnAdjustment = Aspose . Pdf . ColumnAdjustment . AutoFitToWindow ;
tableElement . ColumnWidths = "80 80 80 80 80" ;
tableElement . DefaultCellBorder = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 0.50F , Aspose . Pdf . Color . DarkBlue );
tableElement . DefaultCellPadding = new Aspose . Pdf . MarginInfo ( 16.0 , 2.0 , 8.0 , 2.0 );
tableElement . DefaultCellTextState . ForegroundColor = Aspose . Pdf . Color . DarkCyan ;
tableElement . DefaultCellTextState . FontSize = 8F ;
tableElement . DefaultColumnWidth = "70" ;
tableElement . IsBroken = false ;
tableElement . IsBordersIncluded = true ;
tableElement . Left = 0F ;
tableElement . Top = 40F ;
tableElement . RepeatingColumnsCount = 2 ;
tableElement . RepeatingRowsCount = 3 ;
var rowStyle = new Aspose . Pdf . Text . TextState ();
rowStyle . BackgroundColor = Aspose . Pdf . Color . LightCoral ;
tableElement . RepeatingRowsStyle = rowStyle ;
Aspose . Pdf . LogicalStructure . TableTHeadElement tableTHeadElement = tableElement . CreateTHead ();
Aspose . Pdf . LogicalStructure . TableTBodyElement tableTBodyElement = tableElement . CreateTBody ();
Aspose . Pdf . LogicalStructure . TableTFootElement tableTFootElement = tableElement . CreateTFoot ();
int rowCount = 10 ;
int colCount = 5 ;
int rowIndex ;
int colIndex ;
Aspose . Pdf . LogicalStructure . TableTRElement headTrElement = tableTHeadElement . CreateTR ();
headTrElement . AlternativeText = "Head Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTHElement thElement = headTrElement . CreateTH ();
thElement . SetText ( String . Format ( "Head {0}" , colIndex ));
}
for ( rowIndex = 0 ; rowIndex < rowCount ; rowIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTRElement trElement = tableTBodyElement . CreateTR ();
trElement . AlternativeText = String . Format ( "Row {0}" , rowIndex );
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = trElement . CreateTD ();
tdElement . SetText ( String . Format ( "Cell [{0}, {1}]" , rowIndex , colIndex ));
}
}
Aspose . Pdf . LogicalStructure . TableTRElement footTrElement = tableTFootElement . CreateTR ();
footTrElement . AlternativeText = "Foot Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = footTrElement . CreateTD ();
tdElement . SetText ( String . Format ( "Foot {0}" , colIndex ));
}
document . Save ( dataDir + "StyleTableElement_out.pdf" );
}
using ( var document = new Aspose . Pdf . Document ( dataDir + "StyleTableElement_out.pdf" ))
{
bool isPdfUaCompliance = document . Validate ( dataDir + "StyleTableElement_log.xml" , Aspose . Pdf . PdfFormat . PDF_UA_1 );
Console . WriteLine ( String . Format ( "PDF/UA compliance: {0}" , isPdfUaCompliance ));
}
}
.NET 8
Copy
private static void StyleTable ( )
{
var dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
using var document1 = new Aspose . Pdf . Document ();
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document1 . TaggedContent ;
taggedContent . SetTitle ( "Example table style" );
taggedContent . SetLanguage ( "en-US" );
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . TableElement tableElement = taggedContent . CreateTableElement ();
rootElement . AppendChild ( tableElement );
tableElement . BackgroundColor = Aspose . Pdf . Color . Beige ;
tableElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 0.80F , Aspose . Pdf . Color . Gray );
tableElement . Alignment = Aspose . Pdf . HorizontalAlignment . Center ;
tableElement . Broken = Aspose . Pdf . TableBroken . Vertical ;
tableElement . ColumnAdjustment = Aspose . Pdf . ColumnAdjustment . AutoFitToWindow ;
tableElement . ColumnWidths = "80 80 80 80 80" ;
tableElement . DefaultCellBorder = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 0.50F , Aspose . Pdf . Color . DarkBlue );
tableElement . DefaultCellPadding = new Aspose . Pdf . MarginInfo ( 16.0 , 2.0 , 8.0 , 2.0 );
tableElement . DefaultCellTextState . ForegroundColor = Aspose . Pdf . Color . DarkCyan ;
tableElement . DefaultCellTextState . FontSize = 8F ;
tableElement . DefaultColumnWidth = "70" ;
tableElement . IsBroken = false ;
tableElement . IsBordersIncluded = true ;
tableElement . Left = 0F ;
tableElement . Top = 40F ;
tableElement . RepeatingColumnsCount = 2 ;
tableElement . RepeatingRowsCount = 3 ;
var rowStyle = new Aspose . Pdf . Text . TextState ();
rowStyle . BackgroundColor = Aspose . Pdf . Color . LightCoral ;
tableElement . RepeatingRowsStyle = rowStyle ;
Aspose . Pdf . LogicalStructure . TableTHeadElement tableTHeadElement = tableElement . CreateTHead ();
Aspose . Pdf . LogicalStructure . TableTBodyElement tableTBodyElement = tableElement . CreateTBody ();
Aspose . Pdf . LogicalStructure . TableTFootElement tableTFootElement = tableElement . CreateTFoot ();
int rowCount = 10 ;
int colCount = 5 ;
int rowIndex ;
int colIndex ;
Aspose . Pdf . LogicalStructure . TableTRElement headTrElement = tableTHeadElement . CreateTR ();
headTrElement . AlternativeText = "Head Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTHElement thElement = headTrElement . CreateTH ();
thElement . SetText ( String . Format ( "Head {0}" , colIndex ));
}
for ( rowIndex = 0 ; rowIndex < rowCount ; rowIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTRElement trElement = tableTBodyElement . CreateTR ();
trElement . AlternativeText = String . Format ( "Row {0}" , rowIndex );
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = trElement . CreateTD ();
tdElement . SetText ( String . Format ( "Cell [{0}, {1}]" , rowIndex , colIndex ));
}
}
Aspose . Pdf . LogicalStructure . TableTRElement footTrElement = tableTFootElement . CreateTR ();
footTrElement . AlternativeText = "Foot Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = footTrElement . CreateTD ();
tdElement . SetText ( String . Format ( "Foot {0}" , colIndex ));
}
document1 . Save ( dataDir + "StyleTableElement_out.pdf" );
using var document2 = new Aspose . Pdf . Document ( dataDir + "StyleTableElement_out.pdf" );
bool isPdfUaCompliance = document2 . Validate ( dataDir + "StyleTableElement_log.xml" , Aspose . Pdf . PdfFormat . PDF_UA_1 );
Console . WriteLine ( String . Format ( "PDF/UA compliance: {0}" , isPdfUaCompliance ));
}
تنسيق صف الجدول
Aspose.PDF for .NET يتيح تنسيق صف جدول في مستند PDF المعلّم. لتنسيق صف جدول، يمكنك استخدام خصائص TableTRElement class. فيما يلي قائمة الخصائص التي يمكنك استخدامها لتنسيق صف جدول:
BackgroundColor.
Border.
DefaultCellBorder.
MinRowHeight.
FixedRowHeight.
IsInNewPage.
IsRowBroken.
DefaultCellTextState.
DefaultCellPadding.
VerticalAlignment.
توضح مقتطفات الشيفرة التالية كيفية تنسيق صف جدول في مستند PDF المعلّم:
.NET Core 3.1
Copy
private static void StyleTableRow ( )
{
var dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
using ( var document = new Aspose . Pdf . Document ())
{
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document . TaggedContent ;
taggedContent . SetTitle ( "Example table row style" );
taggedContent . SetLanguage ( "en-US" );
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . TableElement tableElement = taggedContent . CreateTableElement ();
rootElement . AppendChild ( tableElement );
Aspose . Pdf . LogicalStructure . TableTHeadElement tableTHeadElement = tableElement . CreateTHead ();
Aspose . Pdf . LogicalStructure . TableTBodyElement tableTBodyElement = tableElement . CreateTBody ();
Aspose . Pdf . LogicalStructure . TableTFootElement tableTFootElement = tableElement . CreateTFoot ();
int rowCount = 7 ;
int colCount = 3 ;
int rowIndex ;
int colIndex ;
Aspose . Pdf . LogicalStructure . TableTRElement headTrElement = tableTHeadElement . CreateTR ();
headTrElement . AlternativeText = "Head Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTHElement thElement = headTrElement . CreateTH ();
thElement . SetText ( string . Format ( "Head {0}" , colIndex ));
}
for ( rowIndex = 0 ; rowIndex < rowCount ; rowIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTRElement trElement = tableTBodyElement . CreateTR ();
trElement . AlternativeText = string . Format ( "Row {0}" , rowIndex );
trElement . BackgroundColor = Aspose . Pdf . Color . LightGoldenrodYellow ;
trElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 0.75F , Aspose . Pdf . Color . DarkGray );
trElement . DefaultCellBorder = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 0.50F , Aspose . Pdf . Color . Blue );
trElement . MinRowHeight = 100.0 ;
trElement . FixedRowHeight = 120.0 ;
trElement . IsInNewPage = ( rowIndex % 3 == 1 );
trElement . IsRowBroken = true ;
var cellTextState = new Aspose . Pdf . Text . TextState ();
cellTextState . ForegroundColor = Aspose . Pdf . Color . Red ;
trElement . DefaultCellTextState = cellTextState ;
trElement . DefaultCellPadding = new Aspose . Pdf . MarginInfo ( 16.0 , 2.0 , 8.0 , 2.0 );
trElement . VerticalAlignment = Aspose . Pdf . VerticalAlignment . Bottom ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = trElement . CreateTD ();
tdElement . SetText ( string . Format ( "Cell [{0}, {1}]" , rowIndex , colIndex ));
}
}
Aspose . Pdf . LogicalStructure . TableTRElement footTrElement = tableTFootElement . CreateTR ();
footTrElement . AlternativeText = "Foot Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = footTrElement . CreateTD ();
tdElement . SetText ( string . Format ( "Foot {0}" , colIndex ));
}
document . Save ( dataDir + "StyleTableRow_out.pdf" );
}
using ( var document = new Aspose . Pdf . Document ( dataDir + "StyleTableRow_out.pdf" ))
{
bool isPdfUaCompliance = document . Validate ( dataDir + "StyleTableRow_log.xml" , Aspose . Pdf . PdfFormat . PDF_UA_1 );
Console . WriteLine ( string . Format ( "PDF/UA compliance: {0}" , isPdfUaCompliance ));
}
}
.NET 8
Copy
private static void StyleTableRow ( )
{
var dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
using var document1 = new Aspose . Pdf . Document ();
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document1 . TaggedContent ;
taggedContent . SetTitle ( "Example table row style" );
taggedContent . SetLanguage ( "en-US" );
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . TableElement tableElement = taggedContent . CreateTableElement ();
rootElement . AppendChild ( tableElement );
Aspose . Pdf . LogicalStructure . TableTHeadElement tableTHeadElement = tableElement . CreateTHead ();
Aspose . Pdf . LogicalStructure . TableTBodyElement tableTBodyElement = tableElement . CreateTBody ();
Aspose . Pdf . LogicalStructure . TableTFootElement tableTFootElement = tableElement . CreateTFoot ();
int rowCount = 7 ;
int colCount = 3 ;
int rowIndex ;
int colIndex ;
Aspose . Pdf . LogicalStructure . TableTRElement headTrElement = tableTHeadElement . CreateTR ();
headTrElement . AlternativeText = "Head Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTHElement thElement = headTrElement . CreateTH ();
thElement . SetText ( string . Format ( "Head {0}" , colIndex ));
}
for ( rowIndex = 0 ; rowIndex < rowCount ; rowIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTRElement trElement = tableTBodyElement . CreateTR ();
trElement . AlternativeText = string . Format ( "Row {0}" , rowIndex );
trElement . BackgroundColor = Aspose . Pdf . Color . LightGoldenrodYellow ;
trElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 0.75F , Aspose . Pdf . Color . DarkGray );
trElement . DefaultCellBorder = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 0.50F , Aspose . Pdf . Color . Blue );
trElement . MinRowHeight = 100.0 ;
trElement . FixedRowHeight = 120.0 ;
trElement . IsInNewPage = ( rowIndex % 3 == 1 );
trElement . IsRowBroken = true ;
var cellTextState = new Aspose . Pdf . Text . TextState ();
cellTextState . ForegroundColor = Aspose . Pdf . Color . Red ;
trElement . DefaultCellTextState = cellTextState ;
trElement . DefaultCellPadding = new Aspose . Pdf . MarginInfo ( 16.0 , 2.0 , 8.0 , 2.0 );
trElement . VerticalAlignment = Aspose . Pdf . VerticalAlignment . Bottom ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = trElement . CreateTD ();
tdElement . SetText ( string . Format ( "Cell [{0}, {1}]" , rowIndex , colIndex ));
}
}
Aspose . Pdf . LogicalStructure . TableTRElement footTrElement = tableTFootElement . CreateTR ();
footTrElement . AlternativeText = "Foot Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = footTrElement . CreateTD ();
tdElement . SetText ( string . Format ( "Foot {0}" , colIndex ));
}
document1 . Save ( dataDir + "StyleTableRow_out.pdf" );
using var document2 = new Aspose . Pdf . Document ( dataDir + "StyleTableRow_out.pdf" );
bool isPdfUaCompliance = document2 . Validate ( dataDir + "StyleTableRow_log.xml" , Aspose . Pdf . PdfFormat . PDF_UA_1 );
Console . WriteLine ( string . Format ( "PDF/UA compliance: {0}" , isPdfUaCompliance ));
}
تنسيق خلية الجدول
Aspose.PDF for .NET يتيح تنسيق خلية جدول في مستند PDF المعلّم. لتنسيق خلية جدول، يمكنك استخدام خصائص TableCellElement class. فيما يلي قائمة الخصائص التي يمكنك استخدامها لتنسيق خلية جدول:
توضح مقتطفات الشيفرة التالية كيفية تنسيق خلية جدول في مستند PDF المعلّم:
.NET Core 3.1
Copy
private static void StyleTableCell ( )
{
var dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
using ( var document = new Aspose . Pdf . Document ())
{
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document . TaggedContent ;
taggedContent . SetTitle ( "Example table cell style" );
taggedContent . SetLanguage ( "en-US" );
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . TableElement tableElement = taggedContent . CreateTableElement ();
rootElement . AppendChild ( tableElement );
Aspose . Pdf . LogicalStructure . TableTHeadElement tableTHeadElement = tableElement . CreateTHead ();
Aspose . Pdf . LogicalStructure . TableTBodyElement tableTBodyElement = tableElement . CreateTBody ();
Aspose . Pdf . LogicalStructure . TableTFootElement tableTFootElement = tableElement . CreateTFoot ();
int rowCount = 4 ;
int colCount = 4 ;
int rowIndex ;
int colIndex ;
Aspose . Pdf . LogicalStructure . TableTRElement headTrElement = tableTHeadElement . CreateTR ();
headTrElement . AlternativeText = "Head Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTHElement thElement = headTrElement . CreateTH ();
thElement . SetText ( string . Format ( "Head {0}" , colIndex ));
thElement . BackgroundColor = Aspose . Pdf . Color . GreenYellow ;
thElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 4.0F , Aspose . Pdf . Color . Gray );
thElement . IsNoBorder = true ;
thElement . Margin = new Aspose . Pdf . MarginInfo ( 16.0 , 2.0 , 8.0 , 2.0 );
thElement . Alignment = Aspose . Pdf . HorizontalAlignment . Right ;
}
for ( rowIndex = 0 ; rowIndex < rowCount ; rowIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTRElement trElement = tableTBodyElement . CreateTR ();
trElement . AlternativeText = string . Format ( "Row {0}" , rowIndex );
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
int colSpan = 1 ;
int rowSpan = 1 ;
if ( colIndex == 1 && rowIndex == 1 )
{
colSpan = 2 ;
rowSpan = 2 ;
}
else if ( colIndex == 2 && ( rowIndex == 1 || rowIndex == 2 ))
{
continue ;
}
else if ( rowIndex == 2 && ( colIndex == 1 || colIndex == 2 ))
{
continue ;
}
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = trElement . CreateTD ();
tdElement . SetText ( string . Format ( "Cell [{0}, {1}]" , rowIndex , colIndex ));
tdElement . BackgroundColor = Aspose . Pdf . Color . Yellow ;
tdElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 4.0F , Aspose . Pdf . Color . Gray );
tdElement . IsNoBorder = false ;
tdElement . Margin = new Aspose . Pdf . MarginInfo ( 8.0 , 2.0 , 8.0 , 2.0 );
tdElement . Alignment = Aspose . Pdf . HorizontalAlignment . Center ;
var cellTextState = new Aspose . Pdf . Text . TextState ();
cellTextState . ForegroundColor = Aspose . Pdf . Color . DarkBlue ;
cellTextState . FontSize = 7.5F ;
cellTextState . FontStyle = Aspose . Pdf . Text . FontStyles . Bold ;
cellTextState . Font = Aspose . Pdf . Text . FontRepository . FindFont ( "Arial" );
tdElement . DefaultCellTextState = cellTextState ;
tdElement . IsWordWrapped = true ;
tdElement . VerticalAlignment = Aspose . Pdf . VerticalAlignment . Center ;
tdElement . ColSpan = colSpan ;
tdElement . RowSpan = rowSpan ;
}
}
Aspose . Pdf . LogicalStructure . TableTRElement footTrElement = tableTFootElement . CreateTR ();
footTrElement . AlternativeText = "Foot Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = footTrElement . CreateTD ();
tdElement . SetText ( string . Format ( "Foot {0}" , colIndex ));
}
document . Save ( dataDir + "StyleTableCell_out.pdf" );
}
using ( var document = new Aspose . Pdf . Document ( dataDir + "StyleTableCell_out.pdf" ))
{
bool isPdfUaCompliance = document . Validate ( dataDir + "StyleTableCell_log.xml" , Aspose . Pdf . PdfFormat . PDF_UA_1 );
Console . WriteLine ( string . Format ( "PDF/UA compliance: {0}" , isPdfUaCompliance ));
}
}
.NET 8
Copy
private static void StyleTableCell ( )
{
var dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
using var document1 = new Aspose . Pdf . Document ();
Aspose . Pdf . Tagged . ITaggedContent taggedContent = document1 . TaggedContent ;
taggedContent . SetTitle ( "Example table cell style" );
taggedContent . SetLanguage ( "en-US" );
Aspose . Pdf . LogicalStructure . StructureElement rootElement = taggedContent . RootElement ;
Aspose . Pdf . LogicalStructure . TableElement tableElement = taggedContent . CreateTableElement ();
rootElement . AppendChild ( tableElement );
Aspose . Pdf . LogicalStructure . TableTHeadElement tableTHeadElement = tableElement . CreateTHead ();
Aspose . Pdf . LogicalStructure . TableTBodyElement tableTBodyElement = tableElement . CreateTBody ();
Aspose . Pdf . LogicalStructure . TableTFootElement tableTFootElement = tableElement . CreateTFoot ();
int rowCount = 4 ;
int colCount = 4 ;
int rowIndex ;
int colIndex ;
Aspose . Pdf . LogicalStructure . TableTRElement headTrElement = tableTHeadElement . CreateTR ();
headTrElement . AlternativeText = "Head Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTHElement thElement = headTrElement . CreateTH ();
thElement . SetText ( string . Format ( "Head {0}" , colIndex ));
thElement . BackgroundColor = Aspose . Pdf . Color . GreenYellow ;
thElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 4.0F , Aspose . Pdf . Color . Gray );
thElement . IsNoBorder = true ;
thElement . Margin = new Aspose . Pdf . MarginInfo ( 16.0 , 2.0 , 8.0 , 2.0 );
thElement . Alignment = Aspose . Pdf . HorizontalAlignment . Right ;
}
for ( rowIndex = 0 ; rowIndex < rowCount ; rowIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTRElement trElement = tableTBodyElement . CreateTR ();
trElement . AlternativeText = string . Format ( "Row {0}" , rowIndex );
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
int colSpan = 1 ;
int rowSpan = 1 ;
if ( colIndex == 1 && rowIndex == 1 )
{
colSpan = 2 ;
rowSpan = 2 ;
}
else if ( colIndex == 2 && ( rowIndex == 1 || rowIndex == 2 ))
{
continue ;
}
else if ( rowIndex == 2 && ( colIndex == 1 || colIndex == 2 ))
{
continue ;
}
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = trElement . CreateTD ();
tdElement . SetText ( string . Format ( "Cell [{0}, {1}]" , rowIndex , colIndex ));
tdElement . BackgroundColor = Aspose . Pdf . Color . Yellow ;
tdElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 4.0F , Aspose . Pdf . Color . Gray );
tdElement . IsNoBorder = false ;
tdElement . Margin = new Aspose . Pdf . MarginInfo ( 8.0 , 2.0 , 8.0 , 2.0 );
tdElement . Alignment = Aspose . Pdf . HorizontalAlignment . Center ;
var cellTextState = new Aspose . Pdf . Text . TextState ();
cellTextState . ForegroundColor = Aspose . Pdf . Color . DarkBlue ;
cellTextState . FontSize = 7.5F ;
cellTextState . FontStyle = Aspose . Pdf . Text . FontStyles . Bold ;
cellTextState . Font = Aspose . Pdf . Text . FontRepository . FindFont ( "Arial" );
tdElement . DefaultCellTextState = cellTextState ;
tdElement . IsWordWrapped = true ;
tdElement . VerticalAlignment = Aspose . Pdf . VerticalAlignment . Center ;
tdElement . ColSpan = colSpan ;
tdElement . RowSpan = rowSpan ;
}
}
Aspose . Pdf . LogicalStructure . TableTRElement footTrElement = tableTFootElement . CreateTR ();
footTrElement . AlternativeText = "Foot Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
Aspose . Pdf . LogicalStructure . TableTDElement tdElement = footTrElement . CreateTD ();
tdElement . SetText ( string . Format ( "Foot {0}" , colIndex ));
}
document1 . Save ( dataDir + "StyleTableCell_out.pdf" );
using var document2 = new Aspose . Pdf . Document ( dataDir + "StyleTableCell_out.pdf" );
bool isPdfUaCompliance = document2 . Validate ( dataDir + "StyleTableCell_log.xml" , Aspose . Pdf . PdfFormat . PDF_UA_1 );
Console . WriteLine ( string . Format ( "PDF/UA compliance: {0}" , isPdfUaCompliance ));
}
ضبط موضع الجدول
توضح الشيفرة التالية كيفية ضبط موضع الجدول في مستند PDF المعلّم:
.NET Core 3.1
Copy
private static void AdjustTablePosition ( )
{
var dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
using ( var document = new Aspose . Pdf . Document ())
{
var taggedContent = document . TaggedContent ;
taggedContent . SetTitle ( "Example table cell style" );
taggedContent . SetLanguage ( "en-US" );
var rootElement = taggedContent . RootElement ;
var tableElement = taggedContent . CreateTableElement ();
rootElement . AppendChild ( tableElement );
var positionSettings = new Aspose . Pdf . Tagged . PositionSettings
{
HorizontalAlignment = Aspose . Pdf . HorizontalAlignment . None ,
Margin = new Aspose . Pdf . MarginInfo
{
Left = 20 ,
Right = 0 ,
Top = 0 ,
Bottom = 0
},
VerticalAlignment = Aspose . Pdf . VerticalAlignment . None ,
IsFirstParagraphInColumn = false ,
IsKeptWithNext = false ,
IsInNewPage = false ,
IsInLineParagraph = false
};
tableElement . AdjustPosition ( positionSettings );
var tableTHeadElement = tableElement . CreateTHead ();
var tableTBodyElement = tableElement . CreateTBody ();
var tableTFootElement = tableElement . CreateTFoot ();
var rowCount = 4 ;
var colCount = 4 ;
int rowIndex ;
int colIndex ;
var headTrElement = tableTHeadElement . CreateTR ();
headTrElement . AlternativeText = "Head Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
var thElement = headTrElement . CreateTH ();
thElement . SetText ( string . Format ( "Head {0}" , colIndex ));
thElement . BackgroundColor = Aspose . Pdf . Color . GreenYellow ;
thElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 4.0F , Aspose . Pdf . Color . Gray );
thElement . IsNoBorder = true ;
thElement . Margin = new Aspose . Pdf . MarginInfo ( 16.0 , 2.0 , 8.0 , 2.0 );
thElement . Alignment = Aspose . Pdf . HorizontalAlignment . Right ;
}
for ( rowIndex = 0 ; rowIndex < rowCount ; rowIndex ++)
{
var trElement = tableTBodyElement . CreateTR ();
trElement . AlternativeText = string . Format ( "Row {0}" , rowIndex );
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
var colSpan = 1 ;
var rowSpan = 1 ;
if ( colIndex == 1 && rowIndex == 1 )
{
colSpan = 2 ;
rowSpan = 2 ;
}
else if ( colIndex == 2 && ( rowIndex == 1 || rowIndex == 2 ))
{
continue ;
}
else if ( rowIndex == 2 && ( colIndex == 1 || colIndex == 2 ))
{
continue ;
}
var tdElement = trElement . CreateTD ();
tdElement . SetText ( string . Format ( "Cell [{0}, {1}]" , rowIndex , colIndex ));
tdElement . BackgroundColor = Aspose . Pdf . Color . Yellow ;
tdElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 4.0F , Aspose . Pdf . Color . Gray );
tdElement . IsNoBorder = false ;
tdElement . Margin = new Aspose . Pdf . MarginInfo ( 8.0 , 2.0 , 8.0 , 2.0 );
tdElement . Alignment = Aspose . Pdf . HorizontalAlignment . Center ;
var cellTextState = new Aspose . Pdf . Text . TextState ();
cellTextState . ForegroundColor = Aspose . Pdf . Color . DarkBlue ;
cellTextState . FontSize = 7.5F ;
cellTextState . FontStyle = Aspose . Pdf . Text . FontStyles . Bold ;
cellTextState . Font = Aspose . Pdf . Text . FontRepository . FindFont ( "Arial" );
tdElement . DefaultCellTextState = cellTextState ;
tdElement . IsWordWrapped = true ;
tdElement . VerticalAlignment = Aspose . Pdf . VerticalAlignment . Center ;
tdElement . ColSpan = colSpan ;
tdElement . RowSpan = rowSpan ;
}
}
var footTrElement = tableTFootElement . CreateTR ();
footTrElement . AlternativeText = "Foot Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
var tdElement = footTrElement . CreateTD ();
tdElement . SetText ( string . Format ( "Foot {0}" , colIndex ));
}
document . Save ( dataDir + "AdjustTablePosition_out.pdf" );
}
using ( var document = new Aspose . Pdf . Document ( dataDir + "AdjustTablePosition_out.pdf" ))
{
var isPdfUaCompliance = document . Validate ( dataDir + "AdjustTablePosition_log.xml" , Aspose . Pdf . PdfFormat . PDF_UA_1 );
Console . WriteLine ( string . Format ( "PDF/UA compliance: {0}" , isPdfUaCompliance ));
}
}
.NET 8
Copy
private static void AdjustTablePosition ( )
{
var dataDir = RunExamples . GetDataDir_AsposePdf_WorkingDocuments ();
using var document = new Aspose . Pdf . Document ();
var taggedContent = document . TaggedContent ;
taggedContent . SetTitle ( "Example table cell style" );
taggedContent . SetLanguage ( "en-US" );
var rootElement = taggedContent . RootElement ;
var tableElement = taggedContent . CreateTableElement ();
rootElement . AppendChild ( tableElement );
var positionSettings = new Aspose . Pdf . Tagged . PositionSettings
{
HorizontalAlignment = Aspose . Pdf . HorizontalAlignment . None ,
Margin = new Aspose . Pdf . MarginInfo
{
Left = 20 ,
Right = 0 ,
Top = 0 ,
Bottom = 0
},
VerticalAlignment = Aspose . Pdf . VerticalAlignment . None ,
IsFirstParagraphInColumn = false ,
IsKeptWithNext = false ,
IsInNewPage = false ,
IsInLineParagraph = false
};
tableElement . AdjustPosition ( positionSettings );
var tableTHeadElement = tableElement . CreateTHead ();
var tableTBodyElement = tableElement . CreateTBody ();
var tableTFootElement = tableElement . CreateTFoot ();
var rowCount = 4 ;
var colCount = 4 ;
int rowIndex ;
int colIndex ;
var headTrElement = tableTHeadElement . CreateTR ();
headTrElement . AlternativeText = "Head Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
var thElement = headTrElement . CreateTH ();
thElement . SetText ( string . Format ( "Head {0}" , colIndex ));
thElement . BackgroundColor = Aspose . Pdf . Color . GreenYellow ;
thElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 4.0F , Aspose . Pdf . Color . Gray );
thElement . IsNoBorder = true ;
thElement . Margin = new Aspose . Pdf . MarginInfo ( 16.0 , 2.0 , 8.0 , 2.0 );
thElement . Alignment = Aspose . Pdf . HorizontalAlignment . Right ;
}
for ( rowIndex = 0 ; rowIndex < rowCount ; rowIndex ++)
{
var trElement = tableTBodyElement . CreateTR ();
trElement . AlternativeText = string . Format ( "Row {0}" , rowIndex );
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
var colSpan = 1 ;
var rowSpan = 1 ;
if ( colIndex == 1 && rowIndex == 1 )
{
colSpan = 2 ;
rowSpan = 2 ;
}
else if ( colIndex == 2 && ( rowIndex == 1 || rowIndex == 2 ))
{
continue ;
}
else if ( rowIndex == 2 && ( colIndex == 1 || colIndex == 2 ))
{
continue ;
}
var tdElement = trElement . CreateTD ();
tdElement . SetText ( string . Format ( "Cell [{0}, {1}]" , rowIndex , colIndex ));
tdElement . BackgroundColor = Aspose . Pdf . Color . Yellow ;
tdElement . Border = new Aspose . Pdf . BorderInfo ( Aspose . Pdf . BorderSide . All , 4.0F , Aspose . Pdf . Color . Gray );
tdElement . IsNoBorder = false ;
tdElement . Margin = new Aspose . Pdf . MarginInfo ( 8.0 , 2.0 , 8.0 , 2.0 );
tdElement . Alignment = Aspose . Pdf . HorizontalAlignment . Center ;
var cellTextState = new Aspose . Pdf . Text . TextState ();
cellTextState . ForegroundColor = Aspose . Pdf . Color . DarkBlue ;
cellTextState . FontSize = 7.5F ;
cellTextState . FontStyle = Aspose . Pdf . Text . FontStyles . Bold ;
cellTextState . Font = Aspose . Pdf . Text . FontRepository . FindFont ( "Arial" );
tdElement . DefaultCellTextState = cellTextState ;
tdElement . IsWordWrapped = true ;
tdElement . VerticalAlignment = Aspose . Pdf . VerticalAlignment . Center ;
tdElement . ColSpan = colSpan ;
tdElement . RowSpan = rowSpan ;
}
}
var footTrElement = tableTFootElement . CreateTR ();
footTrElement . AlternativeText = "Foot Row" ;
for ( colIndex = 0 ; colIndex < colCount ; colIndex ++)
{
var tdElement = footTrElement . CreateTD ();
tdElement . SetText ( string . Format ( "Foot {0}" , colIndex ));
}
document . Save ( dataDir + "AdjustTablePosition_out.pdf" );
using var documentOut = new Aspose . Pdf . Document ( dataDir + "AdjustTablePosition_out.pdf" );
var isPdfUaCompliance = documentOut . Validate ( dataDir + "AdjustTablePosition_log.xml" , Aspose . Pdf . PdfFormat . PDF_UA_1 );
Console . WriteLine ( string . Format ( "PDF/UA compliance: {0}" , isPdfUaCompliance ));
}