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.
-
Create a Winforms application and add a VSPrinter control.
-
Load the document files into the VSPrinter control.
-
Extract the page images per page and add them as RenderImages to C1PrintDocument.
-
Load C1PrintDocument in C1PrintPreviewControl.
Code for the above implementation is:
// loads the specified VSPrinter document into the preview
private void loadVP(string fileName)
{
try
{
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;
else
doc.PageLayout.PageSettings.Landscape = false ;
doc.Body.Children.Add(new RenderImage(_vp.Picture));
}
c1PrintPreviewControl1.Document = doc;
}
catch
{
MessageBox.Show(string.Format("Error loading {0}", fileName));
}
finally
{
c1PrintPreviewControl1.PreviewPane.Busy = false;
}
}