import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.pdf.CMYKColor;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfGState;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfTransparencyGroup;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
float gap = (document.getPageSize().width() - 400) / 3;
PdfTemplate tp;
PdfTransparencyGroup group;
tp = cb.createTemplate(200, 200);
pictureCircles(0, 0, tp);
group = new PdfTransparencyGroup();
group.setIsolated(true);
group.setKnockout(false);
tp.setGroup(group);
cb.addTemplate(tp, 200 + 2 * gap, 500);
document.close();
}
public static void pictureCircles(float x, float y, PdfContentByte cb) {
PdfGState gs = new PdfGState();
gs.setBlendMode(PdfGState.BM_MULTIPLY);
gs.setFillOpacity(1f);
cb.setGState(gs);
cb.setColorFill(new CMYKColor(0f, 0f, 0f, 0.15f));
cb.circle(x + 125, y + 75, 70);
cb.fill();
cb.circle(x + 125, y + 125, 70);
cb.fill();
}
}
29.52.Transparency |
| 29.52.1. | PdfTransparencyGroup |