示例#1
0
        /// <summary>
        /// Creates a new document in the specified path, with the specified format, and opens it
        /// </summary>
        /// <param name="format"></param>
        /// <param name="path"></param>
        public IDocumentEditor Create(IDocumentTemplate format)
        {
            // Create document
            var document = format.CreateDocument();

            document.IsDirty = true;

            // Find and create editor
            IDocumentEditor editor = CreateEditor(document);

            // Trigger event
            if (DocumentOpened != null)
            {
                DocumentOpened(this, new DocumentOpenedEventArgs(editor));
            }

            return(editor);
        }
        public Stream GetContentStream()
        {
            bool deletionLock = deletionCountdown.TryAddCount();

            if (!deletionLock)
            {
                throw new FileNotFoundException("The cached file has been deleted.");
            }
            if (!created)
            {
                lock (creationLock)
                {
                    if (!created)
                    {
                        var dynamicTemplateData = new DynamicTemplateData(templateData);
                        using (var document = template.CreateDocument())
                        {
                            using (var fileStream = File.Create(path))
                            {
                                using (var pdfWriter = PdfWriter.GetInstance(document, fileStream))
                                {
                                    document.Open();
                                    template.WriteDocument(document, dynamicTemplateData);
                                    document.Close();
                                }
                            }
                        }

                        this.CreationDate = File.GetCreationTimeUtc(path);
                        this.created      = true;
                    }
                }
            }

            return(File.OpenRead(path));
        }