| Article | 60000271 |
| Type | HowTo |
| Product | Engine |
| Version | 6 |
| Date Added | 10/16/2007 |
| Submitted by | |
| Keywords |
private
void button1_Click(object
sender, EventArgs e)
{
// Except for EMF, the same can be done with PDF, BMP, JPG, SVG, HPG (HPGL)
// From version 6010 and above the printer can be used in order to export an area or the whole drawing in a
// raster format (BMP, JPG), PDF, SVG, or HGPL#region create simple drawing
//create a simple drawing
vdFC.BaseControl.ActiveDocument.New();
vdFC.BaseControl.ActiveDocument.CommandAction.CmdBox3d(new VectorDraw.Geometry.gPoint(10, 10), 10, 12, 14, 10);
vdFC.BaseControl.ActiveDocument.CommandAction.CmdCircle(new VectorDraw.Geometry.gPoint(3, 3), 5.0d);
#endregion#region save as EMF the Extends using fixed EMF width
//save as EMF the Extends using fixed EMF width
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrinterName = "c:\\test_extends.emf"; // or PDF bmp jpg svg
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution=96; //Screen DPI
VectorDraw.Geometry.Box Extends= vdFC.BaseControl.ActiveDocument.ActiveLayOut.Entities.GetBoundingBox(true,true);
int EMFwidth = 500; //fixed width
int EMFheight = (int) (EMFwidth * Extends.Height/Extends.Width); // keep propotions
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.paperSize = new Rectangle(0, 0, (int)(EMFwidth * 100 / vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution), (int)(EMFheight * 100 / vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution));
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintExtents();
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintScaleToFit();
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintOut();
#endregion#region save as EMF the screen using fixed EMF height
//save as EMF the screen using fixed EMF height
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrinterName = "c:\\test_screen.emf"; // or PDF bmp jpg svg
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution = 96; //Screen DPI
VectorDraw.Geometry.Box screen_Box = new VectorDraw.Geometry.Box();
double screen_width = vdFC.BaseControl.ActiveDocument.ActiveLayOut.PixelSize * vdFC.BaseControl.Width;
double screen_height = vdFC.BaseControl.ActiveDocument.ActiveLayOut.ViewSize;
screen_Box.AddPoint(vdFC.BaseControl.ActiveDocument.ActiveLayOut.ViewCenter - new VectorDraw.Geometry.gPoint(screen_width / 2.0d, screen_height / 2.0d));
screen_Box.AddPoint(vdFC.BaseControl.ActiveDocument.ActiveLayOut.ViewCenter + new VectorDraw.Geometry.gPoint(screen_width / 2.0d, screen_height / 2.0d));
EMFheight = 500; // this is fixed
EMFwidth = (int)(EMFheight * screen_width / screen_height); //keeping the propotion
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.paperSize = new Rectangle(0, 0, (int)(EMFwidth * 100 / vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution), (int)(EMFheight * 100 / vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution));
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintWindow = screen_Box; // Here the code can be changed so
// the user can select a rectangle in screen and this area is saved to file.
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintScaleToFit();
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintOut();
#endregion#region call the PrintPreview in order the user to select the area to export to file
// call the PrintPreview in order the user to select the area to export to file
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrinterName = "*.emf"; // Using *.emf or *.pdf etc the print dialog will prompt a dialog to input the file name
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution = 96; //Screen DPI
EMFwidth = 500; //fixed width
EMFheight = 500; // and height
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.paperSize = new Rectangle(0, 0, (int)(EMFwidth * 100 / vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution), (int)(EMFheight * 100 / vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.Resolution));
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintExtents();
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.PrintScaleToFit();
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.InitializePreviewFormProperties(true, true, false, false);
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.CenterDrawingToPaper();
vdFC.BaseControl.ActiveDocument.ActiveLayOut.Printer.DialogPreview();
#endregion
}