C# Класс PDFExport.PDFGraphics

Implements the IGraphics interface for the PDF-Sharp output.
Every point, path, rectangle and so on is measured in pixels. PDF doesn't know about pixels, but dots. One dot is the 72th of an inch. So one has to apply some scaling for alle drawn elements. This can be done with a call to ScaleTransform for example to get from pixel coordinates to dot coordinates. This solution has one disadvantage: There are a few points where PDF-Sharp scales from pixels to dots itself: fonts and images. If we don't care about this, all fonts and images would appear to small in the resulting PDF. The solution is to "unscale" those elements first. To do this, there are the two properties ScaleFont and ScaleImage. //We take the DPI of the screen from a Control Graphics gdiGraphics = (new Control()).CreateGraphics(); //Apply a scaling to get from pixels to dots graphics.ScaleTransform(72.0f / gdiGraphics.DpiX, 72.0f / gdiGraphics.DpiY); //Unscale the font graphics.ScaleFont = gdiGraphics.DpiY / 72.0f; //Unscale the images graphics.ScaleImage = gdiGraphics.DpiX / 72.0f; graphics.TakeInitialTransform(); Word wrap is slightly different to the GDI word wrapping. If a single word is longer than a line, GDI breaks the word and prints the rest in a new line. Here the rest isn't printed but an ellipsis is appendet to the not fitting word. The following points are on the to do list: - Clipping isn't very good right now. We should unerstand the regions. There are a few things which are not perfect and won't be changed now: - Only horizontal, vertical and diagonal gradients are drawn correctly. Thats ok since NClass dosn't use any other gradients. - Images get a gray border in pdf if they have colored (even white) pixels next to transparent pixels. A workaround is to draw them by GDI on a surface. This surface is white. This looks good until the backgound of the entity is also white. If not, images are inside a white box. - If one draws with a gradient brush and the next drawing operation uses a black brush, this drawing is done with the gradient again. That's because the brush isn't changed in pdf. This is a bug in PDFSharp.
Наследование: IGraphics
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
DrawEllipse ( Pen pen, int x, int y, int width, int height ) : void
DrawImage ( Image image, Point point ) : void
DrawImage ( Image image, int x, int y ) : void
DrawLine ( Pen pen, Point pt1, Point pt2 ) : void
DrawLine ( Pen pen, int x1, int y1, int x2, int y2 ) : void
DrawLines ( Pen pen, Point points ) : void
DrawPath ( Pen pen, GraphicsPath path ) : void
DrawPolygon ( Pen pen, Point points ) : void
DrawRectangle ( Pen pen, Rectangle rect ) : void
DrawString ( string s, Font font, Brush brush, PointF point ) : void
DrawString ( string s, Font font, Brush brush, PointF point, StringFormat format ) : void
DrawString ( string s, Font font, Brush brush, RectangleF layoutRectangle ) : void
DrawString ( string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format ) : void
FillEllipse ( Brush brush, Rectangle rect ) : void
FillEllipse ( Brush brush, int x, int y, int width, int height ) : void
FillPath ( Brush brush, GraphicsPath path ) : void
FillPolygon ( Brush brush, Point points ) : void
FillRectangle ( Brush brush, Rectangle rect ) : void
PDFGraphics ( XGraphics graphics ) : System

Initializes a new instnace of PDFGraphics.

ResetTransform ( ) : void
RotateTransform ( float angle ) : void
ScaleTransform ( float sx, float sy ) : void
SetClip ( GraphicsPath path, CombineMode combineMode ) : void
SetClip ( Rectangle rect, CombineMode combineMode ) : void
SetClip ( RectangleF rect, CombineMode combineMode ) : void
SetClip ( Region region, CombineMode combineMode ) : void
TakeInitialTransform ( ) : void

Takes the inital state.

TranslateTransform ( float dx, float dy ) : void

Приватные методы

Метод Описание
ApplyClip ( Region region ) : void

Applies the clipping stored in region.

BrushToXBrush ( Brush brush ) : PdfSharp.Drawing.XBrush

Converts a GDI-Brush to a PDF-XBrush.

Only Solid- and LinearGradientBrushes are supported.

CombineClippingRegion ( CombineMode combineMode, Region region ) : void

Combines the local clippingRegion with the given region.

DashStyleToXDashStyle ( DashStyle dashStyle ) : XDashStyle

Converts a GDI-DashStyle to a PDF-XDashStyle.

FillModeToXFillMode ( FillMode fillMode ) : XFillMode

Converts a GDI-FillMode to a PDF-XFillMode.

FloatArrayToDoubleArray ( float floats ) : double[]

Converts an array of floats to an array of doubles.

FontStyleToXFontStyle ( FontStyle fontStyle ) : XFontStyle

Converts a GDI-FontStyle to a PDF-XFontStyle.

FontToXFont ( Font font ) : PdfSharp.Drawing.XFont

Converts a GDI-Font to a PDF-XFont.

GraphicsPathToXGraphicsPath ( GraphicsPath path ) : PdfSharp.Drawing.XGraphicsPath

Converts a GDI-GraphicsPath to a PDF-XGraphicsPath.

ImageToXImage ( Image image ) : PdfSharp.Drawing.XImage

Converts a GDI-Image to a PDF-XImage.

The GDI-Image gets drawn on a white background.

LineCapToXLineCap ( LineCap lineCap ) : XLineCap

Converts a GDI-LineCap to a PDF-XLineCap.

PDF only supports square, round and flat line caps. So all the other GDI line caps gets mapped to the best PDF line caps as follows. XLineCap.Square LineCap.Square LineCap.Triangle LineCap.SquareAnchor LineCap.DiamondAnchor LineCap.ArrowAnchor XLineCap.Round LineCap.Round LineCap.RoundAnchor XLineCap.Flat LineCap.Flat LineCap.NoAnchor LineCap.Custom LineCap.AnchorMask

LineJoinToXLineJoin ( LineJoin lineJoin ) : XLineJoin

Converts a GDI-LineJoin to a PDF-XLineJoin.

PDF doesn't support LineJoin.MiterClipped so this is mapped to XLineJoin.Miter, too.

PenToXPen ( Pen pen ) : PdfSharp.Drawing.XPen

Converts a GDI-Pen to a PDF-XPen.

RestoreInitialClip ( ) : void

Resets the clipping.

RestoreInitialTransform ( ) : void

Restores the state to the initial state.

SetText ( String text, float width, int maxLines, PdfSharp.Drawing.XFont xFont ) : List

This method will take a text and do a word wrap so it fits into the given width. If a line is wider than width, a new line is started. If the resulting line count is greater than maxLines, an ellipsis is added. The result is a list of strings where one item per line.

StringAlignmentToXLineAlignment ( StringAlignment stringAlignment ) : XLineAlignment

Converts a GDI-StringAlignment to a PDF-XLineAlignment.

StringAlignmentToXStringAlignment ( StringAlignment stringAlignment ) : XStringAlignment

Converts a GDI-StringAlignment to a PDF-XStringAlignment.

StringFormatFlagsToXStringFormatFlags ( StringFormatFlags stringFormatFlags ) : XStringFormatFlags

Converts a GDI-StringFormatFlags to a PDF-XStringFormatFlags.

StringFormatToXStringFormat ( StringFormat format ) : PdfSharp.Drawing.XStringFormat

Converts a GDI-StringFormat to a PDF-XStringFormat.

TokenizeString ( string text, string separator ) : List

This method will devide string by a separator and return the tokens as a list. The list will contain the text between the separators as well as the separators itself.

TrimString ( string s, float width, PdfSharp.Drawing.XFont font, StringTrimming stringTrimming ) : string

Trims a string so it fits into the rectangle. Only one line is trimed.

The StringTrimming.EllipsisPath is handeled as StringTrimming.EllipsisCharacter.

Описание методов

DrawEllipse() публичный Метод

public DrawEllipse ( Pen pen, int x, int y, int width, int height ) : void
pen System.Drawing.Pen
x int
y int
width int
height int
Результат void

DrawImage() публичный Метод

public DrawImage ( Image image, Point point ) : void
image Image
point Point
Результат void

DrawImage() публичный Метод

public DrawImage ( Image image, int x, int y ) : void
image Image
x int
y int
Результат void

DrawLine() публичный Метод

public DrawLine ( Pen pen, Point pt1, Point pt2 ) : void
pen System.Drawing.Pen
pt1 Point
pt2 Point
Результат void

DrawLine() публичный Метод

public DrawLine ( Pen pen, int x1, int y1, int x2, int y2 ) : void
pen System.Drawing.Pen
x1 int
y1 int
x2 int
y2 int
Результат void

DrawLines() публичный Метод

public DrawLines ( Pen pen, Point points ) : void
pen System.Drawing.Pen
points Point
Результат void

DrawPath() публичный Метод

public DrawPath ( Pen pen, GraphicsPath path ) : void
pen System.Drawing.Pen
path System.Drawing.Drawing2D.GraphicsPath
Результат void

DrawPolygon() публичный Метод

public DrawPolygon ( Pen pen, Point points ) : void
pen System.Drawing.Pen
points Point
Результат void

DrawRectangle() публичный Метод

public DrawRectangle ( Pen pen, Rectangle rect ) : void
pen System.Drawing.Pen
rect System.Drawing.Rectangle
Результат void

DrawString() публичный Метод

public DrawString ( string s, Font font, Brush brush, PointF point ) : void
s string
font System.Drawing.Font
brush System.Drawing.Brush
point System.Drawing.PointF
Результат void

DrawString() публичный Метод

public DrawString ( string s, Font font, Brush brush, PointF point, StringFormat format ) : void
s string
font System.Drawing.Font
brush System.Drawing.Brush
point System.Drawing.PointF
format System.Drawing.StringFormat
Результат void

DrawString() публичный Метод

public DrawString ( string s, Font font, Brush brush, RectangleF layoutRectangle ) : void
s string
font System.Drawing.Font
brush System.Drawing.Brush
layoutRectangle System.Drawing.RectangleF
Результат void

DrawString() публичный Метод

public DrawString ( string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format ) : void
s string
font System.Drawing.Font
brush System.Drawing.Brush
layoutRectangle System.Drawing.RectangleF
format System.Drawing.StringFormat
Результат void

FillEllipse() публичный Метод

public FillEllipse ( Brush brush, Rectangle rect ) : void
brush System.Drawing.Brush
rect System.Drawing.Rectangle
Результат void

FillEllipse() публичный Метод

public FillEllipse ( Brush brush, int x, int y, int width, int height ) : void
brush System.Drawing.Brush
x int
y int
width int
height int
Результат void

FillPath() публичный Метод

public FillPath ( Brush brush, GraphicsPath path ) : void
brush System.Drawing.Brush
path System.Drawing.Drawing2D.GraphicsPath
Результат void

FillPolygon() публичный Метод

public FillPolygon ( Brush brush, Point points ) : void
brush System.Drawing.Brush
points Point
Результат void

FillRectangle() публичный Метод

public FillRectangle ( Brush brush, Rectangle rect ) : void
brush System.Drawing.Brush
rect System.Drawing.Rectangle
Результат void

PDFGraphics() публичный Метод

Initializes a new instnace of PDFGraphics.
public PDFGraphics ( XGraphics graphics ) : System
graphics PdfSharp.Drawing.XGraphics An instance of which is used to /// create the PDF.
Результат System

ResetTransform() публичный Метод

public ResetTransform ( ) : void
Результат void

RotateTransform() публичный Метод

public RotateTransform ( float angle ) : void
angle float
Результат void

ScaleTransform() публичный Метод

public ScaleTransform ( float sx, float sy ) : void
sx float
sy float
Результат void

SetClip() публичный Метод

public SetClip ( GraphicsPath path, CombineMode combineMode ) : void
path System.Drawing.Drawing2D.GraphicsPath
combineMode CombineMode
Результат void

SetClip() публичный Метод

public SetClip ( Rectangle rect, CombineMode combineMode ) : void
rect System.Drawing.Rectangle
combineMode CombineMode
Результат void

SetClip() публичный Метод

public SetClip ( RectangleF rect, CombineMode combineMode ) : void
rect System.Drawing.RectangleF
combineMode CombineMode
Результат void

SetClip() публичный Метод

public SetClip ( Region region, CombineMode combineMode ) : void
region System.Drawing.Region
combineMode CombineMode
Результат void

TakeInitialTransform() публичный Метод

Takes the inital state.
public TakeInitialTransform ( ) : void
Результат void

TranslateTransform() публичный Метод

public TranslateTransform ( float dx, float dy ) : void
dx float
dy float
Результат void