props.putMapping(mc1, enabled);
COSName mc2 = COSName.getPDFName("MC2");
props.putMapping(mc2, disabled);
//Setup page content stream and paint background/title
PDPageContentStream contentStream = new PDPageContentStream(doc, page, false, false);
PDFont font = PDType1Font.HELVETICA_BOLD;
contentStream.beginMarkedContentSequence(COSName.OC, mc0);
contentStream.beginText();
contentStream.setFont(font, 14);
contentStream.moveTextPositionByAmount(80, 700);
contentStream.drawString("PDF 1.5: Optional Content Groups");
contentStream.endText();
font = PDType1Font.HELVETICA;
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.moveTextPositionByAmount(80, 680);
contentStream.drawString("You should see a green textline, but no red text line.");
contentStream.endText();
contentStream.endMarkedContentSequence();
//Paint enabled layer
contentStream.beginMarkedContentSequence(COSName.OC, mc1);
contentStream.setNonStrokingColor(Color.GREEN);
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.moveTextPositionByAmount(80, 600);
contentStream.drawString(
"This is from an enabled layer. If you see this, that's good.");
contentStream.endText();
contentStream.endMarkedContentSequence();
//Paint disabled layer
contentStream.beginMarkedContentSequence(COSName.OC, mc2);
contentStream.setNonStrokingColor(Color.RED);
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.moveTextPositionByAmount(80, 500);
contentStream.drawString(
"This is from a disabled layer. If you see this, that's NOT good!");
contentStream.endText();
contentStream.endMarkedContentSequence();
contentStream.close();
File targetFile = new File(testResultsDir, "ocg-generation.pdf");
doc.save(targetFile.getAbsolutePath());
}
finally