Aspose.PDF for Java是一种快速,轻量级的PDF处理控件,无需使用Adobe Acrobat便可生成,修改,转换,渲染,保护和打印PDF文档。同时支持使用PDF,XFA,TXT,HTML,PCL,XML,XPS和图像文件格式。安全
Aspose.PDF for Java(点击下载)提供PDF压缩选项,表格建立和操做,图形支持,图像功能,普遍的超连接功能,扩展的安全控制和自定义字体处理。此外,开发人员能够经过其API或XML模板直接建立PDF文档,并能够建立表单或管理PDF文档中嵌入的表单域。app
Aspose.PDF for Java更新至v19.8,新增在标记PDF中实现表格支持,支持在单个页面中渲染全部内容,修复HTML到PDF没法解析引起的URL异常等问题。字体
PDF / UA:在标记PDF中实现表格支持spa
使用ITaggedContent接口的createTableElement()方法建立表。要为表建立Head,Body和Foot,请使用TableElement对象的createTHead(),createTBody()和createTFoot()方法。orm
抽象类TableRowCollectionElement是TableTHeadElement,TableTBodyElement和TableTFootElement类的基础。方法TableRowCollectionElement.createTR()为对应的对象建立行。 对象
表行对象属于TableTRElement calss。 方法TableTRElement.createTH()和TableTRElement.createTD()为相应的行建立行的单元格。 您还能够验证所建立文档的PDF / UA合规性。 下面的代码段显示了如何使用此功能。接口
Document document = new Document(); ITaggedContent taggedContent = document.getTaggedContent(); taggedContent.setTitle("Table example - THead, TBody, TFoot; Summary"); taggedContent.setLanguage("en-US"); StructureElement rootElement = taggedContent.getRootElement(); TableElement tableElement = taggedContent.createTableElement(); rootElement.appendChild(tableElement); TableTHeadElement tableTHeadElement = tableElement.createTHead(); TableTBodyElement tableTBodyElement = tableElement.createTBody(); TableTFootElement tableTFootElement = tableElement.createTFoot(); int rowCount = 7; int colCount = 3; int rowIndex; int colIndex; TableTRElement headTrElement = tableTHeadElement.createTR(); headTrElement.setAlternativeText("Head Row"); for (colIndex = 0; colIndex < colCount; colIndex++) { TableTHElement thElement = headTrElement.createTH(); thElement.setText("Head Cell [head row, "+colIndex+" ]"); } for (rowIndex = 0; rowIndex < rowCount; rowIndex++) { TableTRElement trElement = tableTBodyElement.createTR(); trElement.setAlternativeText("Row "+rowIndex); for (colIndex = 0; colIndex < colCount; colIndex++) { TableTDElement tdElement = trElement.createTD(); tdElement.setText("Cell ["+rowIndex+", "+colIndex+"]"); } } TableTRElement footTrElement = tableTFootElement.createTR(); footTrElement.setAlternativeText("Foot Row"); for (colIndex = 0; colIndex < colCount; colIndex++) { TableTDElement tdElement = footTrElement.createTD(); tdElement.setText("Foot Cell [foot row, "+colIndex+"]"); } StructureAttributes tableAttributes = tableElement.getAttributes().getAttributes(AttributeOwnerStandard.Table); StructureAttribute summaryAttribute = new StructureAttribute(AttributeKey.Summary); summaryAttribute.setStringValue("The summary text for table"); tableAttributes.setAttribute(summaryAttribute); // Save document document.save(dataDir+"TaggedTable_"+version+".pdf"); boolean isPdfUaCompliance = document.validate(new ByteArrayOutputStream(), PdfFormat.PDF_UA_1); System.out.println("PDF/UA compliance: "+ isPdfUaCompliance);