Skip to main content Skip to footer

Loading ActiveX VSPrinter Documents into C1PrintDocument

Few years ago we had a sample for converting and viewing VsPrinter Documents (*.vp) files in C1PrintPreview (1.x) control. But after the introduction of 2.0 framework and merging of C1Report and C1Preview controls, the object model of the Preview controls changed. In this blog, we will provide code for loading VsPrinter Document files into C1PrintDocument, which can be viewed with C1PrintPreviewControl (2.0& 4.0).

About VsPrinter Document Files

The VsPrinter control has a VSPrinter.SaveDoc method for saving the VSPrinter document files (.vp). These files are compressed archives containing one enhanced metafile per page. These enhanced metafiles can then be added as RenderImages into a C1PrintDocument.

Loading VP Files in C1PrintDocument

The implementation is quite simple.

  1. Create a Winforms application and add a VSPrinter control.
  2. Load the document files into the VSPrinter control.
  3. Extract the page images per page and add them as RenderImages to C1PrintDocument.
  4. Load C1PrintDocument in C1PrintPreviewControl.

Code for the above implementation is :

// loads the specified VSPrinter document into the preview  
private void loadVP(string fileName)  
        c1PrintPreviewControl1.PreviewPane.Busy = true;  
        _vp.LoadDoc(fileName, false);  
        // add pages to C1PrintPreviewControl control  
        C1PrintDocument doc = new C1PrintDocument();  
        for (short page = 1; page <= _vp.PageCount; ++page)  
            _vp.PreviewPage = page;  
            doc.PageLayout.PageSettings.TopMargin = 0;  
            doc.PageLayout.PageSettings.LeftMargin= 0;  
            if (\_vp.Picture.Height< \_vp.Picture.Width )  
                doc.PageLayout.PageSettings.Landscape = true;  
                doc.PageLayout.PageSettings.Landscape = false ;  
            doc.Body.Children.Add(new RenderImage(_vp.Picture));  
        c1PrintPreviewControl1.Document = doc;  
        MessageBox.Show(string.Format("Error loading {0}", fileName));  
        c1PrintPreviewControl1.PreviewPane.Busy = false;  

Download Sample (C#.NET) Download Sample (VB.NET)


comments powered by Disqus