当前位置: 首页>>代码示例>>C#>>正文


C# Document.Open方法代码示例

本文整理汇总了C#中Document.Open方法的典型用法代码示例。如果您正苦于以下问题:C# Document.Open方法的具体用法?C# Document.Open怎么用?C# Document.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Document的用法示例。


在下文中一共展示了Document.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestCreatePdfA_2

        virtual public void TestCreatePdfA_2()
        {
            bool exceptionThrown = false;
            Document document;
            PdfAWriter writer;
            try
            {
                string filename = OUT + "TestCreatePdfA_1.pdf";
                FileStream fos = new FileStream(filename, FileMode.Create);

                document = new Document();

                writer = PdfAWriter.GetInstance(document, fos, PdfAConformanceLevel.PDF_A_1A);
                writer.CreateXmpMetadata();

                document.Open();

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

                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);
                document.Close();
            }
            catch (PdfAConformanceException)
            {
                exceptionThrown = true;
            }
            if (!exceptionThrown)
                Assert.Fail("PdfAConformance exception should be thrown");
        }
开发者ID:jagruti23,项目名称:itextsharp,代码行数:34,代码来源:PdfAWriterTest.cs

示例2: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Global.Init(this);

            m_vPDF = new CustomPdfView(this);

            var doc = new Document();
            int ret = doc.Open("/mnt/extSdCard/test.pdf", null);

            switch (ret)
            {
                case -1://need input password
                    Finish();
                    break;
                case -2://unknown encryption
                    Finish();
                    break;
                case -3://damaged or invalid format
                    Finish();
                    break;
                case -10://access denied or invalid file path
                    Finish();
                    break;
                case 0://succeeded, and continue
                    break;
                default://unknown error
                    Finish();
                    break;
            }
            m_vPDF.Document = doc;
            SetContentView(m_vPDF);
        }
开发者ID:Antonio24991GM,项目名称:RadaeePDF-Xamarin,代码行数:34,代码来源:Activity1.cs

示例3: CreatePdfAutomaticTest

        virtual public void CreatePdfAutomaticTest() {
            String fileName = "xmp_metadata_automatic.pdf";
            // step 1
            Document document = new Document();
            // step 2
            PdfWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT_FOLDER + fileName, FileMode.Create),
                                                      PdfAConformanceLevel.PDF_A_1B);
            document.AddTitle("Hello World example");
            document.AddSubject("This example shows how to add metadata & XMP");
            document.AddKeywords("Metadata, iText, step 3");
            document.AddCreator("My program using 'iText'");
            document.AddAuthor("Bruno Lowagie & Paulo Soares");
            writer.CreateXmpMetadata();
            // step 3
            document.Open();
            Font font = FontFactory.GetFont("../../resources/text/pdfa/FreeMonoBold.ttf", BaseFont.WINANSI,
                                            BaseFont.EMBEDDED, 12);
            document.Add(new Paragraph("Hello World", font));

            FileStream iccStream = new FileStream("../../resources/text/pdfa/sRGB Color Space Profile.icm",
                                                 FileMode.Open);
            ICC_Profile icc = ICC_Profile.GetInstance(iccStream);
            iccStream.Close();

            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);
            // step 5
            document.Close();
            CompareResults(fileName, fileName);
        }
开发者ID:jagruti23,项目名称:itextsharp,代码行数:29,代码来源:PdfAXmpWriterTest.cs

示例4: MetadaCheckTest

        public void MetadaCheckTest() {
            FileStream fos = new FileStream(OUT + "metadaPDFA2CheckTest1.pdf", FileMode.Create);
            Document document = new Document();
            PdfWriter writer = PdfAWriter.GetInstance(document, fos, PdfAConformanceLevel.PDF_A_2B);
            document.Open();
            PdfContentByte canvas = writer.DirectContent;

            canvas.SetColorFill(BaseColor.LIGHT_GRAY);
            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.LineTo(writer.PageSize.Left, writer.PageSize.Bottom);
            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 exc) {
                exceptionThrown = true;
            }

            if (!exceptionThrown)
                Assert.Fail("PdfAConformance exception should be thrown on unknown blend mode.");
        }
开发者ID:smartleos,项目名称:itextsharp,代码行数:31,代码来源:PdfA2CheckerTest.cs

示例5: FileHeader

        virtual public void FileHeader()
        {
            MemoryStream baos = new MemoryStream();
            Document document = new Document();
            PdfWriter.GetInstance(document, baos);
            document.Open();
            document.Add(new Chunk("Hello World"));
            document.Close();

            byte[] bytes = baos.ToArray();
            Assert.AreEqual(bytes[0], '%');
            Assert.IsTrue((sbyte)bytes[10] < 0);
            Assert.IsTrue((sbyte)bytes[11] < 0);
            Assert.IsTrue((sbyte)bytes[12] < 0);
            Assert.IsTrue((sbyte)bytes[13] < 0);
        }
开发者ID:newlysoft,项目名称:itextsharp,代码行数:16,代码来源:PdfAFileStructureTest.cs

示例6: streamObjects

        virtual public void streamObjects()
        {
            MemoryStream baos = new MemoryStream();
            Document document = new Document();
            PdfWriter writer = PdfWriter.GetInstance(document, baos);
            document.Open();
            document.Add(new Chunk("Hello World"));
            PdfIndirectReference refa =
                writer.AddToBody(new PdfStream(Encoding.UTF8.GetBytes("Hello World"))).IndirectReference;
            writer.Info.Put(new PdfName("HelloWorld"), refa);
            document.Close();

            byte[] bytes = baos.ToArray();
            String str = Encoding.UTF8.GetString(bytes, 22, 44);
            Assert.AreEqual("\n<</Length 11>>stream\nHello World\nendstream\n", str);
        }
开发者ID:jagruti23,项目名称:itextsharp,代码行数:16,代码来源:PdfAFileStructureTest.cs

示例7: FileTrailer

        virtual public void FileTrailer()
        {
            MemoryStream baos = new MemoryStream();
            Document document = new Document();
            PdfWriter.GetInstance(document, baos);
            document.Open();
            document.Add(new Chunk("Hello World"));
            document.Close();

            byte[] bytes = baos.ToArray();
            String str = Encoding.UTF8.GetString(bytes, bytes.Length - 6, 6);
            Assert.AreEqual("%%EOF\n", str);
            PdfReader reader = new PdfReader(baos.ToArray());
            Assert.IsNotNull(reader.Trailer.Get(PdfName.ID));
            reader.Close();
        }
开发者ID:jagruti23,项目名称:itextsharp,代码行数:16,代码来源:PdfAFileStructureTest.cs

示例8: TransparencyCheckTest1

        public void TransparencyCheckTest1() {
            string filename = OUT + "pdfa2TransparencyCheckTest1.pdf";
            FileStream fos = new FileStream(filename, FileMode.Create);
            Document document = new Document();
            PdfAWriter writer = PdfAWriter.GetInstance(document, fos, PdfAConformanceLevel.PDF_A_2B);
            document.Open();

            PdfContentByte canvas = writer.DirectContent;

            canvas.SaveState();
            PdfGState gs = new PdfGState();
            gs.BlendMode = PdfGState.BM_DARKEN;
            canvas.SetGState(gs);
            canvas.Rectangle(100, 100, 100, 100);
            canvas.Fill();
            canvas.RestoreState();

            canvas.SaveState();
            gs = new PdfGState();
            gs.BlendMode = new PdfName("Lighten");
            canvas.SetGState(gs);
            canvas.Rectangle(200, 200, 100, 100);
            canvas.Fill();
            canvas.RestoreState();

            bool conformanceExceptionThrown = false;
            try {
                canvas.SaveState();
                gs = new PdfGState();
                gs.BlendMode = new PdfName("UnknownBM");
                canvas.SetGState(gs);
                canvas.Rectangle(300, 300, 100, 100);
                canvas.Fill();
                canvas.RestoreState();

                document.Close();
            }
            catch (PdfAConformanceException pdface) {
                conformanceExceptionThrown = true;
            }

            if (!conformanceExceptionThrown)
                Assert.Fail("PdfAConformance exception should be thrown on unknown blend mode.");
        }
开发者ID:smartleos,项目名称:itextsharp,代码行数:44,代码来源:PdfA2CheckerTest.cs

示例9: CreatePdfTest

        virtual public void CreatePdfTest() {
            String fileName = "xmp_metadata.pdf";
            // step 1
            Document document = new Document();
            // step 2
            PdfWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT_FOLDER + fileName, FileMode.Create),
                                                      PdfAConformanceLevel.PDF_A_2B);
            writer.SetTagged();
            writer.CreateXmpMetadata();
            XmpWriter xmp = writer.XmpWriter;

            DublinCoreProperties.AddSubject(xmp.XmpMeta, "Hello World");
            DublinCoreProperties.AddSubject(xmp.XmpMeta, "XMP & Metadata");
            DublinCoreProperties.AddSubject(xmp.XmpMeta, "Metadata");

            PdfProperties.SetKeywords(xmp.XmpMeta, "Hello World, XMP & Metadata, Metadata");
            PdfProperties.SetVersion(xmp.XmpMeta, "1.4");

            // step 3
            document.Open();
            document.AddLanguage("en_US");

            // step 4
            Font font = FontFactory.GetFont("../../resources/text/pdfa/FreeMonoBold.ttf", BaseFont.WINANSI,
                                            BaseFont.EMBEDDED, 12);
            document.Add(new Paragraph("Hello World", font));
            FileStream iccStream = new FileStream("../../resources/text/pdfa/sRGB Color Space Profile.icm",
                                                 FileMode.Open);
            ICC_Profile icc = ICC_Profile.GetInstance(iccStream);
            iccStream.Close();
            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);
            // step 5
            document.Close();

            CompareResults(fileName, fileName);
        }
开发者ID:jagruti23,项目名称:itextsharp,代码行数:36,代码来源:PdfAXmpWriterTest.cs

示例10: ImageCheckTest2

        public void ImageCheckTest2() {
            string filename = OUT + "ImageCheckTest2.pdf";
            FileStream fos = new FileStream(filename, FileMode.Create);
            Document document = new Document();
            PdfWriter writer = PdfAWriter.GetInstance(document, fos, PdfAConformanceLevel.PDF_A_2B);
            writer.CreateXmpMetadata();
            document.Open();

            List<String> pdfaErrors = new List<String>();
            try {
                Image img = Image.GetInstance(RESOURCES + @"jpeg2000\p0_01.j2k");
                document.Add(img);
                document.NewPage();
            }
            catch (Exception e) {
                pdfaErrors.Add(e.Message);
            }

            try {
                Image img = Image.GetInstance(RESOURCES + @"jpeg2000\p0_02.j2k");
                document.Add(img);
            }
            catch (Exception e) {
                pdfaErrors.Add(e.Message);
            }

            try {
                Image img = Image.GetInstance(RESOURCES + @"jpeg2000\p1_01.j2k");
                document.Add(img);
            }
            catch (Exception e) {
                pdfaErrors.Add(e.Message);
            }

            try {
                Image img = Image.GetInstance(RESOURCES + @"jpeg2000\p1_02.j2k");
                document.Add(img);
            }
            catch (Exception e) {
                pdfaErrors.Add(e.Message);
            }

            Assert.AreEqual(4, pdfaErrors.Count);
            for (int i = 0; i < 4; i++) {
                Assert.AreEqual(true, pdfaErrors[i].Contains("JPX"));
            }

            document.Close();
        }
开发者ID:smartleos,项目名称:itextsharp,代码行数:49,代码来源:PdfA2CheckerTest.cs

示例11: AnnotationCheckTest6

        public void AnnotationCheckTest6() {
            Document document = new Document();
            PdfAWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT + "annotationCheckTest6.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));

            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);

            PdfAnnotation annot = new PdfAnnotation(writer, new Rectangle(100, 100, 200, 200));
            annot.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT));
            annot.Put(PdfName.SUBTYPE, PdfName.WIDGET);
            annot.Put(PdfName.CONTENTS, new PdfDictionary());
            annot.Put(PdfName.FT, new PdfName("Btn"));
            PdfDictionary ap = new PdfDictionary();
            PdfStream s = new PdfStream(Encoding.Default.GetBytes("Hello World"));
            //PdfDictionary s = new PdfDictionary();
            ap.Put(PdfName.N, writer.AddToBody(s).IndirectReference);
            annot.Put(PdfName.AP, ap);
            PdfContentByte canvas = writer.DirectContent;
            canvas.AddAnnotation(annot);
            bool exceptionThrown = false;
            try {
                document.Close();
            }
            catch (PdfAConformanceException e) {
                if (e.GetObject() == annot && e.Message
                    .Equals("Appearance dictionary of Widget subtype and Btn field type shall contain only the n key with dictionary value")) {
                    exceptionThrown = true;
                }
            }
            if (!exceptionThrown)
                Assert.Fail("PdfAConformanceException should be thrown.");
        }
开发者ID:smartleos,项目名称:itextsharp,代码行数:40,代码来源:PdfA2CheckerTest.cs

示例12: AnnotationCheckTest4

        public void AnnotationCheckTest4() {
            Document document = new Document();
            PdfAWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT + "annotationCheckTest4.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));

            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);

            PdfAnnotation annot = new PdfAnnotation(writer, new Rectangle(100, 100, 200, 200));
            annot.Put(PdfName.SUBTYPE, PdfName.TEXT);
            annot.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT & PdfAnnotation.FLAGS_INVISIBLE));
            PdfContentByte canvas = writer.DirectContent;
            canvas.AddAnnotation(annot);
            bool exceptionThrown = false;
            try {
                document.Close();
            }
            catch (PdfAConformanceException e) {
                if (e.GetObject() == annot && e.Message
                    .Equals("The F key's Print flag bit shall be set to 1 and its Hidden, Invisible, NoView and ToggleNoView flag bits shall be set to 0.")) {
                    exceptionThrown = true;
                }
            }
            if (!exceptionThrown)
                Assert.Fail("PdfAConformanceException should be thrown.");
        }
开发者ID:smartleos,项目名称:itextsharp,代码行数:33,代码来源:PdfA2CheckerTest.cs

示例13: AnnotationCheckTest2_3

        public void AnnotationCheckTest2_3() {
            Document document = new Document();
            PdfAWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT + "annotationCheckTest2_3.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));

            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);

            PdfAnnotation annot = new PdfAnnotation(writer, new Rectangle(100, 100, 200, 200));
            annot.Put(PdfName.SUBTYPE, PdfName.WIDGET);
            annot.Put(PdfName.CONTENTS, new PdfDictionary());
            annot.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT));
            PdfContentByte canvas = writer.DirectContent;
            canvas.AddAnnotation(annot);
            bool exceptionThrown = false;
            try {
                document.Close();
            }
            catch (PdfAConformanceException e) {
                if (e.GetObject() == annot && e.Message.Equals("Every annotation shall have at least one appearance dictionary")) {
                    exceptionThrown = true;
                }
            }
            if (!exceptionThrown)
                Assert.Fail("PdfAConformanceException with correct message should be thrown.");
        }
开发者ID:smartleos,项目名称:itextsharp,代码行数:33,代码来源:PdfA2CheckerTest.cs

示例14: AnnotationCheckTest2_2

        public void AnnotationCheckTest2_2() {
            Document document = new Document();
            PdfAWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT + "annotationCheckTest2_2.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));

            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);

            PdfAnnotation annot = new PdfAnnotation(writer, new Rectangle(100, 200, 100, 200));
            annot.Put(PdfName.SUBTYPE, PdfName.WIDGET);
            annot.Put(PdfName.CONTENTS, new PdfDictionary());
            annot.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT));
            PdfContentByte canvas = writer.DirectContent;
            canvas.AddAnnotation(annot);
            document.Close();
        }
开发者ID:smartleos,项目名称:itextsharp,代码行数:23,代码来源:PdfA2CheckerTest.cs

示例15: CanvasCheckTest2

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

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

            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);

            PdfContentByte canvas = writer.DirectContent;
            for (int i = 0; i < 28; i++) {
                canvas.SaveState();
            }
            for (int i = 0; i < 28; i++) {
                canvas.RestoreState();
            }
            document.Close();
        }
开发者ID:smartleos,项目名称:itextsharp,代码行数:24,代码来源:PdfA2CheckerTest.cs


注:本文中的Document.Open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。