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


C# Document.CloseDocument方法代码示例

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


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

示例1: WriteToStream

        /// <summary>
        /// Exports the chart to the specified output stream as binary. When 
        /// exporting to a web response the WriteToHttpResponse() method is likely
        /// preferred.
        /// </summary>
        /// <param name="outputStream">An output stream.</param>
        internal void WriteToStream(Stream outputStream)
        {
            switch (this.ContentType)
              {
            case "image/jpeg":
              CreateSvgDocument().Draw().Save(
            outputStream,
            ImageFormat.Jpeg);
              break;

            case "image/png":
              // PNG output requires a seekable stream.
              using (MemoryStream seekableStream = new MemoryStream())
              {
            CreateSvgDocument().Draw().Save(
                seekableStream,
                ImageFormat.Png);
            seekableStream.WriteTo(outputStream);
              }
              break;

            case "application/pdf":
              SvgDocument svgDoc = CreateSvgDocument();

              // Create PDF document.
              using (Document pdfDoc = new Document())
              {
            // Scalar to convert from 72 dpi to 150 dpi.
            float dpiScalar = 150f / 72f;

            // Set page size. Page dimensions are in 1/72nds of an inch.
            // Page dimensions are scaled to boost dpi and keep page
            // dimensions to a smaller size.
            pdfDoc.SetPageSize(new Rectangle(
              svgDoc.Width / dpiScalar,
              svgDoc.Height / dpiScalar));

            // Set margin to none.
            pdfDoc.SetMargins(0f, 0f, 0f, 0f);

            // Create PDF writer to write to response stream.
            using (PdfWriter pdfWriter = PdfWriter.GetInstance(
              pdfDoc,
              outputStream))
            {
              // Configure PdfWriter.
              pdfWriter.SetPdfVersion(PdfWriter.PDF_VERSION_1_5);
              pdfWriter.CompressionLevel = PdfStream.DEFAULT_COMPRESSION;

              // Add meta data.
              pdfDoc.AddCreator(PdfMetaCreator);
              pdfDoc.AddTitle(this.Name);

              // Output PDF document.
              pdfDoc.Open();
              pdfDoc.NewPage();

              // Create image element from SVG image.
              Image image = Image.GetInstance(svgDoc.Draw(), ImageFormat.Bmp);
              image.CompressionLevel = PdfStream.DEFAULT_COMPRESSION;

              // Must match scaling performed when setting page size.
              image.ScalePercent(100f / dpiScalar);

              // Add image element to PDF document.
              pdfDoc.Add(image);

              pdfDoc.CloseDocument();
            }
              }

              break;

            case "image/svg+xml":
              using (StreamWriter writer = new StreamWriter(outputStream))
              {
            writer.Write(this.Svg);
            writer.Flush();
              }

              break;

            default:
              throw new InvalidOperationException(string.Format(
            "ContentType '{0}' is invalid.", this.ContentType));
              }

              outputStream.Flush();
        }
开发者ID:397152971,项目名称:wms_rfid,代码行数:95,代码来源:Exporter.cs

示例2: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Form["type"] != null && Request.Form["svg"] != null && Request.Form["filename"] != null)
                {
                    string tType = Request.Form["type"].ToString();
                    string tSvg = Request.Form["svg"].ToString();
                    string tFileName = Request.Form["filename"].ToString();

                    if (tFileName == "")
                    {
                        tFileName = "chart";
                    }

                    string tTmp = new Random().Next().ToString();

                    string tExt = "";
                    string tTypeString = "";

                    switch (tType)
                    {
                        case "image/png":
                            tTypeString = "-m image/png";
                            tExt = "png";
                            break;
                        case "image/jpeg":
                            tTypeString = "-m image/jpeg";
                            tExt = "jpg";
                            break;
                        case "application/pdf":
                            tTypeString = "-m application/pdf";
                            tExt = "pdf";
                            break;
                        case "image/svg+xml":
                            tTypeString = "-m image/svg+xml";
                            tExt = "svg";
                            break;
                    }

                    string tSvgOuputFile = tTmp + "." + "svg";
                    string tOutputFile = tTmp + "." + tExt;

                    if (tTypeString != "")
                    {
                        string tWidth = Request.Form["width"].ToString();
                        //WRITING SVG TO DISK
                        StreamWriter tSw = new StreamWriter(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tSvgOuputFile);
                        tSw.Write(tSvg);
                        tSw.Close();
                        tSw.Dispose();

                        Svg.SvgDocument tSvgObj = SvgDocument.Open(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tSvgOuputFile);

                        switch (tExt)
                        {
                            case "jpg":
                                tSvgObj.Draw().Save(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile, ImageFormat.Jpeg);
                                //DELETING SVG FILE 
                                if (File.Exists(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tSvgOuputFile))
                                {
                                    File.Delete(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tSvgOuputFile);
                                }
                                break;
                            case "png":
                                tSvgObj.Draw().Save(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile, ImageFormat.Png);
                                //DELETING SVG FILE
                                if (File.Exists(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tSvgOuputFile))
                                {
                                    File.Delete(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tSvgOuputFile);
                                }
                                break;
                            case "pdf":

                                PdfWriter tWriter = null;
                                Document tDocumentPdf = null;
                                try
                                {
                                    // First step saving png that would be used in pdf
                                    tSvgObj.Draw().Save(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile.Substring(0, tOutputFile.LastIndexOf(".")) + ".png", ImageFormat.Png);

                                    // Creating pdf document
                                    tDocumentPdf = new Document(new iTextSharp.text.Rectangle((float)tSvgObj.Width, (float)tSvgObj.Height));
                                    // setting up margin to full screen image
                                    tDocumentPdf.SetMargins(0.0f, 0.0f, 0.0f, 0.0f);
                                    // creating image
                                    iTextSharp.text.Image tGraph = iTextSharp.text.Image.GetInstance(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile.Substring(0, tOutputFile.LastIndexOf(".")) + ".png");
                                    tGraph.ScaleToFit((float)tSvgObj.Width, (float)tSvgObj.Height);

                                    // Insert content
                                    tWriter = PdfWriter.GetInstance(tDocumentPdf, new FileStream(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile, FileMode.Create));
                                    tDocumentPdf.Open();
                                    tDocumentPdf.NewPage();
                                    tDocumentPdf.Add(tGraph);
                                    tDocumentPdf.CloseDocument();

                                    // deleting png
                                    if (File.Exists(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile.Substring(0, tOutputFile.LastIndexOf(".")) + ".png"))
                                    {
                                        File.Delete(Server.MapPath(null) + ConfigurationManager.AppSettings["EXPORT_TEMP_FOLDER"].ToString() + tOutputFile.Substring(0, tOutputFile.LastIndexOf(".")) + ".png");
//.........这里部分代码省略.........
开发者ID:razormad,项目名称:Highcharts-export-module-asp.net,代码行数:101,代码来源:highcharts_export.aspx.cs

示例3: GenerateInvoicePDF

        private void GenerateInvoicePDF()
        {
            Document document = new Document(PageSize.A4, 20f, 20f, 20f, 20f);
            try
            {
                if (!Directory.Exists(InvoiceFolderPath))
                {
                    Directory.CreateDirectory(InvoiceFolderPath);
                }

                PdfWriter.GetInstance(document, new FileStream(string.Format(InvoiceFolderPath + @"/Invoice{0}.pdf", txtInvoiceNumber.Text), FileMode.Create));
                document.Open();
                //Tables for Logo and Invoice Details
                PdfPTable outerHeader = new PdfPTable(2);
                outerHeader.DefaultCell.BorderWidth = 0;
                outerHeader.TotalWidth = 750f;
                outerHeader.WidthPercentage = 100;
                outerHeader.SpacingAfter = 20f;
                outerHeader.HorizontalAlignment = Element.ALIGN_LEFT;
                PdfPTable pdfCompanyTable = CreateCompanyGrid();
                PdfPTable pdfInvoiceTable = CreateInvoiceGrid();
                outerHeader.AddCell(pdfCompanyTable);
                outerHeader.AddCell(pdfInvoiceTable);

                //Tables for Billing and Shipping Address
                PdfPTable outerAddress = new PdfPTable(2);
                outerAddress.DefaultCell.BorderWidth = 0;
                outerAddress.TotalWidth = 750f;
                outerAddress.WidthPercentage = 100;
                outerAddress.SpacingAfter = 10f;
                outerAddress.HorizontalAlignment = Element.ALIGN_LEFT;
                PdfPTable pdfBillingAddressTable = CreateBillingAddressGrid();
                outerAddress.AddCell(pdfBillingAddressTable);
                PdfPTable pdfShippingAddressTable = CreateShippingAddressGrid();
                outerAddress.AddCell(pdfShippingAddressTable);

                //Product Table
                PdfPTable pdfProductTable = CreateProductsGrid();

                //Tables for Authorized Signatory and Invoice Amounts
                PdfPTable outerInvoiceDetails = new PdfPTable(2);
                outerInvoiceDetails.DefaultCell.BorderWidth = 0;
                outerInvoiceDetails.TotalWidth = 750f;
                outerInvoiceDetails.WidthPercentage = 100;
                outerInvoiceDetails.SpacingAfter = 20f;
                outerInvoiceDetails.HorizontalAlignment = Element.ALIGN_LEFT;
                PdfPTable pdfAuthorizedSignatoryTable = CreateAuthorizedSignatoryGrid();
                outerInvoiceDetails.AddCell(pdfAuthorizedSignatoryTable);
                PdfPTable pdfinvoiceAmountTable = CreateInvoiceAmountDetailsGrid();
                outerInvoiceDetails.AddCell(pdfinvoiceAmountTable);
                PdfPTable pdfNotes = CreateNotesGrid();
                //Adding all tables to the document
                document.Add(outerHeader);
                document.Add(outerAddress);
                document.Add(pdfProductTable);
                document.Add(outerInvoiceDetails);
                document.Add(pdfNotes);
                document.Close();
            }
            catch (Exception ex)
            {
                if (document.IsOpen())
                {
                    document.CloseDocument();
                }

                MessageBox.Show("Error previwing Invoice :" + ex.Message);
            }
        }
开发者ID:UmeshTayade,项目名称:SleekBill,代码行数:69,代码来源:AddEditInvoice.cs

示例4: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Form["type"] != null && Request.Form["svg"] != null && Request.Form["filename"] != null)
                {
                    string tType = Request.Form["type"].ToString();
                    string tSvg = Request.Form["svg"].ToString();
                    string tFileName = Request.Form["filename"].ToString();
                    if (tFileName == "") tFileName = "chart";

                    MemoryStream data = new MemoryStream(Encoding.ASCII.GetBytes(tSvg));
                    MemoryStream stream = new MemoryStream();

                    switch (tType)
                    {
                        case "image/png":
                            tFileName += ".png";
                            SvgDocument.Open(data).Draw().Save(stream, ImageFormat.Png);
                            break;
                        case "image/jpeg":
                            tFileName += ".jpg";
                            SvgDocument.Open(data).Draw().Save(stream, ImageFormat.Jpeg);
                            break;
                        case "image/svg+xml":
                            tFileName += ".svg";
                            stream = data;
                            break;
                        case "application/pdf":
                            tFileName += ".pdf";

                            PdfWriter tWriter = null;
                            Document tDocumentPdf = null;
                            try
                            {
                                SvgDocument tSvgObj = SvgDocument.Open(data);

                                tSvgObj.Draw().Save(stream, ImageFormat.Png);

                                // Creating pdf document
                                tDocumentPdf = new Document(new iTextSharp.text.Rectangle((float)tSvgObj.Width, (float)tSvgObj.Height));

                                // setting up margin to full screen image
                                tDocumentPdf.SetMargins(0.0f, 0.0f, 0.0f, 0.0f);

                                // creating image
                                iTextSharp.text.Image tGraph = iTextSharp.text.Image.GetInstance(stream.ToArray());
                                tGraph.ScaleToFit((float)tSvgObj.Width, (float)tSvgObj.Height);

                                stream = new MemoryStream();

                                // create writer
                                tWriter = PdfWriter.GetInstance(tDocumentPdf, stream);

                                tDocumentPdf.Open();
                                tDocumentPdf.NewPage();
                                tDocumentPdf.Add(tGraph);
                                tDocumentPdf.CloseDocument();
                                tDocumentPdf.Close();
                            }
                            catch (Exception ex)
                            {
                                throw ex;

                            }
                            finally
                            {
                                tDocumentPdf.Close();
                                tDocumentPdf.Dispose();
                                tWriter.Close();
                                tWriter.Dispose();
                            }
                            break;
                    }

                    if (stream != null)
                    {
                        Response.ClearContent();
                        Response.ClearHeaders();
                        Response.ContentType = tType;
                        Response.AppendHeader("Content-Disposition", "attachment; filename=" + tFileName);
                        Response.BinaryWrite(stream.ToArray());
                        Response.End();
                    }
                }
            }
        }
开发者ID:fcsobel,项目名称:Highcharts-export-module-asp.net,代码行数:87,代码来源:highcharts_export.aspx.cs

示例5: GeneratePdf


//.........这里部分代码省略.........
            IContentRepository contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
            PageData startPage = contentRepository.Get<PageData>(ContentReference.StartPage);

            using (MemoryStream memoryStream = new MemoryStream())
            {
                using (Document document = new Document(PageSize.A4))
                {
                    PdfWriter.GetInstance(document, memoryStream);

                    document.AddCreationDate();

                    string author = page["Author"] as string;
                    string title = page["Title"] as string;
                    XhtmlString pdfHeader = startPage["PdfHeader"] as XhtmlString;
                    XhtmlString pdfFooter = startPage["PdfFooter"] as XhtmlString;

                    if (!string.IsNullOrWhiteSpace(author))
                    {
                        document.AddAuthor(author);
                    }

                    document.AddTitle(!string.IsNullOrWhiteSpace(title) ? title : page.Name);

                    document.Open();

                    Dictionary<string, object> providers = new Dictionary<string, object>
                                                               {
                                                                   {
                                                                       HTMLWorker.IMG_PROVIDER,
                                                                       new ImageProvider(
                                                                       document)
                                                                   }
                                                               };

                    StyleSheet styleSheet = OutputHelper.GetStyleSheet();

                    try
                    {
                        Paragraph paragraph = new Paragraph(!string.IsNullOrWhiteSpace(title) ? title : page.Name);
                        document.Add(paragraph);

                        // Add the header
                        if (pdfHeader != null && !pdfHeader.IsEmpty)
                        {
                            using (StringReader stringReader = new StringReader(pdfHeader.ToHtmlString()))
                            {
                                foreach (IElement element in
                                    HTMLWorker.ParseToList(stringReader, styleSheet, providers))
                                {
                                    document.Add(element);
                                }
                            }
                        }

                        // Add the selected properties
                        foreach (KeyValuePair<string, string> content in propertyValues)
                        {
                            using (StringReader stringReader = new StringReader(content.Value))
                            {
                                foreach (IElement element in
                                    HTMLWorker.ParseToList(stringReader, styleSheet, providers))
                                {
                                    document.Add(element);
                                }
                            }
                            
                            document.Add(new Chunk(Environment.NewLine));
                        }

                        // Add the footer
                        if (pdfFooter != null && !pdfFooter.IsEmpty)
                        {
                            using (StringReader stringReader = new StringReader(pdfFooter.ToHtmlString()))
                            {
                                foreach (IElement element in
                                    HTMLWorker.ParseToList(stringReader, styleSheet, providers))
                                {
                                    document.Add(element);
                                }
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Paragraph paragraph = new Paragraph("Error!" + exception.Message);
                        Chunk text = paragraph.Chunks[0];
                        if (text != null)
                        {
                            text.Font.Color = BaseColor.RED;
                        }

                        document.Add(paragraph);
                    }

                    document.CloseDocument();
                }

                return memoryStream.ToArray();
            }
        }
开发者ID:jstemerdink,项目名称:EPiServer.Libraries,代码行数:101,代码来源:PdfOutputFormat.cs


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