Beispiel #1
0
// ===========================================================================
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document()) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                PdfContentByte cb  = writer.DirectContent;
                float          gap = (document.PageSize.Width - 400) / 3;

                PictureBackdrop(gap, 500, cb);
                PictureBackdrop(200 + 2 * gap, 500, cb);
                PictureBackdrop(gap, 500 - 200 - gap, cb);
                PictureBackdrop(200 + 2 * gap, 500 - 200 - gap, cb);

                PictureCircles(gap, 500, cb);
                cb.SaveState();
                PdfGState gs1 = new PdfGState();
                gs1.FillOpacity = 0.5f;
                cb.SetGState(gs1);
                PictureCircles(200 + 2 * gap, 500, cb);
                cb.RestoreState();

                cb.SaveState();
                PdfTemplate          tp    = cb.CreateTemplate(200, 200);
                PdfTransparencyGroup group = new PdfTransparencyGroup();
                tp.Group = group;
                PictureCircles(0, 0, tp);
                cb.SetGState(gs1);
                cb.AddTemplate(tp, gap, 500 - 200 - gap);
                cb.RestoreState();

                cb.SaveState();
                tp       = cb.CreateTemplate(200, 200);
                tp.Group = group;
                PdfGState gs2 = new PdfGState();
                gs2.FillOpacity = 0.5f;
                gs2.BlendMode   = PdfGState.BM_HARDLIGHT;
                tp.SetGState(gs2);
                PictureCircles(0, 0, tp);
                cb.AddTemplate(tp, 200 + 2 * gap, 500 - 200 - gap);
                cb.RestoreState();

                cb.ResetRGBColorFill();
                ColumnText ct = new ColumnText(cb);
                Phrase     ph = new Phrase("Ungrouped objects\nObject opacity = 1.0");
                ct.SetSimpleColumn(ph, gap, 0, gap + 200, 500, 18,
                                   Element.ALIGN_CENTER
                                   );
                ct.Go();

                ph = new Phrase("Ungrouped objects\nObject opacity = 0.5");
                ct.SetSimpleColumn(ph, 200 + 2 * gap, 0, 200 + 2 * gap + 200, 500,
                                   18, Element.ALIGN_CENTER
                                   );
                ct.Go();

                ph = new Phrase(
                    "Transparency group\nObject opacity = 1.0\nGroup opacity = 0.5\nBlend mode = Normal"
                    );
                ct.SetSimpleColumn(ph, gap, 0, gap + 200, 500 - 200 - gap, 18,
                                   Element.ALIGN_CENTER
                                   );
                ct.Go();

                ph = new Phrase(
                    "Transparency group\nObject opacity = 0.5\nGroup opacity = 1.0\nBlend mode = HardLight"
                    );
                ct.SetSimpleColumn(ph, 200 + 2 * gap, 0, 200 + 2 * gap + 200,
                                   500 - 200 - gap, 18, Element.ALIGN_CENTER
                                   );
                ct.Go();
            }
        }