-
Notifications
You must be signed in to change notification settings - Fork 601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PdfPCell background color ignoring alpha channel of an rgba #276
Comments
I've found this. The alpha channel is ignored, because it's value is not delivered at this point. The alpha channel should be delivered to this method: But I don't know how to set this. I've found that there is the parameter "S" which is for transparency. See https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf Maybe someone else can help with this example: private static void cellWithRgb(Document doc) {
PdfPCell redCell = new PdfPCell(new Paragraph("Red"));
redCell.setBackgroundColor(new Color(255, 0, 0, 50));
PdfPCell greenCell = new PdfPCell(new Paragraph("Green"));
greenCell.setBackgroundColor(new Color(0, 255, 0, 100));
PdfPCell blueCell = new PdfPCell(new Paragraph("Blue"));
blueCell.setBackgroundColor(new Color(0, 204, 255, 255));
final PdfPTable table = new PdfPTable(1);
table.addCell(redCell);
table.addCell(greenCell);
table.addCell(blueCell);
doc.add(table);
} |
Here you have an example of the ContentByte in use: With this sample you see how to write table using DirectContent: Maybe you can manage using this for the background color. Here is a sample of code. Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try {
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("transparency-1.pdf"));
document.open();
Rectangle page = document.getPageSize();
PdfContentByte cb = writer.getDirectContent();
cb.saveState();
PdfGState gs1 = new PdfGState();
gs1.setFillOpacity(0.5f);
cb.setGState(gs1);
PdfPTable head = new PdfPTable(3);
for (int k = 1; k <= 6; ++k) {
PdfPCell cell = new PdfPCell(new Phrase("head " + k));
cell.setBackgroundColor(new Color(0, 204, 255));
head.addCell(cell);
}
head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(), cb);
cb.restoreState();
cb.sanityCheck();
}
catch (Exception de) {
de.printStackTrace();
}
document.close(); But as you can see the borders and the text inherit also of the transparency :/ |
Related: https://stackoverflow.com/a/56954685/1729265
|
@asturio maybe we need to build a release to make these changes available to all |
so this one should be closed? |
Is it expected behavior for PdfPCell to ignore the alpha channel value when you setBackgroundColor with a Color(r,g,b,a)?
I haven't seen anything in the docs/javadocs for this class regarding the alpha channel.
The text was updated successfully, but these errors were encountered: