當前位置: 首頁>>代碼示例>>C#>>正文


C# PdfGState.Put方法代碼示例

本文整理匯總了C#中iTextSharp.text.pdf.PdfGState.Put方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfGState.Put方法的具體用法?C# PdfGState.Put怎麽用?C# PdfGState.Put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在iTextSharp.text.pdf.PdfGState的用法示例。


在下文中一共展示了PdfGState.Put方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: EgsCheckTest4

        public void EgsCheckTest4() {
            Document document = new Document();
            PdfAWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT + "pdfa2egsCheckTest4.pdf", FileMode.Create), PdfAConformanceLevel.PDF_A_2B);
            writer.CreateXmpMetadata();
            document.Open();

            Font font = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
            document.Add(new Paragraph("Hello World", font));

            PdfContentByte canvas = writer.DirectContent;
            PdfGState gs = new PdfGState();
            gs.Put(PdfName.TR2, new PdfName("Test"));
            gs.Put(PdfName.HTP, new PdfName("Test"));
            canvas.SaveState();
            canvas.SetGState(gs);
            canvas.RestoreState();
            canvas.MoveTo(writer.PageSize.Left, writer.PageSize.Bottom);
            canvas.LineTo(writer.PageSize.Right, writer.PageSize.Bottom);
            canvas.LineTo(writer.PageSize.Right, writer.PageSize.Top);
            canvas.Fill();

            FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read);
            ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
            iccProfileFileStream.Close();

            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

            bool exceptionThrown = false;
            try {
                document.Close();
            }
            catch (PdfAConformanceException e) {
                if (e.GetObject() == gs) {
                    exceptionThrown = true;
                }
            }
            if (!exceptionThrown)
                Assert.Fail("PdfAConformanceException should be thrown.");
        }
開發者ID:smartleos,項目名稱:itextsharp,代碼行數:39,代碼來源:PdfA2CheckerTest.cs

示例2: EgsCheckTest3

        public void EgsCheckTest3() {
            Document document = new Document();
            PdfAWriter writer = PdfAWriter.GetInstance(document,
                new FileStream(OUT + "pdfa2EgsCheckTest3.pdf", FileMode.Create), PdfAConformanceLevel.PDF_A_2A);
            writer.CreateXmpMetadata();
            document.Open();

            Font font = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
            document.Add(new Paragraph("Hello World", font));

            PdfContentByte canvas = writer.DirectContent;
            PdfGState gs = new PdfGState();
            PdfDictionary dict = new PdfDictionary();
            dict.Put(PdfName.HALFTONETYPE, new PdfNumber(5));
            dict.Put(PdfName.HALFTONENAME, new PdfName("Test"));
            gs.Put(PdfName.HT, dict);
            canvas.SetGState(gs);

            bool exceptionThrown = false;
            try {
                document.Close();
            }
            catch (PdfAConformanceException e) {
                exceptionThrown = true;
            }
            if (!exceptionThrown)
                Assert.Fail("PdfAConformanceException should be thrown.");
        }
開發者ID:smartleos,項目名稱:itextsharp,代碼行數:28,代碼來源:PdfA2CheckerTest.cs

示例3: TransparencyCheckTest4

        public void TransparencyCheckTest4() {
            // step 1
            Document document = new Document(new Rectangle(850, 600));
            // step 2
            PdfAWriter writer
                = PdfAWriter.GetInstance(document, new FileStream(OUT + "pdfa2TransperancyCheckTest4.pdf", FileMode.Create),
                    PdfAConformanceLevel.PDF_A_2B);
            writer.CreateXmpMetadata();
            // step 3
            document.Open();
            // step 4
            PdfContentByte canvas = writer.DirectContent;

            // add the clipped image
            Image img = Image.GetInstance(RESOURCES + "img/bruno_ingeborg.jpg");
            float w = img.ScaledWidth;
            float h = img.ScaledHeight;
            canvas.Ellipse(1, 1, 848, 598);
            canvas.Clip();
            canvas.NewPath();
            canvas.AddImage(img, w, 0, 0, h, 0, -600);

            // Create a transparent PdfTemplate
            PdfTemplate t2 = writer.DirectContent.CreateTemplate(850, 600);
            PdfTransparencyGroup transGroup = new PdfTransparencyGroup();
            transGroup.Put(PdfName.CS, PdfName.DEVICEGRAY);
            transGroup.Isolated = true;
            transGroup.Knockout = false;
            t2.Group = transGroup;

            // Add transparent ellipses to the template
            int gradationStep = 30;
            float[] gradationRatioList = new float[gradationStep];
            for (int i = 0; i < gradationStep; i++) {
                gradationRatioList[i] = 1 - (float) Math.Sin(Math.PI/180*90.0f/gradationStep*(i + 1));
            }
            for (int i = 1; i < gradationStep + 1; i++) {
                t2.SetLineWidth(5*(gradationStep + 1 - i));
                t2.SetGrayStroke(gradationRatioList[gradationStep - i]);
                t2.Ellipse(0, 0, 850, 600);
                t2.Stroke();
            }

            // Create an image mask for the direct content
            PdfDictionary maskDict = new PdfDictionary();
            maskDict.Put(PdfName.TYPE, PdfName.MASK);
            maskDict.Put(PdfName.S, new PdfName("Luminosity"));
            maskDict.Put(new PdfName("G"), t2.IndirectReference);
            PdfGState gState = new PdfGState();
            gState.Put(PdfName.SMASK, maskDict);
            canvas.SetGState(gState);

            canvas.AddTemplate(t2, 0, 0);

            FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read);
            ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
            iccProfileFileStream.Close();

            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

            // step 5
            document.Close();
        }
開發者ID:smartleos,項目名稱:itextsharp,代碼行數:63,代碼來源:PdfA2CheckerTest.cs


注:本文中的iTextSharp.text.pdf.PdfGState.Put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。