📄 printtoimagedlg.cpp
字号:
// PrintToImageDlg.cpp : implementation file
//
#include "stdafx.h"
#include "pdfcmdsample.h"
#include "PrintToImageDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPrintToImageDlg dialog
CPrintToImageDlg::CPrintToImageDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPrintToImageDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPrintToImageDlg)
m_strSourceFilePath = _T("");
m_strDestFilePath = _T("");
m_PageCount = 0;
m_PageRange = _T("");
m_bRemoveMargin = FALSE;
m_PageNo = 0;
m_PageDPI = 96;
m_PageScale = 50;
m_PageHeight = 100;
m_PageWidth = 100;
pMainDlg = (CPDFCMDSampleDlg *)pParent;
m_KeepRadio = FALSE;
//}}AFX_DATA_INIT
}
void CPrintToImageDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPrintToImageDlg)
DDX_Control(pDX, IDC_KEEPRADIO, m_CheckKeepRadio);
DDX_Control(pDX, IDC_PAGE_DPI, m_EditPageDPI);
DDX_Control(pDX, IDC_PAGE_HEIGHT, m_EditPageHeight);
DDX_Control(pDX, IDC_PAGE_SCALE, m_EditPageScale);
DDX_Control(pDX, IDC_PAGE_WIDTH, m_EditPageWidth);
DDX_Control(pDX, IDC_IMAGE_SIZE, m_ImageSize);
DDX_Control(pDX, IDC_PAGE_NO, m_EditPageNo);
DDX_Control(pDX, IDC_PAGE_RANGE, m_EditPageRange);
DDX_Control(pDX, IDC_TIFF_COMPRESS, m_TIFFCompress);
DDX_Control(pDX, IDC_ROTATE_DEGREE, m_Rotate);
DDX_Control(pDX, IDC_CONTENT, m_Content);
DDX_Control(pDX, IDC_IMAGE_FORMAT, m_ImageFormat);
DDX_Control(pDX, IDC_BPP, m_BPP);
DDX_Text(pDX, IDC_PAGE_COUNT, m_PageCount);
DDX_Text(pDX, IDC_PAGE_RANGE, m_PageRange);
DDX_Check(pDX, IDC_REMOVE_MARGIN, m_bRemoveMargin);
DDX_Text(pDX, IDC_PAGE_NO, m_PageNo);
DDX_Text(pDX, IDC_PAGE_DPI, m_PageDPI);
DDX_Text(pDX, IDC_PAGE_SCALE, m_PageScale);
DDX_Text(pDX, IDC_PAGE_HEIGHT, m_PageHeight);
DDX_Text(pDX, IDC_PAGE_WIDTH, m_PageWidth);
DDX_Check(pDX, IDC_KEEPRADIO, m_KeepRadio);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPrintToImageDlg, CDialog)
//{{AFX_MSG_MAP(CPrintToImageDlg)
ON_BN_CLICKED(IDC_BTN_PRINT_TO_IMAGE, OnBtnPrintToImage)
ON_CBN_SELCHANGE(IDC_IMAGE_FORMAT, OnSelchangeImageFormat)
ON_CBN_SELCHANGE(IDC_BPP, OnSelchangeBpp)
ON_CBN_SELCHANGE(IDC_CONTENT, OnSelchangeContent)
ON_CBN_EDITCHANGE(IDC_IMAGE_SIZE, OnEditchangeImageSize)
ON_CBN_SELCHANGE(IDC_IMAGE_SIZE, OnSelchangeImageSize)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPrintToImageDlg message handlers
void CPrintToImageDlg::OnBtnPrintToImage()
{
// TODO: Add your control notification handler code here
CFileDialog PDFDlg(TRUE, _T("pdf"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("PDF Files(*.pdf)|*.pdf||"));
CFileDialog BitmapDlg(FALSE, _T("Bitmap File"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("Bitmap Files(*.bmp)|*.bmp||"));
CFileDialog TIFFDlg(FALSE, _T("TIFF File"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("TIFF Files(*.tiff)|*.tiff||"));
CFileDialog MultiTIFFDlg(FALSE, _T("MultiTIFF File"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("MultiTIFF Files(*.tiff)|*.tiff||"));
CFileDialog GIFDlg(FALSE, _T("GIF File"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("GIF Files(*.gif)|*.gif||"));
CFileDialog JPEGDlg(FALSE, _T("JPEG File"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("JPEG Files(*.jpeg)|*.jpeg||"));
CFileDialog JPEG2000Dlg(FALSE, _T("JPEG2000 File"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("JPEG2000 Files(*.jp2)|*.jp2||"));
CString strPDFFilePath,strImageFilePath,strGIFFilePath,strJPEGFilepath;
long width, height;
int iFormatCurSel(0),iBPPCurSel(0);
iBPPCurSel = m_BPP.GetCurSel();
UpdateData(TRUE);
if(PDFDlg.DoModal() == IDOK)
{
strPDFFilePath = PDFDlg.GetPathName();
}
else
{
return;
}
if(pMainDlg->m_pPDFPrintToImage != NULL)
{
VARIANT vr;
V_VT(&vr) = VT_BSTR;
V_BSTR(&vr) = strPDFFilePath.AllocSysString();
m_QueryPassword.Initialize(pMainDlg->m_pPDFPrintToImage,DIID__IPDF2ImageEvents);
try
{
pMainDlg->m_pPDFPrintToImage->OpenFile(vr, "");
m_PageCount = pMainDlg->m_pPDFPrintToImage->GetPageCount();
pMainDlg->m_pPDFPrintToImage->PutremoveMargin(m_bRemoveMargin);
if(bScaleORSize)
{
pMainDlg->m_pPDFPrintToImage->SetScale(m_PageScale,m_PageDPI);
}
else
{
pMainDlg->m_pPDFPrintToImage->SetSize(m_PageWidth , m_PageHeight , m_KeepRadio);
}
UpdateData(FALSE);
}
catch(_com_error e)
{
AfxMessageBox( e.Description());
}
m_QueryPassword.Uninitialize(pMainDlg->m_pPDFPrintToImage,DIID__IPDF2ImageEvents);
int iRotateSel = m_Rotate.GetCurSel();
switch(iRotateSel)
{
case 0:
pMainDlg->m_pPDFPrintToImage->put_rotation(Rotate_0);
break;
case 1:
pMainDlg->m_pPDFPrintToImage->put_rotation(Rotate_90);
break;
case 2:
pMainDlg->m_pPDFPrintToImage->put_rotation(Rotate_180);
break;
case 3:
pMainDlg->m_pPDFPrintToImage->put_rotation(Rotate_270);
break;
case 4:
pMainDlg->m_pPDFPrintToImage->put_rotation(Rotate_Neg_90);
break;
case 5:
pMainDlg->m_pPDFPrintToImage->put_rotation(Rotate_Neg_180);
break;
case 6:
pMainDlg->m_pPDFPrintToImage->put_rotation(Rotate_Neg_270);
break;
}
int iContentSel = m_Content.GetCurSel();
switch(iContentSel)
{
case 0:
pMainDlg->m_pPDFPrintToImage->put_content(PC_ContentAndForm);
break;
case 1:
pMainDlg->m_pPDFPrintToImage->put_content(PC_ContentOnly);
break;
case 2:
pMainDlg->m_pPDFPrintToImage->put_content(PC_FormOnly);
break;
}
iFormatCurSel = m_ImageFormat.GetCurSel();
switch(iFormatCurSel)
{
case 0:
if(TIFFDlg.DoModal() == IDOK)
strImageFilePath = TIFFDlg.GetPathName();
else
return;
switch(iBPPCurSel)
{
case 0:
pMainDlg->m_pPDFPrintToImage->PrintToTIFF(m_PageNo, (LPSTR)(LPCSTR)strImageFilePath, BPP_1,GetCompress(), 0, &width, &height);
break;
case 1:
pMainDlg->m_pPDFPrintToImage->PrintToTIFF(m_PageNo, (LPSTR)(LPCSTR)strImageFilePath, BPP_4,GetCompress() ,0, &width, &height);
break;
case 2:
pMainDlg->m_pPDFPrintToImage->PrintToTIFF(m_PageNo, (LPSTR)(LPCSTR)strImageFilePath, BPP_8,GetCompress() ,0, &width, &height);
break;
case 3:
pMainDlg->m_pPDFPrintToImage->PrintToTIFF(m_PageNo, (LPSTR)(LPCSTR)strImageFilePath, BPP_16,GetCompress() ,0, &width, &height);
break;
case 4:
pMainDlg->m_pPDFPrintToImage->PrintToTIFF(m_PageNo, (LPSTR)(LPCSTR)strImageFilePath, BPP_24,GetCompress() ,0, &width, &height);
break;
}
VariantClear(&vr);
ShellExecute(NULL, "open", strImageFilePath, NULL, NULL, SW_SHOW);
break;
case 1:
if(MultiTIFFDlg.DoModal() == IDOK)
strImageFilePath = MultiTIFFDlg.GetPathName();
else
return;
switch(iBPPCurSel)
{
case 0:
pMainDlg->m_pPDFPrintToImage->PrintToMultiTIFF(m_PageRange.AllocSysString(), (LPSTR)(LPCSTR)strImageFilePath, BPP_1,GetCompress(), 0, &width, &height);
break;
case 1:
pMainDlg->m_pPDFPrintToImage->PrintToMultiTIFF(m_PageRange.AllocSysString(), (LPSTR)(LPCSTR)strImageFilePath, BPP_4,GetCompress() ,0, &width, &height);
break;
case 2:
pMainDlg->m_pPDFPrintToImage->PrintToMultiTIFF(m_PageRange.AllocSysString(), (LPSTR)(LPCSTR)strImageFilePath, BPP_8,GetCompress() ,0, &width, &height);
break;
case 3:
pMainDlg->m_pPDFPrintToImage->PrintToMultiTIFF(m_PageRange.AllocSysString(), (LPSTR)(LPCSTR)strImageFilePath, BPP_24,GetCompress() ,0, &width, &height);
break;
}
VariantClear(&vr);
ShellExecute(NULL, "open", strImageFilePath, NULL, NULL, SW_SHOW);
break;
case 2:
if(BitmapDlg.DoModal() == IDOK)
{
strImageFilePath = BitmapDlg.GetPathName();
}
else
return;
switch(iBPPCurSel)
{
case 0:
pMainDlg->m_pPDFPrintToImage->PrintToBMP(m_PageNo, (LPSTR)(LPCSTR)strImageFilePath, BPP_1, &width, &height);
break;
case 1:
pMainDlg->m_pPDFPrintToImage->PrintToBMP(m_PageNo, (LPSTR)(LPCSTR)strImageFilePath, BPP_4, &width, &height);
break;
case 2:
pMainDlg->m_pPDFPrintToImage->PrintToBMP(m_PageNo, (LPSTR)(LPCSTR)strImageFilePath, BPP_8, &width, &height);
break;
case 3:
pMainDlg->m_pPDFPrintToImage->PrintToBMP(m_PageNo, (LPSTR)(LPCSTR)strImageFilePath, BPP_16, &width, &height);
break;
case 4:
pMainDlg->m_pPDFPrintToImage->PrintToBMP(m_PageNo, (LPSTR)(LPCSTR)strImageFilePath, BPP_24, &width, &height);
break;
}
VariantClear(&vr);
ShellExecute(NULL, "open", strImageFilePath, NULL, NULL, SW_SHOW);
break;
case 3:
if(GIFDlg.DoModal() == IDOK)
strGIFFilePath = GIFDlg.GetPathName();
else
return;
pMainDlg->m_pPDFPrintToImage->PrintToGIF(m_PageNo, strGIFFilePath.AllocSysString(), &width, &height);
VariantClear(&vr);
ShellExecute(NULL, "open", strGIFFilePath, NULL, NULL, SW_SHOW);
break;
case 4:
if(JPEGDlg.DoModal() == IDOK)
strJPEGFilepath = JPEGDlg.GetPathName();
else
return;
pMainDlg->m_pPDFPrintToImage->PrintToJPEG(m_PageNo,strJPEGFilepath.AllocSysString(),0, &width, &height);
VariantClear(&vr);
ShellExecute(NULL, "open", strJPEGFilepath, NULL, NULL, SW_SHOW);
break;
case 5:
if(JPEG2000Dlg.DoModal() == IDOK)
strJPEGFilepath = JPEG2000Dlg.GetPathName();
else
return;
try
{
pMainDlg->m_pPDFPrintToImage->PrintToJPEG2000(m_PageNo,strJPEGFilepath.AllocSysString(),50,&width, &height);
}
catch (_com_error e)
{
MessageBox(e.Description());
}
VariantClear(&vr);
ShellExecute(NULL, "open", strJPEGFilepath, NULL, NULL, SW_SHOW);
break;
}
}
}
void CPrintToImageDlg::OnBtnBrowseSource()
{
// TODO: Add your control notification handler code here
CFileDialog PDFDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "PDF Files (*.pdf)|*.pdf||", this);
if (PDFDlg.DoModal() != IDOK)
return ;
// GetDlgItem(IDC_EDIT_SOURCE)->SetWindowText(PDFDlg.GetPathName()) ;
}
void CPrintToImageDlg::OnBtnBrowseDest()
{
// TODO: Add your control notification handler code here
CFileDialog ImgDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "All Files (*.*)|*.*||", this);
if (ImgDlg.DoModal() != IDOK)
return ;
// GetDlgItem(IDC_EDIT_DEST)->SetWindowText(ImgDlg.GetPathName()) ;
}
void CPrintToImageDlg::OnSelchangeImageFormat()
{
// TODO: Add your control notification handler code here
int iSel = m_ImageFormat.GetCurSel();
int i(0);
//int icount = m_ImageFormat.GetCount();
switch(iSel)
{
case 0:
m_TIFFCompress.EnableWindow(TRUE);
m_EditPageRange.EnableWindow(FALSE);
m_EditPageNo.EnableWindow(TRUE);
m_BPP.EnableWindow(TRUE);
for( ;i < 7; i++)
m_BPP.DeleteString(0);
m_BPP.InsertString(0,"1 bit");
m_BPP.InsertString(1,"4 bits");
m_BPP.InsertString(2,"8 bits");
m_BPP.InsertString(3,"24 bits");
m_BPP.SetCurSel(0);
UpdateData(FALSE);
break;
case 1:
m_EditPageRange.EnableWindow(TRUE);
m_TIFFCompress.EnableWindow(TRUE);
m_EditPageNo.EnableWindow(FALSE);
m_BPP.EnableWindow(TRUE);
for( ;i < 7; i++)
m_BPP.DeleteString(0);
m_BPP.InsertString(0,"1 bit");
m_BPP.InsertString(1,"4 bits");
m_BPP.InsertString(2,"8 bits");
m_BPP.InsertString(3,"24 bits");
m_BPP.SetCurSel(0);
UpdateData(FALSE);
break;
case 2:
m_TIFFCompress.EnableWindow(FALSE);
m_EditPageRange.EnableWindow(FALSE);
m_EditPageNo.EnableWindow(TRUE);
m_BPP.EnableWindow(TRUE);
for( ;i < 7; i++)
m_BPP.DeleteString(0);
m_BPP.InsertString(0,"1 bit");
m_BPP.InsertString(1,"4 bits");
m_BPP.InsertString(2,"8 bits");
m_BPP.InsertString(3,"16 bits");
m_BPP.InsertString(4,"24 bits");
m_BPP.SetCurSel(0);
UpdateData(FALSE);
break;
case 3:
m_TIFFCompress.EnableWindow(FALSE);
m_EditPageRange.EnableWindow(FALSE);
m_EditPageNo.EnableWindow(TRUE);
m_BPP.EnableWindow(TRUE);
for( ;i < 7; i++)
m_BPP.DeleteString(0);
m_BPP.InsertString(0,"8 bits");
m_BPP.SetCurSel(0);
UpdateData(FALSE);
break;
case 4:
m_TIFFCompress.EnableWindow(FALSE);
m_EditPageRange.EnableWindow(FALSE);
m_EditPageNo.EnableWindow(TRUE);
m_BPP.EnableWindow(TRUE);
for( ;i < 7; i++)
m_BPP.DeleteString(0);
m_BPP.EnableWindow(FALSE);
UpdateData(FALSE);
break;
case 5:
m_TIFFCompress.EnableWindow(FALSE);
m_EditPageRange.EnableWindow(FALSE);
m_EditPageNo.EnableWindow(TRUE);
m_BPP.EnableWindow(TRUE);
for( ;i < 7; i++)
m_BPP.DeleteString(0);
m_BPP.EnableWindow(FALSE);
UpdateData(FALSE);
break;
}
}
void CPrintToImageDlg::OnSelchangeBpp()
{
// TODO: Add your control notification handler code here
}
void CPrintToImageDlg::OnPrintToImage()
{
}
BOOL CPrintToImageDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_EditPageRange.EnableWindow(FALSE);
m_EditPageWidth.EnableWindow(FALSE);
m_EditPageHeight.EnableWindow(FALSE);
m_CheckKeepRadio.EnableWindow(FALSE);
m_ImageFormat.SetCurSel(0);
m_BPP.SetCurSel(0);
m_TIFFCompress.SetCurSel(0);
m_Rotate.SetCurSel(0);
m_Content.SetCurSel(0);
m_ImageSize.SetCurSel(0);
bScaleORSize = TRUE;
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
TIFFCompressEnum CPrintToImageDlg::GetCompress()
{
int iSel;
iSel = m_TIFFCompress.GetCurSel();
switch(iSel)
{
case 0: return TIFF_NO_COMPRESS;
case 1: return TIFF_CCITT_G3 ;
case 2: return TIFF_CCITT_G4 ;
case 3: return TIFF_LZW ;
case 4: return TIFF_JPEG_24B ;
case 5: return TIFF_ZIP ;
}
return TIFF_NO_COMPRESS;
}
void CPrintToImageDlg::OnSelchangeContent()
{
// TODO: Add your control notification handler code here
}
void CPrintToImageDlg::OnEditchangeImageSize()
{
// TODO: Add your control notification handler code here
}
void CPrintToImageDlg::OnSelchangeImageSize()
{
// TODO: Add your control notification handler code here
int iSel = m_ImageSize.GetCurSel();
switch(iSel)
{
case 0:
bScaleORSize = TRUE;
m_EditPageScale.EnableWindow(TRUE);
m_EditPageDPI.EnableWindow(TRUE);
m_EditPageWidth.EnableWindow(FALSE);
m_EditPageHeight.EnableWindow(FALSE);
m_CheckKeepRadio.EnableWindow(FALSE);
break;
case 1:
bScaleORSize = FALSE;
m_EditPageScale.EnableWindow(FALSE);
m_EditPageDPI.EnableWindow(FALSE);
m_EditPageWidth.EnableWindow(TRUE);
m_EditPageHeight.EnableWindow(TRUE);
m_CheckKeepRadio.EnableWindow(TRUE);
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -