Planet PDF Forum Archive

Planet PDF ForumWowsers! This is page is old, head to the LIVE Planet PDF Forum. It features more than 10 conferences, covering everything from beginner to in-depth developer and pre-press discussions. If you wish to continue... one & two archive covers 1999-2011 (160,000 pages).


New Forum | Previous | Next | (P-PDF) Developers


Topic: Distiller print down problem
Conf: (P-PDF) Developers, Msg: 123382
From: randomwalker
Date: 12/6/2004 05:41 PM

Hi, Now I create an app which supports both print horizontal and vertical.
In this application, there are many report page, when print , some ones need print in vertical while other ones need to print in horizontal.
I create a function to create print dc. Now there are a problem. when app finish printing vertical and then go on printing in horizontal, app will down. It is strange that it only happen when the current printer is Acrobat 5.0 Pdf Distiller or Acrobat 6.0 PDF. But for some other printer such as real printer (HP or some other machine) and Acrobat pdf writer 5.0, it works good.
App only down in Release version, in debug version, it works well. and when I
add a code "AfxMessgeBox(" ......");" before the code CreateDC(), it works well in release version, too. So I am very confused about this.
Please give me some suggestion.
Thank you!
--------------------------------------------
COutputDC* GetECGPrinterDC(LPCTSTR lpszPrintDevice, BOOL bDuplex, long lPrintDirection)
{
CRacScanLDADoc* pDoc =((CRSCANApp*)AfxGetApp())->GetDocument();

HANDLE hPrinter;
if (!OpenPrinter((LPTSTR)lpszPrintDevice, &hPrinter, NULL))
return NULL;

int nSize = DocumentProperties(NULL, hPrinter, (LPTSTR)lpszPrintDevice,
NULL, NULL, 0);
if(nSize <= 0)
{
ClosePrinter( hPrinter ) ;
return NULL;
}
LPDEVMODE lpDevMode = (LPDEVMODE)MemoryAlloc(nSize);

// Fill in the rest of the structure.
if (DocumentProperties(NULL, hPrinter, (LPTSTR)lpszPrintDevice, lpDevMode,NULL, DM_OUT_BUFFER) != IDOK)
{
ClosePrinter( hPrinter ) ;
MemoryFree(lpDevMode);
return NULL;
}
lpDevMode->dmFields = DM_ORIENTATION |DM_PAPERSIZE |DM_COPIES |DM_PRINTQUALITY |DM_YRESOLUTION |DM_LOGPIXELS |DM_DUPLEX;
lpDevMode->dmOrientation=(lPrintDirection==PRINT_DIRECTION_PORTRAIT)?DMORIENT_PORTRAITMORIENT_LANDSCAPE;
lpDevMode->dmPaperSize = DMPAPER_A4;
lpDevMode->dmCopies= 1;
//revised by lgw 2000/11/17
// Set the print quality
int nPrinterType = pDoc->GetPrinterType (lpszPrintDevice);
if(nPrinterType != PRINTER_FILE_BMP)
{
lpDevMode->dmYResolution =300;
lpDevMode->dmPrintQuality =300;
}
else
{
// printer bitmap writer, read the print resolution from register.
REGSYSCONDITION sRegSys;
pDoc->MemGetSysCondition (sRegSys);
lpDevMode->dmYResolution = lpDevMode->dmPrintQuality = sRegSys.nBitmapResolution ;
}

if ( bDuplex )
lpDevMode->dmDuplex = (lPrintDirection==PRINT_DIRECTION_PORTRAIT) ? DMDUP_HORIZONTAL : DMDUP_VERTICAL;
else
lpDevMode->dmDuplex = DMDUP_SIMPLEX;

// set the parameters to the printer.
if (DocumentProperties(NULL, hPrinter, (LPTSTR)lpszPrintDevice, lpDevMode,
lpDevMode, DM_OUT_BUFFER|DM_IN_BUFFER) != IDOK)
{
ClosePrinter( hPrinter ) ;
MemoryFree(lpDevMode);
return NULL;
}

DWORD dBytes = 0 ;
GetPrinter(hPrinter, 2, NULL, 0, &dBytes);
PRINTER_INFO_2* pPrinterInfo = NULL ;
pPrinterInfo =(PRINTER_INFO_2*)MemoryAlloc ((int)dBytes);
GetPrinter(hPrinter, 2, (LPBYTE)pPrinterInfo, dBytes, &dBytes);
CDC *pDC =new CDC;

//-*********************************
AfxMessageBox("........"); // it add this code, no problem, else , system down in the following CreateDC() function in release version when printer is acorbat distiller, in debug, it work well.
//-*********************************

if(!(pDC->CreateDC(pPrinterInfo->pDriverName, pPrinterInfo->pPrinterName, pPrinterInfo->pPortName,(LPDEVMODE)lpDevMode)))
{
ClosePrinter( hPrinter ) ;
delete pDC ;
MemoryFree(pPrinterInfo);
MemoryFree(lpDevMode);
return NULL;
}

COutputDC* pOutputDC =new COutputDC(pDC, WIN_PRINT_ID, lPrintDirection);
pOutputDC->SetResolution (lpDevMode->dmYResolution);

// after get DC, free resources
ClosePrinter(hPrinter);
MemoryFree(pPrinterInfo);
MemoryFree(lpDevMode);
return pOutputDC;
}
--------------------------------------------

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link...

Download free demo

Debenu PDF Tools Pro

It's simple to use and will let you preview and edit PDF files, it's a Windows application that makes...

Download free demo

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
Platinum Sponsor





Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.

Features

Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.