Universal Document Converter
Información general
Descargas
Comprar
Tutoriales
Desarrolladores
Soporte técnico
Acerca de fCoder SIA


      Búsqueda en el sitio
   


      Conversiones populares
Adobe PDF a JPEG
Word Document a PDF
Hojas de cálculo Excel a PDF
PowerPoint a JPEG
Diseño Visio a PDF
Diseño AutoCAD a TIFF
Página web a JPEG
Convertir de cálculo Excel a PDF
Convertir DjVu a PDF
Convertir una página web a PDF

      Tutorial de vídeo
Ver el tutorial



Página principal>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 Acerca de fCoder SIA | Mapa del sitio