當前位置: 首頁>>代碼示例>>C#>>正文


C# PdfDocument.Save方法代碼示例

本文整理匯總了C#中PdfSharp.Pdf.PdfDocument.Save方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfDocument.Save方法的具體用法?C# PdfDocument.Save怎麽用?C# PdfDocument.Save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PdfSharp.Pdf.PdfDocument的用法示例。


在下文中一共展示了PdfDocument.Save方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main

    static void Main(string[] args)
    {
      // Create a new PDF document
      PdfDocument document = new PdfDocument();

      // Create an empty page
      PdfPage page = document.AddPage();
      //page.Contents.CreateSingleContent().Stream.UnfilteredValue;

      // Get an XGraphics object for drawing
      XGraphics gfx = XGraphics.FromPdfPage(page);

      XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

      // Create a font
      XFont font = new XFont("Arial", 20, XFontStyle.Bold, options);

      // Draw the text
      gfx.DrawString("Hello, World!", font, XBrushes.Black,
        new XRect(0, 0, page.Width, page.Height),
        XStringFormats.Center);

      // Save the document...
      string filename = "HelloWorld.pdf";
      document.Save(filename);
      // ...and start a viewer.
      Process.Start(filename);
    }
開發者ID:AnthonyNystrom,項目名稱:Pikling,代碼行數:28,代碼來源:Program.cs

示例2: CreatePDF

        public Stream CreatePDF()
        {
            using (PdfDocument doc = new PdfDocument())
            {
                ScanImages((image) =>
                {
                    using (XImage ximage = XImage.FromGdiPlusImage(image))
                    {
                        PdfPage page = doc.AddPage();
                        page.Width = XUnit.FromInch(this.settings.PageSize.Width);
                        page.Height = XUnit.FromInch(this.settings.PageSize.Height);
                        using (XGraphics xgraphics = XGraphics.FromPdfPage(page))
                        {
                            xgraphics.DrawImage(ximage, 0, 0);
                        }
                    }
                });

                if (doc.PageCount > 0)
                {
                    var response = new MemoryStream();
                    doc.Save(response, false);
                    return response;
                }
                else
                {
                    throw new ScanException("Nothing was scanned.");
                }
            }
        }
開發者ID:sodablue,項目名稱:RoxiScan,代碼行數:30,代碼來源:ScanToPDFService.cs

示例3: Convert

 public bool Convert(string inputFileName, string outputFileName)
 {
     try
     {
         using (PdfDocument doc = new PdfDocument())
         {
             PdfPage page = doc.AddPage();
             using (XGraphics gfx = XGraphics.FromPdfPage(page))
             using (var image = XImage.FromFile(inputFileName))
             {
                 var border = 10;
                 var widthRatio = (gfx.PageSize.Width - border * 2) / image.PixelWidth;
                 var heightRatio = (gfx.PageSize.Height - border) / image.PixelHeight;
                 var scaling = Math.Min(widthRatio, heightRatio);
                 gfx.DrawImage(image, border, border, image.PixelWidth * scaling, image.PixelHeight * scaling);
                 doc.Save(outputFileName);
             }
         }
         return true;
     }
     catch (Exception ex)
     {
         Logger.WarnFormat(ex, "Error converting file {0} to Pdf.", inputFileName);
         return false;
     }
 }
開發者ID:ProximoSrl,項目名稱:Jarvis.DocumentStore,代碼行數:26,代碼來源:ImagePdfConverter.cs

示例4: Main

        static void Main(string[] args)
        {
            foreach (string arg in args)
            {
                DirectoryInfo directory = new DirectoryInfo(arg);

                string SavePath = string.Format("{0}.pdf",directory.Name);

                var files = directory.GetFiles("*.bmp");

                using (PdfDocument Document = new PdfDocument())
                {
                    foreach (var file in files)
                    {
                        var filename = file.FullName;
                        Console.WriteLine(filename);
                        PdfPage page = Document.AddPage();
                        using (XImage image = XImage.FromFile(filename))
                        {

                            page.Width = image.PointWidth;
                            page.Height = image.PointHeight;
                            using (XGraphics gfx = XGraphics.FromPdfPage(page))
                            {
                                gfx.DrawImage(image, 0, 0);
                            }
                        }
                    }
                    Document.Save(SavePath);
                }
            }
        }
開發者ID:aont,項目名稱:DirectoryToPDF,代碼行數:32,代碼來源:Program.cs

示例5: MergePdfs

        public byte[] MergePdfs(IEnumerable<FileToMerge> files)
        {
            byte[] mergedPdfContents;

            using (var mergedPdfDocument = new PdfDocument())
            {
                foreach (var file in files)
                {
                    using (var memoryStream = new MemoryStream(file.Contents))
                    {
                        var inputPdfDocument = PdfReader.Open(memoryStream, PdfDocumentOpenMode.Import);

                        var pageCount = inputPdfDocument.PageCount;
                        for (var pageNumber = 0; pageNumber < pageCount; pageNumber++)
                        {
                            var page = inputPdfDocument.Pages[pageNumber];
                            mergedPdfDocument.AddPage(page);
                        }
                    }
                }

                using (var mergedPdfStream = new MemoryStream())
                {
                    mergedPdfDocument.Save(mergedPdfStream);

                    mergedPdfContents = mergedPdfStream.ToArray();
                }
            }

            return mergedPdfContents;
        }
開發者ID:justinjstark,項目名稱:DataTricks,代碼行數:31,代碼來源:PdfMerger.cs

示例6: Create

        public void Create(string filename, int qcount, int cellsinq, List<string> cellslabels,int rowscount)
        {
            s_document = new PdfDocument();

            _page = new PdfPage();
            _page.Orientation = PageOrientation.Landscape;
            _page.Size = PageSize.A4;
            s_document.Pages.Add(_page);
            gfx = XGraphics.FromPdfPage(_page);

            DrawCenterMarker(7);

            DrawSideMarker(7, 10, 10);
            DrawSideMarker(7, 285, 10);
            DrawSideMarker(7, 10, 200);
            DrawSideMarker(7, 285, 200);

            AddFields();

            AddQuestions(qcount,cellsinq,cellslabels,rowscount);

            // Save the s_document...
            s_document.Save(filename);
            // ...and start a viewer
            Process.Start(filename);
        }
開發者ID:ondister,項目名稱:Recog,代碼行數:26,代碼來源:LandscapeForm.cs

示例7: Main

    static void Main()
    {
      // Create a new PDF document
      PdfDocument document = new PdfDocument();

      // Create a font
      XFont font = new XFont("Verdana", 16);

      // Create first page
      PdfPage page = document.AddPage();
      XGraphics gfx = XGraphics.FromPdfPage(page);
      gfx.DrawString("Page 1", font, XBrushes.Black, 20, 50, XStringFormats.Default);

      // Create the root bookmark. You can set the style and the color.
      PdfOutline outline = document.Outlines.Add("Root", page, true, PdfOutlineStyle.Bold, XColors.Red);

      // Create some more pages
      for (int idx = 2; idx <= 5; idx++)
      {
        page = document.AddPage();
        gfx = XGraphics.FromPdfPage(page);

        string text = "Page " + idx;
        gfx.DrawString(text, font, XBrushes.Black, 20, 50, XStringFormats.Default);

        // Create a sub bookmark
        outline.Outlines.Add(text, page, true);
      }

      // Save the document...
      const string filename = "Bookmarks_tempfile.pdf";
      document.Save(filename);
      // ...and start a viewer.
      Process.Start(filename);
    }
開發者ID:vronikp,項目名稱:EventRegistration,代碼行數:35,代碼來源:Program.cs

示例8: PdfPrinter

        public static void PdfPrinter(FilterResults results)
        {
            PdfDocument pdf = new PdfDocument();
            int numPages;
            int reminder = 0;

            results.issues.OrderBy(i => i.fields.issuetype.name);
            List<JiraTicket> issues = new List<JiraTicket>();

                numPages = results.issues.Count / 6 + 1;
                reminder = results.issues.Count % 6;

                for (int i = 0; i < numPages - 1; i++)
                {
                    issues = results.issues.Skip(i*6).Take(6).ToList();
                    CreatePdfPage(issues, ref pdf);
                }

                if (reminder > 0)
                {
                    issues = results.issues.Skip((numPages-1)*6).Take(reminder).ToList();
                    CreatePdfPage(issues, ref pdf);
                }

            pdf.Save("C:/ProgramData/JiraCharts/issues.pdf");
        }
開發者ID:xcyroo,項目名稱:SprintAnalyzer,代碼行數:26,代碼來源:PdfCreator.cs

示例9: ParseFile

    /// <summary>
    /// Parses the given XPS file and saves the PDF Version.
    /// </summary>
    void ParseFile(string file)
    {
      string baseDir = "../../../PdfSharp.Xps.UnitTests/Primitives.Glyphs/GlyphFiles";

      string filename = System.IO.Path.Combine(baseDir, file + ".xps");

      PdfDocument document = new PdfDocument();

      try
      {
        XpsModel.XpsDocument xpsDoc = XpsModel.XpsDocument.Open(filename);
        foreach (XpsModel.FixedDocument doc in xpsDoc.Documents)
        {
          foreach (XpsModel.FixedPage page in doc.Pages)
          {
            page.GetType();

            //Render PDF Page
            PdfPage pdfpage = document.AddPage();
            pdfpage.Width = WidthInPoint;
            pdfpage.Height = HeightInPoint;

            PdfRenderer renderer = new PdfRenderer();
            renderer.RenderPage(pdfpage, page);

          }
        }
      }
      catch (Exception ex)
      {
        Debug.WriteLine(ex.Message);
        GetType();
      }
      document.Save(Path.Combine(OutputDirectory, file + ".pdf"));
    }
開發者ID:AnthonyNystrom,項目名稱:Pikling,代碼行數:38,代碼來源:GlyphIndices.cs

示例10: using

        /// <inheritdoc/>
        void Core2D.Interfaces.IProjectExporter.Save(string path, Core2D.Project.XDocument document)
        {
            using (var pdf = new PdfDocument())
            {
                var documentOutline = default(PdfOutline);

                foreach (var container in document.Pages)
                {
                    var page = Add(pdf, container);

                    if (documentOutline == null)
                    {
                        documentOutline = pdf.Outlines.Add(
                            document.Name,
                            page,
                            true,
                            PdfOutlineStyle.Regular,
                            XColors.Black);
                    }

                    documentOutline.Outlines.Add(
                        container.Name,
                        page,
                        true,
                        PdfOutlineStyle.Regular,
                        XColors.Black);
                }

                pdf.Save(path);
                ClearCache(isZooming: false);
            }
        }
開發者ID:Core2D,項目名稱:Core2D,代碼行數:33,代碼來源:PdfRenderer.IProjectExporter.cs

示例11: GetCookBook

        public Uri GetCookBook(string name)
        {
            var document = new PdfDocument();
            document.Info.Title = name + "'s personalized cookbook";
            document.Info.Author = "Pancake Prowler";

            var page = document.AddPage();

            var graphics = XGraphics.FromPdfPage(page);

            var font = new XFont("Verdana", 20, XFontStyle.BoldItalic);

            graphics.DrawString(name + "'s personalized cookbook",
                font,
                XBrushes.Red,
                new System.Drawing.PointF((float)page.Width / 2, (float)page.Height / 2),
                XStringFormats.Center);

            var saveStream = new MemoryStream();
            document.Save(saveStream);

            var memoryStream = new MemoryStream(saveStream.ToArray());
            memoryStream.Seek(0, SeekOrigin.Begin);

            var imageStore = new BlobImageRepository();
            return imageStore.Save("application/pdf", memoryStream, "cookbooks");
        }
開發者ID:kbaley,項目名稱:AzureCodeCamp,代碼行數:27,代碼來源:PdfCreator.cs

示例12: Main

    static void Main()
    {
      // Create new document
      PdfDocument document = new PdfDocument();

      // Set font encoding to unicode
      XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

      XFont font = new XFont("Times New Roman", 12, XFontStyle.Regular, options);

      // Draw text in different languages
      for (int idx = 0; idx < texts.Length; idx++)
      {
        PdfPage page = document.AddPage();
        XGraphics gfx = XGraphics.FromPdfPage(page);
        XTextFormatter tf = new XTextFormatter(gfx);
        tf.Alignment = XParagraphAlignment.Left;

        tf.DrawString(texts[idx], font, XBrushes.Black,
          new XRect(100, 100, page.Width - 200, 600), XStringFormats.TopLeft);
      }

      const string filename = "Unicode_tempfile.pdf";
      // Save the document...
      document.Save(filename);
      // ...and start a viewer.
      Process.Start(filename);
    }
開發者ID:bossaia,項目名稱:alexandrialibrary,代碼行數:28,代碼來源:Program.cs

示例13: Save

        public void Save (PdfDocument document)
        {
            // Save the document...  
            var filename = Path.Combine(ServerProperty.MapPath("~/Resources/PDF"), "test.pdf");
            document.Save(filename);

        }
開發者ID:SDelport,項目名稱:propspect,代碼行數:7,代碼來源:PDFManager.cs

示例14: GenerateApplicationPdf

        internal static byte[] GenerateApplicationPdf(Application application)
        {
            //Create pdf document
            PdfDocument pdf = new PdfDocument();
            PdfPage page = pdf.AddPage();
            //Create pdf content
            Document doc = CreateDocument("Application", string.Format("{1}, {0}",application.Person.Name, application.Person.Surname));
            PopulateDocument(ref doc, application);
            //Create renderer for content
            DocumentRenderer renderer = new DocumentRenderer(doc);
            renderer.PrepareDocument();
            XRect A4 = new XRect(0, 0, XUnit.FromCentimeter(21).Point, XUnit.FromCentimeter(29.7).Point);
            XGraphics gfx = XGraphics.FromPdfPage(page);

            int pages = renderer.FormattedDocument.PageCount;
            for(int i = 0; i < pages; i++)
            {
                var container = gfx.BeginContainer(A4, A4, XGraphicsUnit.Point);
                gfx.DrawRectangle(XPens.LightGray, A4);
                renderer.RenderPage(gfx, (i + 1));
                gfx.EndContainer(container);
            }

            using (MemoryStream ms = new MemoryStream())
            {
                pdf.Save(ms, true);
                return ms.ToArray();
            }
        }
開發者ID:majilik,項目名稱:RecruitmentSystem,代碼行數:29,代碼來源:PdfGenerator.cs

示例15: Page_Load

    void Page_Load(object sender, EventArgs e)
    {
      // Create new PDF document
      PdfDocument document = new PdfDocument();
      this.time = document.Info.CreationDate;
      document.Info.Title = "PDFsharp Clock Demo";
      document.Info.Author = "Stefan Lange";
      document.Info.Subject = "Server time: " +
        this.time.ToString("F", CultureInfo.InvariantCulture);

      // Create new page
      PdfPage page = document.AddPage();
      page.Width = XUnit.FromMillimeter(200);
      page.Height = XUnit.FromMillimeter(200);

      // Create graphics object and draw clock
      XGraphics gfx = XGraphics.FromPdfPage(page);
      RenderClock(gfx);

      // Send PDF to browser
      MemoryStream stream = new MemoryStream();
      document.Save(stream, false);
      Response.Clear();
      Response.ContentType = "application/pdf";
      Response.AddHeader("content-length", stream.Length.ToString());
      Response.BinaryWrite(stream.ToArray());
      Response.Flush();
      stream.Close();
      Response.End();
    }
開發者ID:bossaia,項目名稱:alexandrialibrary,代碼行數:30,代碼來源:Clock.aspx.cs


注:本文中的PdfSharp.Pdf.PdfDocument.Save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。