public void Verify_ClippingPath_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document();

            // step 2
            PdfWriter writer = PdfWriter.GetInstance(document, stream);

            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            var         img = Image.GetInstance(TestUtils.GetImagePath("hitchcock.png"));
            float       w   = img.ScaledWidth;
            float       h   = img.ScaledHeight;
            PdfTemplate t   = writer.DirectContent.CreateTemplate(850, 600);

            t.Ellipse(0, 0, 850, 600);
            t.Clip();
            t.NewPath();
            t.AddImage(img, w, 0, 0, h, 0, -600);
            Image clipped = Image.GetInstance(t);

            clipped.ScalePercent(50);
            document.Add(clipped);

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
Exemplo n.º 2
0
// ---------------------------------------------------------------------------
        public byte[] CreatePdf()
        {
            using (MemoryStream ms = new MemoryStream()) {
                // step 1
                using (Document document = new Document()) {
                    // step 2
                    PdfWriter writer = PdfWriter.GetInstance(document, ms);
                    // step 3
                    document.Open();
                    // step 4
                    Image img = Image.GetInstance(
                        Path.Combine(Utility.ResourceImage, RESOURCE)
                        );
                    float       w = img.ScaledWidth;
                    float       h = img.ScaledHeight;
                    PdfTemplate t = writer.DirectContent.CreateTemplate(850, 600);
                    t.Ellipse(0, 0, 850, 600);
                    t.Clip();
                    t.NewPath();
                    t.AddImage(img, w, 0, 0, h, 0, -600);
                    Image clipped = Image.GetInstance(t);
                    clipped.ScalePercent(50);
                    document.Add(clipped);
                }
                return(ms.ToArray());
            }
        }