Table of Contents

Class vdPrint

Namespace
VectorDraw.Professional.vdObjects
Assembly
VectorDraw.Professional.dll

Implements printing and print-preview operations for a vdLayout / vdDocument.

public sealed class vdPrint : vdObject, IDisposable, IVDSerialise, IBaseObject
Inheritance
vdPrint
Implements
Inherited Members

Examples

Example: Exports the active layout contents to a pdf file in A4 paper size

var printer = document.ActiveLayOut.Printer;
var path = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
printer.PrinterName = path+@"\VectorDraw Print to PDF.pdf";
printer.SelectPaper("A4");
printer.LandScape = false;
printer.PrintExtents();
//scale to fit will scale the drawing to fit in the paper size that you select, so it will not be printed in real size but it will be scaled to fit in the paper
printer.PrintScaleToFit();
printer.CenterDrawingToPaper();
printer.PrintOut();

Example creating a model space drawing with size 12x8 units that we want to print it in scale 1:100 in a paper size A4 in landscape orientation and how to calculate the proper text height to use in model space to be printed with a desired height in paper

//first we must calculate the text height that we have to use in model space so to be printed with the desired size in paper
//with the following reasoning:

//1.We assume that 1 drawing unit in model space is equal to 1 meter in real life
//2.We want to print in scale 1:100 with text height in paper to be 4mm
//   that means 1 mm in paper is equal to 100 mm in real life that is 0.1 meters in Drawing Units in model space,
//   So the scale from paper millimeters to model space DU is 0.1,
//      for example 10mm in paper is 1 meter in real life which is 1 DU in model space,
//      and 4 mm in paper is 0.4 meter in real life which is 0.4 DU in model space
//3.So if we want to have text with height 4 mm in paper after printing, you must set the text height = 4 x 0.1 = 0.4

doc.New(); //clear the document to start with a new one
double textheightmm = 4.0;
double vportscale = 100.0 / 1000.0;//= 0.1(paper/model), for scale 1:100, set 200.0 / 1000.0 for scale 1:200, set 1000.0 / 1000.0 for scale 1:1000, etc..
                        //textheightmm * vportscale ,will give us the text height in model space that we have to use for the text in model space to be printed with height 4 mm in paper after applying the print scale

//Create a sample drawing in model space with size 12x8 units add some text and dimensions taking in consideration the text height calculated above
doc.Model.Entities.AddItem(new vdRect(doc, new gPoint(0, 0), 12, 8, 0));
doc.Model.Entities.AddItem(new vdText(doc,"VectorDraw", new gPoint(6, 4), textheightmm * vportscale)
{
    VerJustify = VdConstVerJust.VdTextVerCen,
    HorJustify = VdConstHorJust.VdTextHorCenter
});
//add some dimensions
doc.Model.Entities.AddItem(new vdDimension(doc)
{
    TextHeight = textheightmm * vportscale,
    dimType = VdConstDimType.dim_Aligned,
    DefPoint1 = new gPoint(0, 0),
    DefPoint2 = new gPoint(0, 8),
    LinePosition = new gPoint(-0.5, 0),
    DimZin = LUnits.LZeroSuppression.DecimalAll,
    dimText = "<> m"
});

doc.Model.Entities.AddItem(new vdDimension(doc)
{
    TextHeight = textheightmm * vportscale,
    dimType = VdConstDimType.dim_Aligned,
    DefPoint1 = new gPoint(0, 8),
    DefPoint2 = new gPoint(12, 8),
    LinePosition = new gPoint(0, 8.5),
    DimZin = LUnits.LZeroSuppression.DecimalAll,
    dimText = "<> m"
});
//modify the model space printer properties to print the model space drawing in scale 1:100 in paper size A4 in landscape orientation
doc.Model.Printer.PrinterName = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + @"\Model 1-100.pdf";
doc.Model.Printer.SelectPaper("A4");
doc.Model.Printer.LandScape = true;
doc.Model.Printer.PrintExtents();
doc.Model.Printer.PrintScale = new PrinterScale(1000, 100);//for scale 1:100 (1000 / 100) = 10, for scale 1:200 (1000 / 200) = 5, for scale 1:1000 (1000 / 1000) = 1, etc..
doc.Model.Printer.CenterDrawingToPaper();
doc.Model.Printer.PrintOut();//export the pdf for model space with the scale 1:100 to see the result of the text height in paper after printing
doc.ZoomExtents();
doc.Redraw(false);

Example of following the code of the previous example and creating a layout with a viewport representing the model space drawing in scale 1:100 and adding a text table in the layout describing the project and then exporting the layout to pdf to see the result of the text height in paper after printing

//Add the code of previous example here to initialize the model space of your document
//create a layout 
var layout = doc.LayOuts.Add("Layout 1");
//assume that the paper size is A4 in landscape orientation which is 297 mm width and 210 mm height,
//add a border to the layout to see the paper size a litle bit offset from the paper borders
layout.Entities.AddItem(new vdRect(doc,new gPoint(3,8), 285,200,0));

//add a viewport to left side of layout with the proper viewport scale to represent the model space drawing in scale 1:100 in paper after printing
layout.Entities.AddItem(new vdViewport(doc)
{
    Center = new gPoint(100, 100),
    Width = 180,
    Height = 180,
    ViewCenter = new gPoint(6, 4),
    ViewportScale = 100.0 / 1000.0 // for scale 1:100 (100 / 1000) = 0.1 
                    // for scale 1:200 (200 / 1000) = 0.2
                    //for scale 1:1000 (1000 / 1000) = 1
                    //etc..
});
//add a text in the right side of the layout as a title describes the subject of our project
layout.Entities.AddItem(new vdMText(doc, "Example of a Viewport inside Layout representing a drawing in scale 1:100 and selecting a printer with paper size A4 in landscape", new gPoint(200, 185), 5)
{
    BoxWidth = 80,
    BackGroundMask = true,
    BackgroundMaskBorder = true,
    BackGroundMaskOffset = 4,
    BackGroundMaskColor = new vdColor(Color.White,0)
});

//set the printer properties for the layout to print in scale 1:1 and select the paper size A4 in landscape orientation
layout.Printer.PrinterName = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + @"/Layout 1-100.pdf";
layout.Printer.SelectPaper("A4");
layout.Printer.LandScape = true;
layout.Printer.PrintScale = new PrinterScale(1, 1);
layout.Printer.PrintWindow = new Box(new gPoint(0, 0), new gPoint(297, 210));

//make the layout active to be able to see the viewport and its content in the drawing area
doc.ActiveLayOut = layout;

layout.Printer.PrintOut();//export the pdf for the layout with the viewport representing the model space drawing in scale 1:100 to see the result of the text height in paper after printing
doc.ZoomAll();
doc.Redraw(false);

Remarks

The vdPrint object encapsulates printer selection, page setup (paper size, orientation,
hard and soft margins), print scaling and rendering behavior used to print a vdLayout.
It provides methods for rendering to a Graphics, exporting to various file
formats (PDF, SVG, EMF, raster images, HPGL, vdcl).
The output color handling, line weight display,
and optional per-palette print style overrides via PrintStyleTable.

Typical usage:

Notes:

  • When PrinterName refers to a file extension (for example ".pdf", ".svg", ".emf", ".bmp", ".jpg"), the object performs file export instead of sending output to a physical printer.

Constructors

vdPrint()

Initializes the vdPrint object.

vdPrint(vdPrint)

Initializes the vdPrint object matching the passed printer object.

Properties

AddPixelsBound

Specifies if one pixel is added to printer window output.

AutoUpdate

Specifies whether the automatic update will be called in order, circles, arcs, ellipses make use of smaller line segments for better quality.

ColorPalette

Get/Set the output color palette

Copies

Get/Set the number of copies to be printed out.

DisplayStatusDialog

Enable / Disable the printing status dialog.

Document

Gets the vdDocument that the object belongs.

DocumentName

Get/Set a string value that represents the printing document name.

DrawPaperHWMargins

et/Set the linetype that the printer's paper hardware margins are rendered.

Hardmargins

Get the hard paper margins of the selected printer in hundrends of inches in current orientation.

HardmarginsMM

Get the hard margins of selected printer in hundrends of millimeters in current orientation.

IgnoreGradientBG

Enable / Disable the printing and the print preview of the background gradient color.

IsFileExport

Returns true if the selected PrinterName ends with one of the following .HPG,.vdcl,.pdf,.svg,.jpg,.emf,.bmp,.gif,.tif,.png,.ico

LandScape

Get/Set a boolean value representing the paper orientation.

Layout

Get the vdLayout object which entities will be printed out.

LineWeights

Get/Set the Lineweight display.

OutInBlackWhite

Get/Set a value that represents if the output printing colors are all black.

PrintAsAPIWhenPossible

Get/Set a boolean value representing the way to use when printing.

PrintScale

Get/Set the PrinterScale of the vdPrint object.

PrintStyleTable

Returns an array of 255 items that overwrites the draw style properties of indexed color items.

PrintWindow

Get/Set a Box that represents the drawing rectangle to be printed out.The Box is in drawing units in Current View Coordinate System.

PrintableAreaMM

Get the printable area without hard margins in hundrends of millimeters in current orientation.

PrinterName

Get/Set the selected printer name.

Resolution

Get/Set the printer's resolution in Dot per inch.

ResolutionPositive

Returns the selected Resolution negative values (-1,-2,-3,-4 : Draft,Low,Medium,High) to their DPI value

UseDefaultPrinterBkColor

Specifies if the PrintOut() will use the default printer background or keep the backround of the screen.

margins

Get/Set the MARGINS of the vdPrint object in hundrends of inches.

paperSize

Get/Set a Rectangle object which represents the paper size in portrait orientation. WARNING! In case of raster type files you should keep in mind that the maximum size of bitmap advised is 1GB. This is a size of 16384 X 16384 pixels multiplied by 4 (all pixels consist of 4 bytes). Papersize width and height are calculated by the formula width(or height) / 100 * resolution. Resolution is defined as pixels per inches.

Methods

CenterDrawingToPaper()

Changes the Margins of the drawing forcing it to be printed out to the center of the drawing.

CopyFrom(vdPrint)

Copies all printer's properties from the passed parameter.

CreatePrintPageEvent(Graphics, PrintDocument)

Internally used only.

DeSerialize(DeSerializer, string, object)

This Function is called foreach field name of the vdPrint object when opening in vdml format.

DialogPreview(vdPrintInitialFlags)

Shows the VectorDraw print preview dialog.

DocumentPropertiesDialog(object)

Retrieves or modifies printer initialization information or displays a printer-configuration property sheet for the specified printer

DrawToBitmap(float, Rectangle, bool)

Simulates the printing output to a bitmap to use to a print preview dialog.

ExportToLines()

Exports the printable view area into a vdDocument object that contains single lines for all drawing objects.

GetPaper()

Get the name of the selected paper.

GetPapers()

Get all supported paper names for the selected printer.

InitializeProperties()

Resets the properties of the vdPrint object to the Default values.

PrintExtents()

Changes the PrintWindow property to the extends of the selected vdLayout for the vdPrint object.

PrintOut()

Prints the selected vdLayout object to the selected printer device.

PrintOutPage()

Prints the selected vdLayout object to the selected printer device as a single page in a multi page printing operation.

PrintScaleToFit()

Changes the PrintScale property so the selected printing area fits to the printer paper.

PrintablePaperDU()

Returns the rectanle in Drawing Units of Current View for the selected printer paper without the hard Margins.

PrintablePaperHInch()

Returns the rectangle of the selected printer paper in hundrends of inches without the Hard Margins.

PrinterSetup(object)

Shows a dialog to select a printer and modify it's properties.Also sets the selected printer's properties to the vdPrint object.

RenderToGraphics(Graphics)

Prints the into the passed Graphics device context.

RenderToGraphics(Graphics, Color)

Prints the into the passed Graphics device context.

SelectPaper(string)

Change the paper of the selected printer.

Serialize(Serializer)

This Function is called when saving the vdPrint object to vdml format.

SetLayout(vdLayout)

Select the passed vdLayout object for the vdPrint object.

ToString()

Gets a System.String that represents the PrinterName of the vdPrint Object.

Update()

Updates the object after change of properties.

UpdatePrinterFromProperties()

Passes the vdPrint properties to the selected printer.

UpdatePropertiesFromDefaultPrinter()

Changes the properties of the vdPrint object using the system's default printer and its settings (paper, orientation etc).

UpdatePropertiesFromPrinter(PrintDocument)

Changes the properties of the vdPrint object using the passed PrintDocument.

UpsideDown()

Inverts the margins in order the print origin to be closer to LowerRight instead UperLeft or the opposit.

VdprintableRectDU()

Returns the rectangle in Drawing Units of Current View for the printable selected area.

WhitePaperDU()

Returns the rectangle in Drawing Units of Current View for the selected printer paper with the Margins.