OpenDocument() публичный Метод

Opens the document.
Version for languages that are not case-dependant. Once the document is opened, you can't write any Header- or Meta-information anymore. You have to open the document before you can begin to add content to the body of the document.
public OpenDocument ( ) : void
Результат void
Пример #1
0
        public PDFHelper(float width, float height)
        {
            m_width  = width;
            m_height = height;

            m_doc    = new iTextSharp.text.Document(new iTextSharp.text.Rectangle(0, 0, Width, Height));
            m_stream = new System.IO.MemoryStream();
            m_writer = iTextSharp.text.pdf.PdfWriter.GetInstance(m_doc, m_stream);
            m_doc.OpenDocument();
            m_canvas = Writer.DirectContent;
            Canvas.SetColorStroke(BaseColor.BLACK);
            Canvas.SetColorFill(BaseColor.WHITE);
        }
Пример #2
0
        static void Main(string[] args)
        {
            // Path
            var path = "C:\\Workspace\\Personal\\Lourtec-2018-i\\MCSDAppBuilder2018I\\Clase-5\\holaMundo.txt";

            /* Tip sobre los strings de forma nativa/implicita
             * "" al crear string con comillas dobles necesitan caracteres de escape para algunos caracteres especiales para eso se utiliza un backslash \, un doble backslash para incluir uno en el text \\
             * @"" copia strings literales, todos sin caracteres de escape, incluye saltos de linea
             * $"" permite generar concatenacion con anclas dinamicas con {}
             */
            var parentDirectory = Path.GetDirectoryName(path);

            Console.WriteLine(parentDirectory);

            var extension = Path.GetExtension(path);

            Console.WriteLine(extension);

            var root = Path.GetPathRoot(path);

            Console.WriteLine(root);

            var randomName = Path.GetRandomFileName();

            Console.WriteLine(randomName);
            // Directory

            var randomDirectoryName = $"{Path.GetDirectoryName(path)}\\{Path.GetRandomFileName()}";

            if (!Directory.Exists(randomDirectoryName))
            {
                Directory.CreateDirectory(randomDirectoryName);

                Console.WriteLine(Directory.GetParent(randomDirectoryName));
                Directory.SetCreationTime(randomDirectoryName, new DateTime(1999, 12, 15));
                Console.WriteLine(Directory.GetCreationTime(randomDirectoryName));
            }

            // DirectoryInfo
            Console.Write("------------Directory Info------------------");
            DirectoryInfo d = new DirectoryInfo(randomDirectoryName);

            Console.WriteLine($"{d.FullName} {d.CreationTime} {d.Attributes.ToString()}");

            // File
            randomName = randomDirectoryName + "\\" + randomName + ".txt";
            if (!File.Exists(randomName))
            {
                using (var fileStream = File.CreateText(randomName))
                {
                    fileStream.WriteLine("Hola Mundo");
                    fileStream.Flush();
                }

                Console.WriteLine(File.ReadAllText(randomName));
            }
            // FileInfo
            FileInfo f = new FileInfo(randomName);

            Console.WriteLine($"{f.FullName} {f.CreationTime} {f.Attributes}");


            // Creacion de Fantasmas
            List <Fantasma> fantasmas   = new List <Fantasma>();
            var             phantonPath = $"{Path.GetDirectoryName(path)}\\Fantasmas";

            if (!Directory.Exists(phantonPath))
            {
                Directory.CreateDirectory(phantonPath);
            }

            if (Directory.Exists(phantonPath))
            {
                Console.WriteLine("----Binary---");
                SerializacionBinaria(phantonPath, fantasmas);

                Console.WriteLine("----XML---");
                SerializacionXml(phantonPath, fantasmas);


                Console.WriteLine("----JSON---");
                SerializacionJson(phantonPath, fantasmas);
            }

            // PDF ITextSharp
            string pdfPath      = @"C:\Workspace\Personal\Lourtec-2018-i\MCSDAppBuilder2018I\Clase-5\phdThesis.pdf";
            string pdfPathClone = @"C:\Workspace\Personal\Lourtec-2018-i\MCSDAppBuilder2018I\Clase-5\Clone.pdf";


            iTextSharp.text.Document document = null;
            try
            {
                document = new iTextSharp.text.Document();
                PdfWriter write  = PdfWriter.GetInstance(document, new FileStream(pdfPathClone, FileMode.Create));
                Anchor    anchor = new Anchor("Hola Mundo");
                iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph();
                paragraph.Add(anchor);
                document.Open();
                document.OpenDocument();

                document.Add(new Chunk("Hola Mundo Chunk"));
                document.Add(paragraph);
                if (document.IsOpen())
                {
                    document.NewPage();
                }
                document.Close();
                write.Close();
            }
            catch (Exception ex)
            {
            }
        }