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


C# Pdf.PdfDocument類代碼示例

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


PdfDocument類屬於PdfSharp.Pdf命名空間,在下文中一共展示了PdfDocument類的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: Genereer

        public static bool Genereer(Deelnemer deelnemer, DeelnemerVerhuisd deelnemerVerhuisd)
        {
            _deelnemer = deelnemer;
            _event = deelnemerVerhuisd;

            // start pdf document
            _document = new PdfDocument();
            _document.Info.Title = "Verhuisbrief " + _deelnemer.Naam;
            _document.Info.Author = "Verhuisbrief Generator";

            // voeg pagina toe
            _page = _document.AddPage();
            _gfx = XGraphics.FromPdfPage(_page);

            // vul pagina
            PlaatsLogo();
            PlaatsTitel();
            PlaatsNAWGegevens();
            PlaatsInhoud();

            // sla document op
            SlaPdfOp();

            return true;
        }
開發者ID:jpkleemans,項目名稱:cqrs-sample,代碼行數:25,代碼來源:Verhuisbrief.cs

示例3: NewPage

 public static XGraphics NewPage(PdfDocument document, XUnit width, XUnit height)
 {
     var page = document.AddPage();
     page.Width = width;
     page.Height = height;
     return XGraphics.FromPdfPage(page);
 }
開發者ID:JBonsink,項目名稱:BaxterLicence,代碼行數:7,代碼來源:PdfRendering.cs

示例4: CreatePdfPage

        private static void CreatePdfPage(List<JiraTicket> issues, ref PdfDocument pdf)
        {
            PdfPage page = pdf.AddPage();
            page.Size = PdfSharp.PageSize.A4;
            page.Orientation = PdfSharp.PageOrientation.Landscape;

            for (int j = 0; j < issues.Count; j++)
            {
                string text = issues[j].fields.issuetype.name + System.Environment.NewLine + issues[j].key
                  + System.Environment.NewLine + issues[j].fields.summary + System.Environment.NewLine
                  + issues[j].fields.customfield_10008;

                XGraphics gfx = XGraphics.FromPdfPage(page);
                XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
                XTextFormatter tf = new XTextFormatter(gfx);
                XRect rect = new XRect();

                if (j < 3)
                {
                    rect = new XRect(15, 15 + j * 180, 400, 170);
                }
                else
                {
                    rect = new XRect(430, 15 + (j - 3) * 180, 400, 170);
                }

                gfx.DrawRectangle(XBrushes.SeaShell, rect);
                tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft);
                gfx.Dispose();
            }
        }
開發者ID:xcyroo,項目名稱:SprintAnalyzer,代碼行數:31,代碼來源:PdfCreator.cs

示例5: Merge

        public PdfDocument Merge( string[] filePaths, Action afterEachAddedFileAction )
        {
            PdfDocument mergedDocument = new PdfDocument();

            foreach ( var filePath in filePaths )
            {
                try
                {
                    using ( PdfDocument documentToAdd = _pdfReader.ReadFile( filePath ) )
                    {
                        for ( int i = 0; i < documentToAdd.PageCount; i++ )
                        {
                            PdfPage page = documentToAdd.Pages[ i ];

                            mergedDocument.AddPage( page );
                        }
                    }
                }
                catch ( Exception ex )
                {
                    string errorMessage = string.Format( "An error occurred processing the following file: {0}\n\nError Message: {1}\n\nFull Error: {2}", filePath, ex.Message, ex );

                    MessageBox.Show( errorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error );
                }

                if ( afterEachAddedFileAction != null )
                {
                    afterEachAddedFileAction();
                }
            }

            return mergedDocument;
        }
開發者ID:randyburden,項目名稱:PDFMerger,代碼行數:33,代碼來源:PdfMerger.cs

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

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

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

示例9: ImportImage

        public ImportedImage ImportImage(StreamReaderHelper stream, PdfDocument document)
        {
            try
            {
                stream.CurrentOffset = 0;
                int offsetImageData;
                if (TestBitmapFileHeader(stream, out offsetImageData))
                {
                    // Magic: TestBitmapFileHeader updates stream.CurrentOffset on success.

                    ImagePrivateDataBitmap ipd = new ImagePrivateDataBitmap(stream.Data, stream.Length);
                    ImportedImage ii = new ImportedImageBitmap(this, ipd, document);
                    if (TestBitmapInfoHeader(stream, ii, offsetImageData))
                    {
                        //stream.CurrentOffset = offsetImageData;
                        return ii;
                    }
                }
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {
            }
            return null;
        }
開發者ID:Core2D,項目名稱:PDFsharp,代碼行數:25,代碼來源:ImageImporterBmp.cs

示例10: Main

    static void Main()
    {
      // Create a new PDF document
      PdfDocument document = new PdfDocument();
      document.Info.Title = "Created with PDFsharp";

      // Create an empty page
      PdfPage page = document.AddPage();

      // 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("Times New Roman", 20, XFontStyle.BoldItalic);

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

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

示例11: Render

        public PdfDocument Render(IEnumerable<Page> pages, Unit pageWidth, Unit pageHeight)
        {
            var currentPageNumber = 1;
            var totalPageNumber = pages.Count();
            var document = new PdfDocument();
            foreach (var page in pages)
            {
                var canvas = AddPageTo(document, pageWidth, pageHeight);
                foreach (var element in page.Elements)
                {
                    borderRenderer.Render(canvas, element);

                    if (element.Specification is Backgrounded)
                        backgroundRenderer.Render(canvas, element);

                    if (element.Specification is Image)
                        imageRenderer.Render(canvas, element);

                    if (element.Specification is Text)
                        textRenderer.Render(canvas, element);
                }
                currentPageNumber++;
            }

            return document;
        }
開發者ID:asgerhallas,項目名稱:DomFx,代碼行數:26,代碼來源:PdfSharpRenderer.cs

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

示例13: GetDocumentFromFiles

        public static PdfDocument GetDocumentFromFiles(List<string> files, bool throwOnFail)
        {
            PdfDocument doc = new PdfDocument();
            doc.Info.Title = "";

            //TODO set some others here
            doc.Info.Elements.SetString("/Producer", "8labs Bulk Image To Pdf converter.");
            doc.Info.Elements.SetString("/Creator", "8labs Bulk Image To Pdf converter.");

            //TODO any sorting, etc... or should happen prior to this function
            foreach (string f in files)
            {
                try
                {
                    if (File.Exists(f)) //TODO more verification on what we're working on.
                    {
                        List<BitmapSource> imgs = ImgToPdf.GetImagesFromFile(f);
                        foreach (BitmapSource bmp in imgs)
                        {
                            //TODO handle scaling here for better results/speed than the pdf lib scaling??
                            //TODO convert to monochrome or otherwise compress?
                            AddImagePage(doc, bmp); //add a page of the image
                        }
                    }
                }
                catch (Exception)
                {
                    //only throw if specified
                    if (throwOnFail) throw;
                }

            }

            return doc;
        }
開發者ID:8labs,項目名稱:BulkImageToPDF,代碼行數:35,代碼來源:ImgToPdf.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類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。