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


C# Document.Close方法代码示例

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


在下文中一共展示了Document.Close方法的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: buttonMerge_Click

        private void buttonMerge_Click(object sender, RoutedEventArgs e)
        {
            //new Document
            Document doc = new Document();
            doc.LoadFromFile(@"..\..\..\..\..\Data\Fax.doc");

            String[] fieldNames
                = new String[] { "Contact Name", "Fax", "From", "Date", "Subject", "Content" };
            DateTime faxDate
                = this.datePickerFaxDate.SelectedDate.HasValue ?
                    this.datePickerFaxDate.SelectedDate.Value : DateTime.Now;
            String[] fieldValues
                = new String[] 
                {
                    this.textBoxTo.Text,
                    this.textBoxFax.Text,
                    this.textBoxFrom.Text,
                    faxDate.ToShortDateString(),
                    this.textBoxSubject.Text,
                    this.textBoxContent.Text
                };
            doc.MailMerge.Execute(fieldNames, fieldValues);

            bool? result = this.saveFileDialog.ShowDialog();
            if (result.HasValue && result.Value)
            {
                using (Stream stream = this.saveFileDialog.OpenFile())
                {
                    doc.SaveToStream(stream, FileFormat.Doc);
					doc.Close();
                }
            }
        }
开发者ID:e-iceblue,项目名称:Spire.Office-for-.NET,代码行数:33,代码来源:MainWindow.xaml.cs

示例3: ExtractTextFromImage

        /// <summary>
        /// Reason : To get Text from image
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public string ExtractTextFromImage(string fileName)
        {
            try
            {
                GC.WaitForPendingFinalizers();

                string ExtractedTest = "";
                string filePath = fileName.Trim() != "" ? @fileName : @"C:\Users\Cuelogic\Desktop\sample images\Untitled.png";
                Document doc = new Document();
                doc.Create(filePath);
                Thread.Sleep(500);
                try
                {
                    Thread.BeginCriticalRegion();
                    doc.OCR(MiLANGUAGES.miLANG_ENGLISH, true, true);
                }
                catch (Exception) { return ""; }

                MODI.Image modiImage = (doc.Images[0] as MODI.Image);
                ExtractedTest = modiImage.Layout.Text;
                doc.Close();
                Thread.EndCriticalRegion();
                return ExtractedTest;
            }
            catch (Exception)
            {
                return "";
            }
            finally
            {
                GC.Collect();
            }
        }
开发者ID:pankajw-cuelogic,项目名称:ImageProcessing,代码行数:38,代码来源:ImageProcess.cs

示例4: ExtractTextFromImage

        /// <summary>
        /// Reason : To get Text from image
        /// </summary>
        /// <param name="fileName">Input file name</param>
        /// <returns>Return Text from image</returns>
        public string ExtractTextFromImage(string fileName)
        {
            try
            {
                if (fileName.Trim() == "")
                    return "File name can not be null";

                string ExtractedTest = "";
                Document doc = new Document();
                GC.WaitForPendingFinalizers();
                doc.Create(fileName);
                Thread.Sleep(500);
                try
                {
                    Thread.BeginCriticalRegion();
                    doc.OCR(MiLANGUAGES.miLANG_ENGLISH, true, true);
                }
                catch (Exception) { return ""; }

                MODI.Image modiImage = (doc.Images[0] as MODI.Image);
                ExtractedTest = modiImage.Layout.Text;
                doc.Close();
                Thread.EndCriticalRegion();
                return ExtractedTest;
            }
            catch (Exception)
            {
                return "";
            }
            finally
            {
                GC.Collect();
            }
        }
开发者ID:pankajw-cuelogic,项目名称:ImageProcessing,代码行数:39,代码来源:ImageGrabber.cs

示例5: Read

        public override string Read(FileInfo fileInfo)
        {
            object nullobj = System.Reflection.Missing.Value;
            object readOnly = true;
            object noEncodingDialog = true;
            object confirmConversions = false;
            object visible = false;
            object filePath = fileInfo.FullName;
            object openAndRepair = false;

            object openFormat = WdOpenFormat.wdOpenFormatAuto;

            _wordDoc = WordApp.Documents.Open(
                ref filePath, ref confirmConversions, ref readOnly, ref nullobj, ref nullobj,
                ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref openFormat,
                ref nullobj, ref visible, ref openAndRepair, ref nullobj, ref noEncodingDialog,
                ref nullobj);

            // Make this document the active document.
            _wordDoc.Activate();

            string result = WordApp.ActiveDocument.Content.Text;

            _wordDoc.Close(ref nullobj, ref nullobj, ref nullobj);

            return result;
        }
开发者ID:NecoMeco,项目名称:BookToVoice,代码行数:27,代码来源:DocReader.cs

示例6: 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

示例7: Document_Class

            public Document_Class()
            {
                _doc = _DocApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);

                foreach (Microsoft.Office.Interop.Word.Section section in _doc.Sections)
                {
                    Range headerRange = section.Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                    headerRange.Fields.Add(headerRange, WdFieldType.wdFieldPage);
                    headerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
                    headerRange.Font.ColorIndex = WdColorIndex.wdBlue;
                    headerRange.Font.Size = 10;
                    headerRange.Text = "TEST";
                }
                foreach (Microsoft.Office.Interop.Word.Section wordSection in _doc.Sections)
                {
                    Range footerRange = wordSection.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                    footerRange.Font.ColorIndex = WdColorIndex.wdDarkRed;
                    footerRange.Font.Size = 10;
                    footerRange.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
                    footerRange.Text = "Footer TEST";
                }

                _doc.Content.SetRange(0, 0);
                _doc.Content.Text = "Text TEST";

                object filename = @"c:\temp1.docx";
                _doc.SaveAs2(ref filename);
                _doc.Close(ref missing, ref missing, ref missing);
                _doc = null;
                _DocApp.Quit(ref missing, ref missing, ref missing);
                _DocApp = null;
                //MessageBox.Show("Document created successfully !");
            }
开发者ID:RoykoSerhiy,项目名称:visualStudio_projects,代码行数:33,代码来源:MainWindow.xaml.cs

示例8: btnCreatePDF_Click

        protected void btnCreatePDF_Click(object sender, EventArgs e)
        {
            // create a PDF document
            Document document = new Document();

            // set the license key
            document.LicenseKey = "B4mYiJubiJiInIaYiJuZhpmahpGRkZE=";

            // add a page to the PDF document
            PdfPage firstPage = document.AddPage();

            string imagesPath = System.IO.Path.Combine(Server.MapPath("~"), "Images");

            // display image in the available space in page and with a auto determined height to keep the aspect ratio
            ImageElement imageElement1 = new ImageElement(0, 0, System.IO.Path.Combine(imagesPath, "evologo-250.png"));
            AddElementResult addResult = firstPage.AddElement(imageElement1);

            // display image with the specified width and the height auto determined to keep the aspect ratio
            // the images is displayed to the right of the previous image and the bounds of the image inside the current page
            // are taken from the AddElementResult object
            ImageElement imageElement2 = new ImageElement(addResult.EndPageBounds.Right + 10, 0, 100,
                    System.IO.Path.Combine(imagesPath, "evologo-250.png"));
            addResult = firstPage.AddElement(imageElement2);

            // Display image with the specified width and the specified height. It is possible for the image to not preserve the aspect ratio
            // The images is displayed to the right of the previous image and the bounds of the image inside the current page
            // are taken from the AddElementResult object
            ImageElement imageElement3 = new ImageElement(addResult.EndPageBounds.Right + 10, 0, 100, 50,
                    System.IO.Path.Combine(imagesPath, "evologo-250.png"));
            addResult = firstPage.AddElement(imageElement3);

            try
            {
                // get the PDF document bytes
                byte[] pdfBytes = document.Save();

                // send the generated PDF document to client browser

                // get the object representing the HTTP response to browser
                HttpResponse httpResponse = HttpContext.Current.Response;

                // add the Content-Type and Content-Disposition HTTP headers
                httpResponse.AddHeader("Content-Type", "application/pdf");
                httpResponse.AddHeader("Content-Disposition", String.Format("attachment; filename=ImageElement.pdf; size={0}", pdfBytes.Length.ToString()));

                // write the PDF document bytes as attachment to HTTP response
                httpResponse.BinaryWrite(pdfBytes);

                // Note: it is important to end the response, otherwise the ASP.NET
                // web page will render its content to PDF document stream
                httpResponse.End();
            }
            finally
            {
                // close the PDF document to release the resources
                document.Close();
            }
        }
开发者ID:ParallaxIT,项目名称:tdb-ws,代码行数:58,代码来源:ImageElementDemo.aspx.cs

示例9: ExtractTextFromImage

 private string ExtractTextFromImage(string filePath)
 {
     Document modiDocument = new Document();
     modiDocument.Create(filePath);
     modiDocument.OCR(MiLANGUAGES.miLANG_ENGLISH);
     MODI.Image modiImage = (modiDocument.Images[0] as MODI.Image);
     string extractedText = modiImage.Layout.Text;
     modiDocument.Close();
     return extractedText;
 }
开发者ID:mkiran1992,项目名称:TextExtractor,代码行数:10,代码来源:CS.aspx.cs

示例10: Parse

        public void Parse(object src, object dest)
        {
            if (src == null || string.IsNullOrEmpty(src.ToString()))
            {
                throw new ArgumentNullException("源文件不能为空");
            }
            if (dest == null || string.IsNullOrEmpty(dest.ToString()))
            {
                throw new ArgumentNullException("目标路径不能为空");
            }
            try
            {
                doc = wordApp.Documents.Open(ref src, ref paraMissing, ref paraMissing
                    , ref paraMissing, ref paraMissing
                    , ref paraMissing, ref paraMissing
                    , ref paraMissing, ref paraMissing, ref paraMissing, ref paraMissing
                    , ref paraMissing, ref paraMissing, ref paraMissing, ref paraMissing
                    , ref paraMissing);

                int startPage = 0;
                int endPage = doc.ComputeStatistics(WdStatistic.wdStatisticPages, ref paraMissing);

                if (doc != null)
                {
                    doc.ExportAsFixedFormat(dest.ToString(), WdExportFormat.wdExportFormatPDF, false, WdExportOptimizeFor.wdExportOptimizeForOnScreen
                        , WdExportRange.wdExportAllDocument, startPage, endPage, WdExportItem.wdExportDocumentWithMarkup,
                        true, true, WdExportCreateBookmarks.wdExportCreateWordBookmarks, true, true, true, ref paraMissing);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (doc != null)
                {
                    doc.Close(ref paraMissing, ref paraMissing, ref paraMissing);
                    doc = null;
                }

                if (wordApp != null)
                {
                    wordApp.Quit(ref paraMissing, ref paraMissing, ref paraMissing);
                    wordApp = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
开发者ID:iimax,项目名称:DocViewer,代码行数:52,代码来源:WordParser.cs

示例11: ToCht

 public string ToCht(string chs)
 {
     var doc = new Document();
     doc.Content.Text = chs;
     doc.Content.TCSCConverter(WdTCSCConverterDirection.wdTCSCConverterDirectionSCTC, true, true);
     string des = doc.Content.Text;
     object saveChanges = false;
     object originalFormat = Missing.Value;
     object routeDocument = Missing.Value;
     doc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
     GC.Collect();
     return des;
 }
开发者ID:hahadalin,项目名称:imewlconverter,代码行数:13,代码来源:OfficeComponent.cs

示例12: ConvertUsingWord

 ///
 /// 使用 Office Word (Microsoft.Office.Interop.Word) 進行轉換
 ///
 public static string ConvertUsingWord(string argSource, bool argIsCht)
 {
     var doc = new Document();
     doc.Content.Text = argSource;
     doc.Content.TCSCConverter(
         argIsCht
             ? WdTCSCConverterDirection.wdTCSCConverterDirectionTCSC
             : WdTCSCConverterDirection.wdTCSCConverterDirectionSCTC, true, true);
     var ret = doc.Content.Text;
     object saveChanges = false;
     object originalFormat = Missing.Value;
     object routeDocument = Missing.Value;
     doc.Close(ref saveChanges, ref originalFormat, ref routeDocument);
     return ret;
 }
开发者ID:CowellJackli,项目名称:ChangeEncodeTool,代码行数:18,代码来源:ChineseConverter.cs

示例13: 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

示例14: 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

示例15: ImageOCR

        public ImageOCR(string filename)
        {
            _filename = filename;
            ConvertToTiffIfNeeded();
            _modi = new Document();

            try
            {
                _modi.Create(_filename);
                _modi.OCR(MiLANGUAGES.miLANG_SYSDEFAULT, true, true);
                GetWords();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                _modi.Close(false);
                _modi = null;
            }
        }
开发者ID:Roballen,项目名称:WebGrab,代码行数:22,代码来源:ImageOCR.cs


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