• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# PdfDocument类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: PdfTrueTypeFont

        /// <summary>
        /// Initializes a new instance of PdfTrueTypeFont from an XFont.
        /// </summary>
        public PdfTrueTypeFont(PdfDocument document, XFont font)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/TrueType");

            // TrueType with WinAnsiEncoding only.
            OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptorFor(font);
            FontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
            _fontOptions = font.PdfOptions;
            Debug.Assert(_fontOptions != null);

            //cmapInfo = new CMapInfo(null/*ttDescriptor*/);
            _cmapInfo = new CMapInfo(ttDescriptor);

            BaseFont = font.GlyphTypeface.GetBaseName();
     
            if (_fontOptions.FontEmbedding == PdfFontEmbedding.Always)
                BaseFont = PdfFont.CreateEmbeddedFontSubsetName(BaseFont);
            FontDescriptor.FontName = BaseFont;

            Debug.Assert(_fontOptions.FontEncoding == PdfFontEncoding.WinAnsi);
            if (!IsSymbolFont)
                Encoding = "/WinAnsiEncoding";

            Owner._irefTable.Add(FontDescriptor);
            Elements[Keys.FontDescriptor] = FontDescriptor.Reference;

            FontEncoding = font.PdfOptions.FontEncoding;
        }
开发者ID:Sl0vi,项目名称:PDFsharp,代码行数:33,代码来源:PdfTrueTypeFont.cs


示例2: Main

        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile("sample.pdf");

            //Use the default printer to print all the pages
            //doc.PrintDocument.Print();

            //Set the printer and select the pages you want to print

            PrintDialog dialogPrint = new PrintDialog();
            dialogPrint.AllowPrintToFile = true;
            dialogPrint.AllowSomePages = true;
            dialogPrint.PrinterSettings.MinimumPage = 1;
            dialogPrint.PrinterSettings.MaximumPage = doc.Pages.Count;
            dialogPrint.PrinterSettings.FromPage = 1;
            dialogPrint.PrinterSettings.ToPage = doc.Pages.Count;

            if (dialogPrint.ShowDialog() == DialogResult.OK)
            {
                //Set the pagenumber which you choose as the start page to print
                doc.PrintFromPage = dialogPrint.PrinterSettings.FromPage;
                //Set the pagenumber which you choose as the final page to print
                doc.PrintToPage = dialogPrint.PrinterSettings.ToPage;
                //Set the name of the printer which is to print the PDF
                doc.PrinterName = dialogPrint.PrinterSettings.PrinterName;

                PrintDocument printDoc = doc.PrintDocument;
                dialogPrint.Document = printDoc;
                printDoc.Print();
            }
        }
开发者ID:RadaSangOn,项目名称:workCore2,代码行数:32,代码来源:Program.cs


示例3: PdfExtGState

    /// <summary>
    /// Initializes a new instance of the <see cref="PdfExtGState"/> class.
    /// </summary>
    /// <param name="document">The document.</param>
    public PdfExtGState(PdfDocument document)
      : base(document)
    {
      Elements.SetName(Keys.Type, "/ExtGState");

#if true_
  //AIS false
  //BM /Normal
  //ca 1
  //CA 1
  //op false
  //OP false
  //OPM 1
  //SA true
  //SMask /None
  //Type /ExtGState

      Elements.SetValue(Keys.AIS, new PdfBoolean(false)); // The alpha source
      Elements.SetName("/BM", "Normal");
      Elements.SetValue(Keys.op, new PdfBoolean(false));
      Elements.SetValue(Keys.OP, new PdfBoolean(false));
      Elements.SetValue(Keys.OPM, new PdfInteger(1));
      Elements.SetValue("/SA", new PdfBoolean(true));
      Elements.SetName("/SMask", "None");
#endif
    }
开发者ID:bossaia,项目名称:alexandrialibrary,代码行数:30,代码来源:PdfExtGState.cs


示例4: PdfType0Font

        public PdfType0Font(PdfDocument document, XFont font, bool vertical)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Font");
            Elements.SetName(Keys.Subtype, "/Type0");
            Elements.SetName(Keys.Encoding, vertical ? "/Identity-V" : "/Identity-H");

            OpenTypeDescriptor ttDescriptor = (OpenTypeDescriptor)FontDescriptorCache.GetOrCreateDescriptorFor(font);
            FontDescriptor = new PdfFontDescriptor(document, ttDescriptor);
            _fontOptions = font.PdfOptions;
            Debug.Assert(_fontOptions != null);

            _cmapInfo = new CMapInfo(ttDescriptor);
            _descendantFont = new PdfCIDFont(document, FontDescriptor, font);
            _descendantFont.CMapInfo = _cmapInfo;

            // Create ToUnicode map
            _toUnicode = new PdfToUnicodeMap(document, _cmapInfo);
            document.Internals.AddObject(_toUnicode);
            Elements.Add(Keys.ToUnicode, _toUnicode);

            BaseFont = font.GlyphTypeface.GetBaseName();
            // CID fonts are always embedded
            BaseFont = PdfFont.CreateEmbeddedFontSubsetName(BaseFont);

            FontDescriptor.FontName = BaseFont;
            _descendantFont.BaseFont = BaseFont;

            PdfArray descendantFonts = new PdfArray(document);
            Owner._irefTable.Add(_descendantFont);
            descendantFonts.Elements.Add(_descendantFont.Reference);
            Elements[Keys.DescendantFonts] = descendantFonts;
        }
开发者ID:Sl0vi,项目名称:PDFsharp,代码行数:33,代码来源:PdfType0Font.cs


示例5: 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 view reference
            doc.ViewerPreferences.CenterWindow = true;
            doc.ViewerPreferences.DisplayTitle = false;
            doc.ViewerPreferences.FitWindow = false;
            doc.ViewerPreferences.HideMenubar = true;
            doc.ViewerPreferences.HideToolbar = true;
            doc.ViewerPreferences.PageLayout = PdfPageLayout.SinglePage;

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

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


示例6: PdfCatalog

        /// <summary>
        /// Initializes a new instance of the <see cref="PdfCatalog"/> class.
        /// </summary>
        public PdfCatalog(PdfDocument document)
            : base(document)
        {
            Elements.SetName(Keys.Type, "/Catalog");

            _version = "1.4";  // HACK in PdfCatalog
        }
开发者ID:Core2D,项目名称:PDFsharp,代码行数:10,代码来源:PdfCatalog.cs


示例7: ParsePdf

        private void ParsePdf(DateTime curDate, byte[] pdfData)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromBytes(pdfData);

            Menus.Add(new Menu(curDate, doc.Pages[0].ExtractText()));
        }
开发者ID:jmazouri,项目名称:Daventinder,代码行数:7,代码来源:MenuPdfParser.cs


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


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


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


示例11: AttatchDocument

 public void AttatchDocument(PdfDocument.DocumentHandle handle)
 {
     lo ck (_documentHandles)
     {
         _documentHandles.Add(handle);
     }
 }
开发者ID:Sl0vi,项目名称:PDFsharp,代码行数:7,代码来源:GlobalObjectTable.cs


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


示例13: EnsureColorMode

    /// <summary>
    /// Checks whether the color mode of a document and a color match.
    /// </summary>
    public static XColor EnsureColorMode(PdfDocument document, XColor color)
    {
      if (document == null)
        throw new ArgumentNullException("document");

      return EnsureColorMode(document.Options.ColorMode, color);
    }
开发者ID:AnthonyNystrom,项目名称:Pikling,代码行数:10,代码来源:ColorSpaceHelper.cs


示例14: GeneratePdfStream

 public Stream GeneratePdfStream(string url)
 {
     var document = new PdfDocument { Url = url };
     var output = new PdfOutput {OutputStream = new MemoryStream()};
     PdfConvert.ConvertHtmlToPdf(document, output);
     output.OutputStream.Position = 0;
     return output.OutputStream;
 }
开发者ID:nucleoid,项目名称:PdfCustomization,代码行数:8,代码来源:PdfTasks.cs


示例15: PdfFormXObject

    internal PdfFormXObject(PdfDocument thisDocument, XForm form)
      : base(thisDocument)
    {
      Elements.SetName(Keys.Type, "/XObject");
      Elements.SetName(Keys.Subtype, "/Form");

      //if (form.IsTemplate)
      //{ }
    }
开发者ID:BackupTheBerlios,项目名称:zp7-svn,代码行数:9,代码来源:PdfFormXObject.cs


示例16: PdfObjectStream

        // Reference: 3.4.6  Object Streams / Page 100

        /// <summary>
        /// Initializes a new instance of the <see cref="PdfObjectStream"/> class.
        /// </summary>
        public PdfObjectStream(PdfDocument document)
            : base(document)
        {
#if DEBUG && CORE
            if (Internal.PdfDiagnostics.TraceObjectStreams)
            {
                Debug.WriteLine("PdfObjectStream(document) created.");
            }
#endif
        }
开发者ID:Sl0vi,项目名称:PDFsharp,代码行数:15,代码来源:PdfObjectStream.cs


示例17: WriteToPdf

        public override void WriteToPdf(PdfDocument doc)
        {
            // to do

            RectArea rect = new RectArea(PosX, PosY, Width, Height, false);
            rect.SetFillColor(0, 0, 0, 0);
            rect.SetStrokeColor(0, 0, 0, 250);
            rect.Stroked = true;
            rect.AddToDocument(doc);
        }
开发者ID:Jazzuell,项目名称:parser,代码行数:10,代码来源:Field.cs


示例18: PdfCrossReferenceStream

        /// <summary>
        /// Initializes a new instance of the <see cref="PdfObjectStream"/> class.
        /// </summary>
        public PdfCrossReferenceStream(PdfDocument document)
            : base(document)
        {
#if DEBUG && CORE
            if (Internal.PdfDiagnostics.TraceXrefStreams)
            {
                Debug.WriteLine("PdfCrossReferenceStream created.");
            }
#endif
        }
开发者ID:Core2D,项目名称:PDFsharp,代码行数:13,代码来源:PdfCrossReferenceStream.cs


示例19: PdfImportedObjectTable

 /// <summary>
 /// Initializes a new instance of this class with the document the objects are imported from.
 /// </summary>
 public PdfImportedObjectTable(PdfDocument owner, PdfDocument externalDocument)
 {
   if (owner == null)
     throw new ArgumentNullException("owner");
   if (externalDocument == null)
     throw new ArgumentNullException("externalDocument");
   this.owner = owner;
   this.externalDocumentHandle = externalDocument.Handle;
   this.xObjects = new PdfFormXObject[externalDocument.PageCount];
 }
开发者ID:BackupTheBerlios,项目名称:zp7-svn,代码行数:13,代码来源:PdfImportedObjectTable.cs


示例20: LoadDocument

        private async void LoadDocument()
        {
            LoadButton.IsEnabled = false;

            pdfDocument = null;
            Output.Source = null;
            PageNumberBox.Text = "1";
            RenderingPanel.Visibility = Visibility.Collapsed;

            var picker = new FileOpenPicker();
            picker.FileTypeFilter.Add(".pdf");
            StorageFile file = await picker.PickSingleFileAsync();
            if (file != null)
            {
                ProgressControl.Visibility = Visibility.Visible;
                try
                {
                    pdfDocument = await PdfDocument.LoadFromFileAsync(file, PasswordBox.Password);
                }
                catch (Exception ex)
                {
                    switch (ex.HResult)
                    {
                        case WrongPassword:
                            rootPage.NotifyUser("Document is password-protected and password is incorrect.", NotifyType.ErrorMessage);
                            break;

                        case GenericFail:
                            rootPage.NotifyUser("Document is not a valid PDF.", NotifyType.ErrorMessage);
                            break;

                        default:
                            // File I/O errors are reported as exceptions.
                            rootPage.NotifyUser(ex.Message, NotifyType.ErrorMessage);
                            break;
                    }
                }

                if (pdfDocument != null)
                {
                    RenderingPanel.Visibility = Visibility.Visible;
                    if (pdfDocument.IsPasswordProtected)
                    {
                        rootPage.NotifyUser("Document is password protected.", NotifyType.StatusMessage);
                    }
                    else
                    {
                        rootPage.NotifyUser("Document is not password protected.", NotifyType.StatusMessage);
                    }
                    PageCountText.Text = pdfDocument.PageCount.ToString();
                }
                ProgressControl.Visibility = Visibility.Collapsed;
            }
            LoadButton.IsEnabled = true;
        }
开发者ID:COMIsLove,项目名称:Windows-universal-samples,代码行数:55,代码来源:Scenario1_Render.xaml.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# PdfLiteral类代码示例发布时间:2022-05-24
下一篇:
C# PdfDirectObject类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap