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


C# PdfDocument.SaveToFile方法代码示例

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


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

示例1: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
            Image img = Image.FromFile(@"..\..\..\..\..\..\Data\Background.png");
            page.BackgroundImage = img;

            //Draw table
            DrawPage(page);

            //Save pdf file.
            doc.SaveToFile("ImageWaterMark.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("ImageWaterMark.pdf");
        }
开发者ID:e-iceblue,项目名称:Spire.PDF-for-.NET,代码行数:28,代码来源:Form1.cs

示例2: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();            

            // Create one page
            PdfPageBase page = doc.Pages.Add();

            //Draw the text
            page.Canvas.DrawString("Hello, World!",
                                   new PdfFont(PdfFontFamily.Helvetica, 30f),
                                   new PdfSolidBrush(Color.Black),
                                   10, 10);
            //Draw the image
            PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SalesReportChart.png");
            float width = image.Width * 0.75f;
            float height = image.Height * 0.75f;
            float x = (page.Canvas.ClientSize.Width - width) / 2;

            page.Canvas.DrawImage(image, x, 60, width, height);

            //Save pdf file.
            doc.SaveToFile("Image.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("Image.pdf");
        }
开发者ID:e-iceblue,项目名称:Spire.PDF-for-.NET,代码行数:28,代码来源:Form1.cs

示例3: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            // Create one page
            PdfPageBase page = doc.Pages.Add();

            //Draw the page
            DrawPage(page);

            //set document info
            doc.DocumentInformation.Author = "Harry Hu";
            doc.DocumentInformation.Creator = "Harry Hu";
            doc.DocumentInformation.Keywords = "pdf, demo, document information";
            doc.DocumentInformation.Producer = "Spire.Pdf";
            doc.DocumentInformation.Subject = "Demo of Spire.Pdf";
            doc.DocumentInformation.Title = "Document Information";

            //file info
            doc.FileInfo.CrossReferenceType = PdfCrossReferenceType.CrossReferenceStream;
            doc.FileInfo.IncrementalUpdate = false;
            doc.FileInfo.Version = PdfVersion.Version1_5;

            //Save pdf file.
            doc.SaveToFile("Properties.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("Properties.pdf");
        }
开发者ID:e-iceblue,项目名称:Spire.PDF-for-.NET,代码行数:31,代码来源:Form1.cs

示例4: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            //load two document
            PdfDocument doc1 = new PdfDocument();
            doc1.LoadFromFile(@"..\..\..\..\..\..\Data\Sample1.pdf");

            PdfDocument doc2 = new PdfDocument();
            doc2.LoadFromFile(@"..\..\..\..\..\..\Data\Sample3.pdf");

            //Create page template
            PdfTemplate template = doc1.Pages[0].CreateTemplate();

            foreach (PdfPageBase page in doc2.Pages)
            {
                page.Canvas.SetTransparency(0.25f, 0.25f, PdfBlendMode.Overlay);
                page.Canvas.DrawTemplate(template, PointF.Empty);
            }

            //Save pdf file.
            doc2.SaveToFile("Overlay.pdf");
            doc1.Close();
            doc2.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("Overlay.pdf");
        }
开发者ID:e-iceblue,项目名称:Spire.Office-for-.NET,代码行数:26,代码来源:Form1.cs

示例5: CreateRekenPyramide

        public PdfDocument CreateRekenPyramide(string filename)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            // Create one page
            PdfPageBase page = doc.Pages.Add();
            int basislengte = 8;
            int maxbasisgetal = 14;

            Random rnd = new Random();
            for (int pyramide = 1; pyramide <= 3; pyramide++)
            {
                GeneratePyramid(basislengte, rnd, maxbasisgetal);

                int papierhoogte = ((int)page.Canvas.Size.Height / 3 - 40) * pyramide;

                TekenHelePyramideOpPapier(page, pyrArray, basislengte, papierhoogte);
            }
            //Save pdf file.
            doc.SaveToFile(filename);
            doc.Close();

            return doc;
        }
开发者ID:MelleKoning,项目名称:rekenblad,代码行数:25,代码来源:RekenPyramide.cs

示例6: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
            
            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold), true);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Categories List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Categories List", format1).Height;
            y = y + 5;

            RectangleF rctg = new RectangleF(new PointF(0, 0), page.Canvas.ClientSize);
            PdfLinearGradientBrush brush
                = new PdfLinearGradientBrush(rctg, Color.Navy, Color.OrangeRed, PdfLinearGradientMode.Vertical);
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
            String formatted
                = "Beverages\nCondiments\nConfections\nDairy Products\nGrains/Cereals\nMeat/Poultry\nProduce\nSeafood";

            PdfList list = new PdfList(formatted);
            list.Font = font;
            list.Indent = 8;
            list.TextIndent = 5;
            list.Brush = brush;
            PdfLayoutResult result = list.Draw(page, 0, y);
            y = result.Bounds.Bottom;

            PdfSortedList sortedList = new PdfSortedList(formatted);
            sortedList.Font = font;
            sortedList.Indent = 8;
            sortedList.TextIndent = 5;
            sortedList.Brush = brush;
            sortedList.Draw(page, 0, y);

            //Save pdf file.
            doc.SaveToFile("SimpleList.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("SimpleList.pdf");
        }
开发者ID:e-iceblue,项目名称:Spire.PDF-for-.NET,代码行数:55,代码来源:Form1.cs

示例7: CrearDocPDF

        public PdfDocument CrearDocPDF(string rutaFichero, /*Usuario user,*/ Dictionary<string, List<Libro>> coleccionLibrosCarrito, string infoCookieLibros)
        {
            PdfDocument miFactura = new PdfDocument();

            PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();

            htmlLayoutFormat.IsWaiting = false;

            PdfPageSettings setting = new PdfPageSettings();
            setting.Size = PdfPageSize.A4;

            //String facturaHTML = File.ReadAllText(rutaFichero + "PlantillaFactura.html");
            String facturaHTML = GenerarFacturaEnHTML(rutaFichero + "Imagenes/", coleccionLibrosCarrito.Values.ElementAt(0), /*user,*/ infoCookieLibros);

            List<string> nombreKey = coleccionLibrosCarrito.Keys.ToList();
            string keyString = "";
            foreach (string key in nombreKey)
            {
                keyString = key;
                keyString = keyString.Replace('/', '_').Replace(' ', '_').Replace(':', '_');
            }

            Thread thread = new Thread(() =>
            {
                miFactura.LoadFromHTML(facturaHTML, false, setting, htmlLayoutFormat);
                //miFactura.LoadFromHTML(facturaHTML, false, true, true);
            });

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();

            //string filePath = rutaFichero + "facturas/" + user.loginUsuario + keyString + ".pdf";

            //if (!File.Exists(filePath))
            //{
            //    FileStream f = File.Create(filePath);
            //    f.Close();
            //}
            try
            {
                //  miFactura.SaveToFile(rutaFichero + "Facturas/" + /*user.alias + keyString +*/ "Recibo.pdf");
                miFactura.SaveToFile("Recibo.pdf");
                mandar_email(miFactura);
            }
            catch (Exception e)
            {

            }


            //System.Diagnostics.Process.Start(rutaFichero + "facturas/" + user.loginUsuario + keyString + ".pdf");

            return miFactura;
        }
开发者ID:gonzalmapi,项目名称:Projects,代码行数:55,代码来源:Controlador_PDF_Email.cs

示例8: SavePDF

        protected bool SavePDF(PdfDocument transferDetails)
        {
            if (File.Exists(Path.Combine(SieradzBankFilesPathHolder.TransferFilesPath, @"..\mBank\Transfers1.pdf")))
            {
                File.Open(Path.Combine(SieradzBankFilesPathHolder.TransferFilesPath, @"..\mBank\Transfers1.pdf"), FileMode.Open).Close();
                File.Delete(Path.Combine(SieradzBankFilesPathHolder.TransferFilesPath, @"..\mBank\Transfers1.pdf"));
            }
            transferDetails.SaveToFile(SieradzBankFilesPathHolder.TransferFilesPath + @"..\mBank\Transfers1.pdf",FileFormat.PDF);
            transferDetails.Close();

            return File.Exists(SieradzBankFilesPathHolder.TransferFilesPath + @"..\mBank\Transfers1.pdf");
        }
开发者ID:sparrow41,项目名称:training,代码行数:12,代码来源:TypowyAdamTransferHandle.cs

示例9: Main

        static void Main(string[] args)
        {
            PdfDocument document = new PdfDocument(PdfConformanceLevel.Pdf_A1B);
            PdfPageBase page = document.Pages.Add();

            PdfPageBase page3 = document.Pages.Add();
            page3.Canvas.DrawString("Hello World2", new PdfFont(PdfFontFamily.Helvetica, 30f), new PdfSolidBrush(Color.Black), 10, 10);
            //save to PDF document
            document.Pages[1].Rotation = PdfPageRotateAngle.RotateAngle180;
            document.Pages.RemoveAt(0);
            document.SaveToFile("FromHTML.pdf", FileFormat.PDF);
            document.Close();
        }
开发者ID:kevinShumingWang,项目名称:SplitPDF,代码行数:13,代码来源:Program.cs

示例10: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            // Create one section
            PdfSection section = doc.Sections.Add();

            //Load image
            PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SalesReportChart.png");
            float imageWidth = image.PhysicalDimension.Width / 2;
            float imageHeight = image.PhysicalDimension.Height / 2;
            foreach (PdfBlendMode mode in Enum.GetValues(typeof(PdfBlendMode)))
            {
                PdfPageBase page = section.Pages.Add();
                float pageWidth = page.Canvas.ClientSize.Width;
                float y = 0;

                //title
                y = y + 5;
                PdfBrush brush = new PdfSolidBrush(Color.OrangeRed);
                PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold));
                PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Center);
                String text = String.Format("Transparency Blend Mode: {0}", mode);
                page.Canvas.DrawString(text, font, brush, pageWidth / 2, y, format);
                SizeF size = font.MeasureString(text, format);
                y = y + size.Height + 6;

                page.Canvas.DrawImage(image, 0, y, imageWidth, imageHeight);
                page.Canvas.Save();
                float d = (page.Canvas.ClientSize.Width - imageWidth) / 5;
                float x = d;
                y = y + d / 2;
                for (int i = 0; i < 5; i++)
                {
                    float alpha = 1.0f / 6 * (5 - i);
                    page.Canvas.SetTransparency(alpha, alpha, mode);
                    page.Canvas.DrawImage(image, x, y, imageWidth, imageHeight);
                    x = x + d;
                    y = y + d / 2;
                }
                page.Canvas.Restore();
            }

            //Save pdf file.
            doc.SaveToFile("Transparency.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("Transparency.pdf");
        }
开发者ID:e-iceblue,项目名称:Spire.PDF-for-.NET,代码行数:51,代码来源:Form1.cs

示例11: ConvertImageToPdf

        public static Downloads.File ConvertImageToPdf(Downloads.File file)
        {
            PdfDocument doc = new PdfDocument();
            PdfSection section = doc.Sections.Add();
            PdfPageBase page = doc.Pages.Add();
            //Load a tiff image from system
            PdfImage image = PdfImage.FromStream(file.FileStream);
            //Set image display location and size in PDF
            float widthFitRate = image.PhysicalDimension.Width / page.Canvas.ClientSize.Width;
            float heightFitRate = image.PhysicalDimension.Height / page.Canvas.ClientSize.Height;
            float fitRate = Math.Max(widthFitRate, heightFitRate);
            float fitWidth = image.PhysicalDimension.Width / fitRate;
            float fitHeight = image.PhysicalDimension.Height / fitRate;
            page.Canvas.DrawImage(image, 30, 30, fitWidth, fitHeight);

            var docId = Guid.NewGuid().ToString();

            try {

                string path = Path.GetTempPath();
                var filePath = path + @"\" + docId +"-" + file.FileName;
                //save and launch the file
                doc.SaveToFile(filePath);
                file.TempLink = filePath;

            } catch (Exception) {

                var tempPath = Environment.GetEnvironmentVariable("TEMP");
                var filePath = tempPath + @"\" + docId + "-" + file.FileName;
                doc.SaveToFile(filePath);
                file.TempLink = filePath;
            }

            doc.Close();
            file.FileStream.Close();

            return file;
        }
开发者ID:sgauzel,项目名称:main,代码行数:38,代码来源:ImageToPDF.cs

示例12: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //Draw pages
            PdfPageBase lastPage = DrawPages(doc);

            //script
            String script
                = "app.alert({"
                + "    cMsg: \"I'll lead; you must follow me.\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action1 = new PdfJavaScriptAction(script);
            doc.AfterOpenAction = action1;

            //script
            script
                = "app.alert({"
                + "    cMsg: \"The firt page!\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action2 = new PdfJavaScriptAction(script);
            action1.NextAction = action2;

            PdfDestination dest = new PdfDestination(lastPage);
            dest.Zoom = 1;
            PdfGoToAction action3 = new PdfGoToAction(dest);
            action2.NextAction = action3;

            //script
            script
                = "app.alert({"
                + "    cMsg: \"Oh sorry, it's the last page. I'm missing!\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action4 = new PdfJavaScriptAction(script);
            action3.NextAction = action4;

            //Save pdf file.
            doc.SaveToFile("ActionChain.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("ActionChain.pdf");
        }
开发者ID:e-iceblue,项目名称:Spire.PDF-for-.NET,代码行数:50,代码来源:Form1.cs

示例13: crearPdf

 private static void crearPdf()
 {
     PdfDocument pdf = new PdfDocument();
     PdfPageBase pagina = pdf.Pages.Add();
     string[] lineasTxT = File.ReadAllLines(CFichero.rutaLibros);
     string salida = "";
     foreach (string linea in lineasTxT)
     {
         salida += linea + "\n";
     }
     pagina.Canvas.DrawString(salida, new PdfFont(PdfFontFamily.TimesRoman, 14), new PdfSolidBrush(Color.Black), 10, 10);
     pdf.SaveToFile("Recibo.pdf");
     pdf.Close();
 }
开发者ID:MaybeGitHub,项目名称:cSharp,代码行数:14,代码来源:CMensajeria.cs

示例14: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            String url = "http://www.e-iceblue.com/";
            doc.LoadFromHTML(url, false, true, true);

            //Save pdf file.
            doc.SaveToFile("FromHTML.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("FromHTML.pdf");
        }
开发者ID:e-iceblue,项目名称:Spire.PDF-for-.NET,代码行数:15,代码来源:Form1.cs

示例15: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            doc.ViewerPreferences.PageLayout = PdfPageLayout.TwoColumnLeft;

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            SetDocumentTemplate(doc, PdfPageSize.A4, margin);

            //create section
            PdfSection section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = new PdfMargins(0);
            SetSectionTemplate(section, PdfPageSize.A4, margin, "Section 1");

            // Create one page
            PdfNewPage page = section.Pages.Add();

            //Draw page
            DrawPage(page); 

            page = section.Pages.Add();
            DrawPage(page);

            page = section.Pages.Add();
            DrawPage(page);

            page = section.Pages.Add();
            DrawPage(page);

            page = section.Pages.Add();
            DrawPage(page);

            //Save pdf file.
            doc.SaveToFile("Template.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("Template.pdf");
        }
开发者ID:e-iceblue,项目名称:Spire.PDF-for-.NET,代码行数:47,代码来源:Form1.cs


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