Universal Document Converter
Product Overview
Download
Purchase
Tutorials
Developer Solutions
Support Service
About fCoder SIA


      Site search
   


      Popular conversions
PDF to JPG converter
Convert Word to PDF
Convert PDF to TIFF
Autocad to PDF converter
Convert Word to JPG
Powerpoint to PDF converter
Printing to PDF
Convert Excel to PDF
Convert DJVU to PDF
Convert Web Page to PDF

      Video tutorials
Show tutorial



Main page>Developer Solutions>Post-Print Examples

Print Image on Desktop Printer Using GDI+


Universal Document Converter is virtual printer software that saves any document you print as a raster PDF or an image file. You can use a post-print feature of Universal Document Converter to apply additional processing to every output file. The example below is just one of many post-print processing solutions. Please let us know if you cannot find the solution you need.

// You can automatically send copy of each image file produced by
// Universal Document Converter from your application using GDI+.
//
// You must initialize GDI+ in your InitInstance() function using
// "GdiplusStartup(...)" and release it in your ExitInstance()
// function using "GdiplusShutdown(...)".
#include "Winspool.h"
#include <atlconv.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib, "Gdiplus.lib")
BOOL PrintImageUsingGDIPlus( char* szPath, char* szPrn )
{
  DEVMODE  *pDM;
  LONG     dmLen;
  HANDLE   prnHandle;
  HDC      hDC;
  UINT     dimCount, frameCount;
  GUID     *pDimIDs;
  GUID     pageGuid;
  float    width, height;
  DOCINFO  di = { sizeof(DOCINFO), "Printing My Image" };
////
  if( !OpenPrinter( szPrn, &prnHandle, 0 ) )
    return 0;
  dmLen = DocumentProperties( 0, prnHandle, szPrn, 0, 0, 0 );
  pDM = (DEVMODE*)new char[dmLen];
  DocumentProperties( 0, prnHandle, szPrn, pDM, 0, DM_OUT_BUFFER );
////
  hDC = CreateDC( szPrn, szPrn, 0, pDM );
  delete pDM;
  if( !hDC )
  {
    ClosePrinter( prnHandle );
    return 0;
  }
  if( StartDoc( hDC, &di ) == SP_ERROR )
  {
    ClosePrinter( prnHandle );
    return 0;
  }
////
  Graphics graphics( hDC );
// Loading image from file
  USES_CONVERSION;
  Image image( A2W( szPath ) );
  dimCount = image.GetFrameDimensionsCount();
  pDimIDs = new GUID[dimCount];
// Get the list of frame dimensions from the Image object
  image.GetFrameDimensionsList( pDimIDs, dimCount );
// Get the number of frames (pages) in the first dimension
  frameCount = image.GetFrameCount( &pDimIDs[0] );
  delete pDimIDs;
  pageGuid = FrameDimensionPage;
  for( UINT i = 0; i < frameCount; i++ )
  {
    StartPage( hDC );
    image.SelectActiveFrame( &pageGuid, i );
    graphics.SetPageUnit( UnitInch );
		
    width = image.GetWidth() / image.GetHorizontalResolution();
    height = image.GetHeight() / image.GetVerticalResolution();
    graphics.DrawImage( &image, 0.f, 0.f, width, height );
		
    EndPage( hDC );
  }
////
  EndDoc( hDC );
  ClosePrinter( prnHandle );
  return ( frameCount > 0 ) ? TRUE : FALSE;
}



Related topics
Popular pages
Popular solutions


© fCoder SIA About fCoder SIA | Privacy Policy | Site Map