Prod.: Engine, ver.: 6, ID: 60000271, HowTo : Using the Printer to export to raster and PDF/SVG/EMF/HPGL files

HowTo : Using the Printer to export to raster and PDF/SVG/EMF/HPGL files

Article60000271
TypeHowTo
ProductEngine
Version6
Date Added10/16/2007
Submitted by
Keywords

Subject

Using the Printer to export to raster and PDF/SVG/EMF/HPGL files

Summary

Using the Printer to export to raster JPG/BMP/TIF/GIF and PDF/SVG/EMF/HPGL files

*** This article applies to version 6009 beta6 (6009 release) and above ***

Solution

In version 6010 and above the vdPrinter object can be used to export the whole drawing or part of it to raster ( BMP JPG GIF TIF ) and PDF, SVG, HPGL and EMF files. Below is a sample code in C# that can be used for this:

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

}

 

 
Using the VDF Wrapper ActiveX (vdraw.ocx) and the VectorDraw.Geometry.tlb and VectorDraw.Professional.tlb, you can do the same with a code like:

Private Sub Command1_Click()
 Dim doc As VectorDraw_Professional.vdDocument
 Dim box As Variant
 Dim EMFwidth As Long 
 Dim EMFheight As Long
 Dim extends As New VectorDraw_Geometry.box

    Set doc = VDraw1.ActiveDocument.WrapperObject
    
    doc.ActiveLayOut.Printer.PrinterName = App.Path + "\10165.emf"
    doc.ActiveLayOut.Printer.Resolution = 96

    extends.AddBox doc.ActiveLayOut.entities.GetBoundingBox(True, False)
    extends.Transformby doc.World2ViewMatrix
    extends.AddWidth doc.ActiveLayOut.Render.PixelSize * CDbl(0.5)
    
    EMFwidth = 1000
    EMFheight = CLng(EMFwidth * extends.Height / extends.Width + 0.5)

    doc.ActiveLayOut.Printer.SelectPaper "CUSTOM"
    doc.ActiveLayOut.Printer.MARGINS.Top = 0
    doc.ActiveLayOut.Printer.MARGINS.Bottom = 0
    doc.ActiveLayOut.Printer.MARGINS.Left = 0
    doc.ActiveLayOut.Printer.MARGINS.Right = 0
    doc.ActionLayout.Printer.Update
    
    VDraw1.ActiveDocument.ActiveLayOut.Printer.ActivePaperWidth = CLng(100# * CDbl(EMFwidth)  / CDbl(doc.ActiveLayOut.Printer.Resolution))
    VDraw1.ActiveDocument.ActiveLayOut.Printer.ActivePaperHeight = CLng(100# * CDbl(EMFheight) / CDbl(doc.ActiveLayOut.Printer.Resolution))
    
    
    Set doc.ActiveLayOut.Printer.PrintWindow = extends
    doc.ActiveLayOut.Printer.PrintScaleToFit
    doc.ActiveLayOut.Printer.PrintOut
End Sub