We sometimes create several PDF's with one print call. With Version 2.10 the first PDF doc is fine but all additional documents are blank.
Our code basically
LPCTSTR szPrinter = "LL PDF Generator";
m_DC.CreateDC("WINSPOOL", szPrinter, NULL, NULL);
EnablePrinter
DOCINFO di;
::ZeroMemory (&di, sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = "Winflex Doc";
di.lpszOutput = file(n).pdf
m_PrintingOK = m_DC.StartDoc(&di);
m_DC.StartPage();
// printing
m_DC.EndPage();
...
m_DC.EndDoc();
HDC createdDC = m_DC.Detach(); // detach the printer DC}
DeleteDC(createdDC);
m_DC.DeleteDC();
Then I basically do the exact same thing with a different filename
(ie file1.pdf file2.pdf ...)
This code worked fine in version 2.04 and earlier.
Version 2.10e creates blank PDF's
Hello Troy,
Attached is a snippet of code that is very similar to what you are doing. Hope this helps.
void CPDFsampleView::OnPdfPrint()
{
// TODO: Add your command handler code here
HFONT font, oldFont;
HDC dc;
DOCINFO di;
// create a printer device context
dc = CreateDC( "winspool", theApp.m_szPrinter, NULL, NULL );
if ( NULL == dc )
{
ASSERT( FALSE );
return;
}
// init the DOCINFO structure, set the output file name
memset( &di, 0, sizeof(di) );
di.cbSize = sizeof( di );
di.lpszDocName = "Test document";
//using the DOCINFO filename
di.lpszOutput = "c:\\test.pdf";
theApp.m_icd.SetDefaultPrinter();
theApp.m_icd.SetFileNameOptionsEx (0x8000001);
// activate printer before starting to print
theApp.m_icd.EnablePrinter("Evaluation Version Developer", "07EFCDAB01000100584F8296EDE2DB671EE2564605C79BD0F9AEB6BDBA542926639B79ECC556F310DB8592F1C68BF146A4D4E86EB8C0E7824CE83E1E8DC2244454F2F7CA64FC6CF3CC82B6221CF4FDE37CB45301E0EF96E5D0200FD36A0E276889666828B1AACE0364E11C1C5632F9E2B4" );
// start printing
StartDoc( dc, &di );
StartPage( dc );
MoveToEx( dc, 100, 100, NULL );
LineTo( dc, 400, 100 );
MoveToEx( dc, 100, 100, NULL );
LineTo( dc, 100, 400 );
font = CreateFont( -24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _T("Verdana") );
oldFont = (HFONT)SelectObject( dc, font );
TextOut( dc, 100, 100, _T("Hi There"), 8 );
if ( oldFont ) SelectObject( dc, oldFont );
DeleteObject( font );
font = CreateFont( -24, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, _T("Wingdings") );
oldFont = (HFONT)SelectObject( dc, font );
TextOut( dc, 100, 200, _T("Hi There"), 8 );
if ( oldFont ) SelectObject( dc, oldFont );
DeleteObject( font );
EndPage( dc );
EndDoc( dc );
DeleteDC( dc );
// printing ended, no need to disactivate printer
// the printer will be disactivated automatically
}
Attached is a snippet of code that is very similar to what you are doing. Hope this helps.
void CPDFsampleView::OnPdfPrint()
{
// TODO: Add your command handler code here
HFONT font, oldFont;
HDC dc;
DOCINFO di;
// create a printer device context
dc = CreateDC( "winspool", theApp.m_szPrinter, NULL, NULL );
if ( NULL == dc )
{
ASSERT( FALSE );
return;
}
// init the DOCINFO structure, set the output file name
memset( &di, 0, sizeof(di) );
di.cbSize = sizeof( di );
di.lpszDocName = "Test document";
//using the DOCINFO filename
di.lpszOutput = "c:\\test.pdf";
theApp.m_icd.SetDefaultPrinter();
theApp.m_icd.SetFileNameOptionsEx (0x8000001);
// activate printer before starting to print
theApp.m_icd.EnablePrinter("Evaluation Version Developer", "07EFCDAB01000100584F8296EDE2DB671EE2564605C79BD0F9AEB6BDBA542926639B79ECC556F310DB8592F1C68BF146A4D4E86EB8C0E7824CE83E1E8DC2244454F2F7CA64FC6CF3CC82B6221CF4FDE37CB45301E0EF96E5D0200FD36A0E276889666828B1AACE0364E11C1C5632F9E2B4" );
// start printing
StartDoc( dc, &di );
StartPage( dc );
MoveToEx( dc, 100, 100, NULL );
LineTo( dc, 400, 100 );
MoveToEx( dc, 100, 100, NULL );
LineTo( dc, 100, 400 );
font = CreateFont( -24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _T("Verdana") );
oldFont = (HFONT)SelectObject( dc, font );
TextOut( dc, 100, 100, _T("Hi There"), 8 );
if ( oldFont ) SelectObject( dc, oldFont );
DeleteObject( font );
font = CreateFont( -24, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, _T("Wingdings") );
oldFont = (HFONT)SelectObject( dc, font );
TextOut( dc, 100, 200, _T("Hi There"), 8 );
if ( oldFont ) SelectObject( dc, oldFont );
DeleteObject( font );
EndPage( dc );
EndDoc( dc );
DeleteDC( dc );
// printing ended, no need to disactivate printer
// the printer will be disactivated automatically
}
More Info
After some more research I found out it wasn't in the creating of the pdf files at all. They are going blank when I'm adding the encryption.
when I create the pdf files I create an array of strings of all the pdf file I've created.
Now here is my code for adding encryption. (normally I save to the same file but when I wrote to a different file the originals are fine but the 2-nth encrypted file are blank - the first encrypted file is fine too.)
IDIDocument amyuni;
CoInitialize(NULL);
COleException oe;
bool dispOK = amyuni.CreateDispatch("CDIntfEx.Document",&oe);
if (dispOK)
{
try
{
for (int i=0; i < m_PDFFiles.GetSize(); i++)
{
amyuni.Open(m_PDFFiles.GetAt(i));
amyuni.SetLicenseKey(company, key);
amyuni.Encrypt("password", "", -64+4);
amyuni.Save("c:\\pdftest\\encrypted" + LConvertType::toString(i) + ".pdf");
}
}
catch(CException* e)
{
char message[1024];
e->GetErrorMessage(message, sizeof(message)-1);
MessageBox(0, message, "Error while Creating PDF", MB_OK|MB_ICONEXCLAMATION);
e->Delete();
}
}
else
{
char tmp[1024];
oe.GetErrorMessage(tmp, 1023);
MessageBox(0, "Cannot create dispatch!!!\n" + tmp, "test", MB_OK);
}
when I create the pdf files I create an array of strings of all the pdf file I've created.
Now here is my code for adding encryption. (normally I save to the same file but when I wrote to a different file the originals are fine but the 2-nth encrypted file are blank - the first encrypted file is fine too.)
IDIDocument amyuni;
CoInitialize(NULL);
COleException oe;
bool dispOK = amyuni.CreateDispatch("CDIntfEx.Document",&oe);
if (dispOK)
{
try
{
for (int i=0; i < m_PDFFiles.GetSize(); i++)
{
amyuni.Open(m_PDFFiles.GetAt(i));
amyuni.SetLicenseKey(company, key);
amyuni.Encrypt("password", "", -64+4);
amyuni.Save("c:\\pdftest\\encrypted" + LConvertType::toString(i) + ".pdf");
}
}
catch(CException* e)
{
char message[1024];
e->GetErrorMessage(message, sizeof(message)-1);
MessageBox(0, message, "Error while Creating PDF", MB_OK|MB_ICONEXCLAMATION);
e->Delete();
}
}
else
{
char tmp[1024];
oe.GetErrorMessage(tmp, 1023);
MessageBox(0, "Cannot create dispatch!!!\n" + tmp, "test", MB_OK);
}
One Solution and a question.
I moved the creation of the IDIDocument inside of the loop. And now it works!!! I'm just wondering why this doesn't work the other way? Creating the IDIDocument for every file seems very inefficient. Please let me know if there is any way I can do this better?
Thanks
Troy
Thanks
Troy