2012-12-16 66 views
6
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Diagnostics; 
using System.IO; 
using System.Drawing; 
using PdfSharp; 
using PdfSharp.Drawing; 
using PdfSharp.Pdf; 
using PdfSharp.Pdf.IO; 

namespace Lightnings_Extractor 
{ 
    class PDF 
    { 
     public PDF() 
     { 
      // 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); 
      // Create a font 
      XFont font = new XFont("Verdana", 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 = @"d:\HelloWorld.pdf"; 
      document.Save(filename); 
      // ...and start a viewer. 
      Process.Start(filename); 
     } 

     private void DrawImage(XGraphics gfx, int number) 
     { 
     } 
    } 
} 

मैं इस लिंक से नमूना ले रहा हूँ: http://www.pdfsharp.net/wiki/Graphics-sample.ashx वहाँ एक नमूना है: मूल आकार में एक चित्र बनाएंमैं पीडीएफएसआरपी का उपयोग कर रहा हूं और क्लास Beginbox को नहीं ढूंढ सकता, यह कहां है?

void DrawImage(XGraphics gfx, int number) 
{ 
    BeginBox(gfx, number, "DrawImage (original)"); 

    XImage image = XImage.FromFile(jpegSamplePath); 

    // Left position in point 
    double x = (250 - image.PixelWidth * 72/image.HorizontalResolution)/2; 
    gfx.DrawImage(image, x, 0); 

    EndBox(gfx); 
} 

मैं यहाँ क्या याद आ रही है?

उत्तर

11

BeginBox और EndBoxbottom of the sample page पर परिभाषित सहायक विधियां हैं।

ध्यान दें कि ये विधियां केवल आस-पास के बॉक्स को बनाने के लिए हैं और शायद आपको वह कार्यक्षमता प्राप्त करने की आवश्यकता नहीं है जिसे आप वास्तव में चाहते हैं (इस मामले में, मूल आकार में एक छवि खींचने के लिए)। तो मैं कोड से उन दो लाइनों को हटा दूंगा।

public void BeginBox(XGraphics gfx, int number, string title) 
{ 
    const int dEllipse = 15; 
    XRect rect = new XRect(0, 20, 300, 200); 
    if (number % 2 == 0) 
    rect.X = 300 - 5; 
    rect.Y = 40 + ((number - 1)/2) * (200 - 5); 
    rect.Inflate(-10, -10); 
    XRect rect2 = rect; 
    rect2.Offset(this.borderWidth, this.borderWidth); 
    gfx.DrawRoundedRectangle(new XSolidBrush(this.shadowColor), rect2, new XSize(dEllipse + 8, dEllipse + 8)); 
    XLinearGradientBrush brush = new XLinearGradientBrush(rect, this.backColor, this.backColor2, XLinearGradientMode.Vertical); 
    gfx.DrawRoundedRectangle(this.borderPen, brush, rect, new XSize(dEllipse, dEllipse)); 
    rect.Inflate(-5, -5); 

    XFont font = new XFont("Verdana", 12, XFontStyle.Regular); 
    gfx.DrawString(title, font, XBrushes.Navy, rect, XStringFormats.TopCenter); 

    rect.Inflate(-10, -5); 
    rect.Y += 20; 
    rect.Height -= 20; 

    this.state = gfx.Save(); 
    gfx.TranslateTransform(rect.X, rect.Y); 
} 

public void EndBox(XGraphics gfx) 
{ 
    gfx.Restore(this.state); 
}