PdfWriter Class
A simple class for creating PDF files. It will not hold contents into memory, so it can be used with little memory.
Remarks
This class is not intended for providing a complete API for writing PDFs, only what is necessary to create them from xls files. Even when this class could be used standalone, on most cases FlexCelPdfExport should be used.
Syntax
Namespace: FlexCel.Pdf
public class PdfWriter
Constructors
Name | Description |
---|---|
PdfWriter | Creates a new PDF file instance. |
Methods
Name | Description |
---|---|
BeginDoc | Call this method before starting the output. It will initialize a new page. After this you can call DrawString(String, TUIFont, TUIBrush, Double, Double), NewPage, etc. Always end the document with a call to EndDoc and then remember to close the stream. |
EndDoc | Always call this method to write the final part of a pdf file. |
NewPage | Closes the active page and creates a new one. All following commands will go to the new page. |
DrawString | Overloaded DrawString(String, TUIFont, TUIBrush, Double, Double) DrawString(String, TUIFont, TUITextDecoration, TUIBrush, Double, Double) DrawString(String, TUIFont, TUIPen, TUIBrush, Double, Double) DrawString(String, TUIFont, TUITextDecoration, TUIPen, TUIBrush, Double, Double) |
Hyperlink | Overloaded Hyperlink(Double, Double, Double, Double, String) Hyperlink(Double, Double, Double, Double, Uri) Hyperlink(Double, Double, Double, Double, Int32, Double, Double) |
Comment | Creates a comment on the pdf file. |
GetBookmarks | Returns all the bookmarks on the file. Note that this will return a COPY of the bookmarks, so changing them will not change them in the file. You need to use SetBookmarks to replace the new list. |
SetBookmarks | Replaces the bookmarks on the file with other list. The new list will be copied, so you can change the old list after setting it and it will not affect the file. |
AddBookmark | Adds a new bookmark to the document. |
MeasureString | Returns the size of a string in points * Scale. (1/72 of an inch * Scale) |
FontHeight | Returns the font height on points * Scale. (1/72 of an inch * Scale) |
FontLinespacing | Returns the font white space on points * Scale. (1/72 of an inch * Scale) |
FontDescent | Returns the font height on points * Scale. (1/72 of an inch * Scale) |
DrawLine | Draws a line on the current page. |
DrawLines | Draws an array of line connecting pairs of points. |
FillRectangle | Fills the interior of a rectangle specified by a pair of coordinates, a width, and a height. No line is drawn around the rectangle. |
DrawRectangle | Draws a rectangle specified by a coordinate pair, a width, and a height. |
DrawAndFillRectangle | Draws and fills a rectangle specified by a coordinate pair, a width, and a height. |
DrawAndFillBeziers | Draws and/or fills a bezier path. If Brush is not null, the shape will be closed for filling. |
DrawAndFillMultiBeziers | Draws and/or fills a bezier path. |
DrawAndFillPolygon | Draws and/or fills a polygon. The shape will be closed. |
IntersectClipRegion | Intersects the current clipping region with the new one. There is no command to reset or expand a clipping region, you need to use SaveState and RestoreState |
ClipRectangle | Intersect the clip region with a rectangle specified by a pair of coordinates, a width, and a height. |
ClipPolygon | Intersects the clipping area with a polygon. |
ClipBeziers | Intersects the clipping area with a bezier region. |
ClipMultiBeziers | Intersects the clipping area with multiple bezier regions. |
DrawImage | Overloaded DrawImage(TUIImage, TUIRectangle, Stream) DrawImage(TUIImage, TUIRectangle, Stream, Int64, Boolean) |
Rotate | Rotates the canvas around point (x,y). |
ScaleBy | Overloaded ScaleBy(Double, Double) ScaleBy(Double, Double, Double, Double) |
GetMatrix | Returns the drawing matrix in use. The elements in this matrix are similar to the ones returned by "System.Drawing.Drawing2D.Matrix.Elements" and have the same meaning. Important remark. This matrix is the real one, and does not consider things like YAxisGrowsDown or Scale. You will probably want to use Transform(TPointF) to find out the coordinates of a point. |
Transform | Overloaded Transform(TPointF) Transform(TPointF, Double[]) |
SaveState | Saves the current graphic state. Be sure to always call RestoreState each time you call this method. |
RestoreState | Restores the graphic state saved by a SaveState call. |
Sign | Signs the pdf documents with the specified TPdfSignature or TPdfVisibleSignature. Note: This method must be called before calling BeginDoc |
TagContentBegin | Marks the start of a content tag inside a stream. Must be finished with a call to TagContentEnd |
TagContentEnd | Ends marking content which started with TagContentBegin |
AttachFile | Overloaded AttachFile(String, String, String, TPdfAttachmentKind) AttachFile(String, String, String, DateTime, TPdfAttachmentKind, TPdfAttachmentDataProviderDelegate) |
ClearAttachments | Removes all existing attachments in the writer. |
Properties
Name | Description |
---|---|
Compress | Set it to true to compress the text on the generated pdf file. |
Properties | Properties of the PDF file. |
PageSize | Page size of the active page. You can change it *before* calling NewPage() and it will change for the new sheets. Note that once NewPage() (or BeginDoc() for the first page) is called, the page size will remain constant for that page. This property must be changed before. |
YAxisGrowsDown | When true, the y axis origin corresponds to the upper corner of a sheet and bigger Y coordinates will move down on the paper. This is the standard GDI+ behavior. When false, the Y origin is at the bottom and it grows up into the page. This is the standard PDF behavior. |
AddFontDescent | When false, (the default) text base will be at the y coordinate. For example, DrawString(..., y=100,...) will draw a string with its base at 100. Font descent (for example the lower part of a "p") will be below 100, and the ascent (the upper part) will be above. This is the standard PDF behavior. When true, all text will be drawn above the y coordinate. (both ascent and descent). This is the standard GDI+ behavior, when StringFormat.LineAlignment=StringAlignment.Far. |
Scale | A scale factor to change X and Y coordinates. When Scale=1, the using is the point (1/72 of an inch). Font size is not affected by scale, it is always in points. |
PdfType | Defines the type of pdf being created. Note that if you set this property to other value than standard, other properties might be ignored. For example, when creating a PDF/A file all fonts must be embedded so the value of the FontEmbed property will be ignored. |
UnlicensedFontAction | Defines what to do when a font has a license that doesn't allow embedding, and you are trying to embed the font. |
UnlicensedReplacementFont | When trying to embed a font that isn't licensed for embedding, and UnlicensedFontAction is TUnlicensedFontAction.Replace this property specifies the font that will be used to replace it. If null or empty, Arial will be used. |
PdfVersion | Defines the version of pdf being created. For maximum compatibility you can choose PDF 1.4. (Acrobat 5.0, but can be opened by any version of Acrobat, even if version less than 1.4 won't have all the features). Choosing PDF 1.6 (Acrobat 7) allows for more compression and smaller files, but you'll need Acrobat 7 or newer to see the files. Older versions won't be able to open it at all. Note that this value will be ignored if you are creating PDFA-1 (as it requires PDF1-4). Also for signing, FlexCel requires PDF1-6. |
EmbedColorProfile | If true, a color profile will be embedded in the generated pdf files. An embedded color profile can increase the size of the generated file in some kilobytes, and it isn't required or needed, so you'll normally want to keep this property false. For PDF/A, it is required, but when you set the PdfType to PDF/A the color profile will always be included anyway, and this property will be ignored. |
FontEmbed | Determines what fonts will be embedded on the generated pdf. Note that when using UNICODE fonts WILL BE EMBEDDED no matter the value of this property. Also if creating PDF/A files. |
FontSubset | When FontEmbed is set to embed the fonts, this setting determines if the full font will be embedded, or only the characters used in the document. If the full font is embedded the resulting file will be larger, but it will be possible to edit it with a third party tool once it has been generated. |
FontMapping | Determines how fonts will be replaced on the generated pdf. Pdf comes with 4 standard font families, Serif, Sans-Serif, Monospace and Symbol. You can use for example the standard Helvetica instead of Arial and do not worry about embedding the font. |
Kerning | By default, pdf does not do any kerning with the fonts. This is, on the string "AVANT", it won't compensate the spaces between "A" and "V". (they should be smaller) If you turn this property on, FlexCel will calculate the kerning and add it to the generated file. The result file will be a little bigger because of the kerning info on all strings, but it will also look a little better. |
UseFauxStyles | When a font doesn't have a bold, italic or bold-italic variant, FlexCel can't export bold, italic or bold-italic characters to the pdf respectively. When this property is true (the default), FlexCel will try to "fake" those missing styles by using a wider pen width for the characters to simulate bold, or doing a slant transform to simulate italics. The results of a simulated bold or italic can be not great, so if you prefer that FlexCel doesn't try to simulate bold or italics, then you can set this property to false. If this property is false and the font you are using doesn't have bold or italics variants, then the pdf won't show bold or italics for that font. ...[more] |
FallbackFonts | A semicolon (;) separated list of font names to try when a character is not found in the used font. When a character is not found in a font, it will display as an empty square by default. By setting this property, FlexCel will try to find a font that supports this character in this list, and if found, use that font to render the character. |
FallbackFontsBold | A semicolon (;) separated list of font names similar to FallbackFonts that will be used only for bold fonts. If you fallback fonts already contain bold variants, you don't need to set this property. This property is only if you want to use different font fallbacks for bold fonts and regular fonts. |
FallbackFontsItalic | A semicolon (;) separated list of font names similar to FallbackFonts that will be used only for italic fonts. If you fallback fonts already contain italic variants, you don't need to set this property. This property is only if you want to use different font fallbacks for italic fonts and regular fonts. |
FallbackFontsBoldItalic | A semicolon (;) separated list of font names similar to FallbackFonts that will be used only for fonts which are both bold and italic. If you fallback fonts already contain bold-italic variants, you don't need to set this property. This property is only if you want to use different font fallbacks for bold-italic fonts and regular fonts. |
GetFontData | Use this event if you want to provide your own font information for embedding for a particular instance. Note that if you don't assign this event, GetFontDataGlobal will be used instead. If GetFontData and GetFontDataGlobal are not assigned the default method will be used, and this will try to find the font on the Fonts folder. To change the font folder, use GetFontFolder event |
GetFontDataGlobal | Use this event if you want to provide your own font information for embedding for the full application. Note that if you assign GetFontData for a particular object instance it will be used instead. Important: This event isn't thread safe or guarded by any lock. You should set it once when your application starts and never modify it. For changing a particular instance, use GetFontData instead. If you aren't sure, use GetFontData |
GetFontFolder | Use this event if you want to provide your own font information for embedding for a particular object instance. For changing the font folder for the full application, use GetFontFolderGlobal instead. Normally FlexCel will search for fonts on [System]\Fonts folder and %localappdata%\Microsoft\Windows\Fonts. If your fonts are in other location, you can tell FlexCel where they are here. If you prefer just to give FlexCel the full data on the font, you can use...[more] |
GetFontFolderGlobal | Use this event if you want to provide your own font folder for the full application. Note that if you assign GetFontFolder for a particular object instance it will be used instead. Important: This event isn't thread safe or guarded by any lock. You should set it once when your application starts and never modify it. For changing a particular instance, use GetFontFolder instead. If you aren't sure, use GetFontFolder Note that you can return more than one path by separating them with semicolons. For example if you return "c:\fonts1;c:\fonts2" FlexCel will search both in fonts1 and fonts2. Every folder you specify here must have at least one font. ...[more] |
OnFontEmbed | Use this event if you want to manually specify which fonts to embed into the pdf document. Note that this applies for a single PdfWriter instance, to set it for the full application, use OnFontEmbedGlobal |
OnFontEmbedGlobal | Use this event if you want to manually specify which fonts to embed into the pdf document for the full application. Note that if you assign OnFontEmbed for a particular object instance it will be used instead. Important: This event isn't thread safe or guarded by any lock. You should set it once when your application starts and never modify it. For changing a particular instance, use OnFontEmbed instead. If you aren't sure, use OnFontEmbed...[more] |
OnFontFolderNotFound | This property determines how FlexCel behaves when one of the folders you specify in GetFontFolder doesn't exist. Note that this applies for a single PdfWriter instance, to set it for the full application, use OnFontFolderNotFoundGlobal |
OnFontFolderNotFoundGlobal | This property determines how FlexCel behaves when one of the folders you specify in GetFontFolder doesn't exist. Important: This event isn't thread safe or guarded by any lock. You should set it once when your application starts and never modify it. For changing a particular instance, use OnFontFolderNotFound instead. If you aren't sure, use OnFontFolderNotFound |
PageLayout | Sets the default page layout when opening the document. |
PageLayoutDisplay | Sets the default page display layout when opening the document. |
InitialZoomAndPage | Sets the default zoom and initial page when opening the document. |
TagActions | Implement this interface in order to define the tags. |