Skip to content

Commit

Permalink
#326 - Yeah! We are now PDF/A1a compliant.
Browse files Browse the repository at this point in the history
Had to move the thead, tbody and tfoot rows directly as children of the table when using PDF version 1.4 or less.
  • Loading branch information
danfickle committed Mar 4, 2019
1 parent 96850ee commit 3136058
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.pdfbox.io.IOUtils;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.verapdf.pdfa.Foundries;
import org.verapdf.pdfa.PDFAParser;
Expand Down Expand Up @@ -61,7 +60,8 @@ public boolean run(String resource, PDFAFlavour flavour, PdfAConformance conform

PdfRendererBuilder builder = new PdfRendererBuilder();
builder.useFastMode();
builder.testMode(true);
//builder.testMode(true);
builder.usePdfVersion(conform.getPart() == 1 ? 1.4f : 1.5f);
builder.usePdfAConformance(conform);
builder.useFont(new File("target/test/artefacts/Karla-Bold.ttf"), "TestFont");
builder.withHtmlContent(html, PdfATester.class.getResource("/html/").toString());
Expand Down Expand Up @@ -109,8 +109,7 @@ public void testAllInOnePdfA1b() throws Exception {
assertTrue(run("all-in-one-no-alpha", PDFAFlavour.PDFA_1_B, PdfAConformance.PDFA_1_B));
}

@Ignore // Failing because TFoot, Tbody and THead strcuture types were only introduced with PDF 1.5.
@Test // We have to factor them out when using PDF/A1a.
@Test
public void testAllInOnePdfA1a() throws Exception {
assertTrue(run("all-in-one-no-alpha", PDFAFlavour.PDFA_1_A, PdfAConformance.PDFA_1_A));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ private static class TableStructualElement extends AbstractStructualElement {
final TableHeadStructualElement thead = new TableHeadStructualElement();
final List<TableBodyStructualElement> tbodies = new ArrayList<>(1);
final TableFootStructualElement tfoot = new TableFootStructualElement();
float pdfVersion = 1.5f;

@Override
void addChild(AbstractTreeItem child) {
Expand All @@ -387,6 +388,10 @@ void addChild(AbstractTreeItem child) {
}
}

void setPdfVersion(float version) {
this.pdfVersion = version;
}

@Override
String getPdfTag() {
return StandardStructureTypes.TABLE;
Expand All @@ -398,9 +403,17 @@ void finish(AbstractStructualElement parent) {

createPdfStrucureElement(parent, child);

finishTreeItem(child.thead, child);
finishTreeItems(child.tbodies, child);
finishTreeItem(child.tfoot, child);
if (pdfVersion < 1.5f) {
// THead, TBody and TFoot were introduced in PDF 1.5 so if we can not use
// them then we process their rows directly and add them to the table.
finishTreeItems(child.thead.children, child);
child.tbodies.forEach(tbody -> finishTreeItems(tbody.children, child));
finishTreeItems(child.tfoot.children, child);
} else {
finishTreeItem(child.thead, child);
finishTreeItems(child.tbodies, child);
finishTreeItem(child.tfoot, child);
}
}
}

Expand Down Expand Up @@ -659,7 +672,6 @@ private static class FigureContentItem extends GenericContentItem {
}

private static void logIncompatibleChild(AbstractTreeItem parent, AbstractTreeItem child, Class<?> expected) {
System.out.println("OH OH");
XRLog.general(Level.WARNING,
"Trying to add incompatible child to parent item: " +
" child type=" + child.getClass().getSimpleName() +
Expand Down Expand Up @@ -836,6 +848,8 @@ private AbstractStructualElement createStructureItem(StructureType type, Box box

TableStructualElement table = (TableStructualElement) box.getParent().getAccessibilityObject();

table.setPdfVersion(_od.getWriter().getVersion());

if (box.getStyle().isIdent(CSSName.DISPLAY, IdentValue.TABLE_HEADER_GROUP)) {
child = table.thead;
} else if (box.getStyle().isIdent(CSSName.DISPLAY, IdentValue.TABLE_ROW_GROUP)) {
Expand Down

0 comments on commit 3136058

Please sign in to comment.