⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdfcmdsampledlg.cpp

📁 i am server im imi mim im im
💻 CPP
📖 第 1 页 / 共 4 页
字号:
	if (out_dlg.DoModal() == IDOK)
	{
		CString dzFilePath = out_dlg.GetPathName( ) ;
        if (!dzFilePath.IsEmpty())
		{
			bSave = FALSE;
            _bstr_t dzPath = dzFilePath;
			try
			{
				m_pPDFFileEdit->Save(dzPath);
			}
			catch (_com_error e) 
			{
				AfxMessageBox(e.Description());
			}
		}
	}
}

void CPDFCMDSampleDlg::OnFileClose() 
{
	// TODO: Add your command handler code here
	if(m_pPDFPageEdit != NULL)
	{
		try
		{
			m_pPDFPageEdit->Close();
			m_pPDFPageEdit->Release();
		}
		catch(_com_error e)
		{
			AfxMessageBox(e.Description());
		}
	}
	if(m_pPDFFileEdit != NULL)
	{
		try
		{	
			m_pPDFFileEdit->Close();
			m_pPDFFileEdit->Release();
		}
		catch (_com_error e) 
		{
			AfxMessageBox(e.Description());
		}
		bFileOpened = FALSE;
		m_CString_FileProc = StaticHead;
		UpdateData(FALSE);
	}
	if(m_pSrcdoc != NULL)
	{
		try
		{	
			m_pSrcdoc->Close();
			m_pSrcdoc->Release();
		}
		catch (_com_error e) 
		{
			AfxMessageBox(e.Description());
		}
		bFileOpened = FALSE;
		m_CString_FileProc = StaticHead;
		UpdateData(FALSE);
	}
	if(m_pPDFForm != NULL)
	{
		try
		{
			m_pPDFForm->Close();
			m_pPDFForm.Release();
		}
		catch ( _com_error e) 
		{
			e.Description();
		}
	}
	bNewPage = FALSE;
}

void CPDFCMDSampleDlg::OnCreateAddfile()
{
	// TODO: Add your command handler code here
	CString szFileName;
	CFileDialog dlg( TRUE, _T("All file"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("All Files (*.*)|*.*||") ) ;
	if (dlg.DoModal()==IDOK)
	{
		_bstr_t szFileExt = dlg.GetFileExt() ;
		szFileName = dlg.GetPathName() ;
		if (szFileName.IsEmpty()) 
			return ;
		else
		{
			if(!IsFileTypeValid(szFileExt)&&(!IsFileTypePDF(szFileExt)))
			{
				AfxMessageBox("File Type not Supported!");
				return;
			}
			else if(IsFileTypePDF(szFileExt))
			{
				m_ClistBox_FileName.AddString(szFileName);
				bFileOpened = TRUE;
			}
			else
			{
				m_ClistBox_FileName.AddString(szFileName);
			}
		}
	}
}

void CPDFCMDSampleDlg::OnCreateConvert() 
{
	// TODO: Add your command handler code here
	_bstr_t in_FilePath = "",out_FilePath = "";
    int i = 0, len = 0;
	CString FilePath = ""; 
	CString	dzFilePath = "";
	CString FileName = "";
	CString FileFullName = "";
	_bstr_t FileExt = "";
	if(m_ClistBox_FileName.GetCount()  < 1)
	{
		AfxMessageBox("You must add a file or more files");
		return;
	}
	while( !(m_ClistBox_FileName.GetTextLen(i) == LB_ERR))
	{
 		len = m_ClistBox_FileName.GetTextLen(i);
 		m_ClistBox_FileName.GetText(i,FilePath.GetBuffer(len));
		FilePath.ReleaseBuffer();	
		FileExt = FilePath.Right(3);
		len =  FilePath.ReverseFind('\\');
        FileFullName = FilePath;
		FileFullName.Delete(0,len+1);
		FileName = FileFullName.Left((FileFullName.GetLength() - 4));
		if(!IsFileTypePDF(FileExt))
		{
 			CFileDialog out_dlg( FALSE, _T("pdf"), FileName, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("PDF Files (*.pdf)|*.pdf||") ) ;
			if (out_dlg.DoModal() == IDOK)
 			{
				CString dzFilePath = out_dlg.GetPathName();
				if (dzFilePath.IsEmpty()) return;
				m_CString_FileProc = StaticHead+FileFullName;
				UpdateData(FALSE);
				out_FilePath = dzFilePath;
				in_FilePath = FilePath;
				try
				{
					m_pPDFCreate->Convert(in_FilePath, out_FilePath);
				}
				catch (_com_error e) 
				{
					AfxMessageBox(e.Description());
				}
 		}
 	}
 		i++;
 	}
}

void CPDFCMDSampleDlg::OnCreateDeletefile() 
{
	// TODO: Add your command handler code here
	if(m_ClistBox_FileName.GetCount()<=0)
	{
		return;
	}
	else{
		int CurrentSel = m_ClistBox_FileName.GetCurSel();
		if(CurrentSel == LB_ERR){
			AfxMessageBox("Please specify the file you want to delete!");
		}
		else{
			if(m_ClistBox_FileName.DeleteString(CurrentSel) == LB_ERR)
				AfxMessageBox("Delete file failed");
		}
	}
}

void CPDFCMDSampleDlg::OnCreateConcate() 
{
	// TODO: Add your command handler code here
	CFileDialog dlg( FALSE, _T("pdf"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("PDF Files (*.pdf)|*.pdf||") ) ;
	if (dlg.DoModal() == IDOK)
	{
		CString FilePath = dlg.GetPathName( );
        if (!FilePath.IsEmpty( ))
		{
            _bstr_t dzPath = FilePath;
			try
			{
				m_pPDFCombine->Concate(dzPath);
			}
			catch (_com_error e) 
			{
				AfxMessageBox(e.Description());
			}
		}
	}
}

void CPDFCMDSampleDlg::OnCreateOverlay() 
{
	// TODO: Add your command handler code here
	CFileDialog dlg( FALSE, _T("pdf"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("PDF Files (*.pdf)|*.pdf||") ) ;
	if (dlg.DoModal() == IDOK)
	{
		CString FilePath = dlg.GetPathName( );
        if (!FilePath.IsEmpty( ))
		{
            _bstr_t dzPath = FilePath;
			try
			{
				m_pPDFCombine->Overlay(dzPath);
			}
			catch (_com_error e) 
			{
				AfxMessageBox(e.Description());
			}
		}
	}
}

void CPDFCMDSampleDlg::OnCreatePreference() 
{
	// TODO: Add your command handler code here
	UnitEnum Unit=Unit_MM;
	StandardPageSizeEnum Standard=SP_Screen;
	OrientationEnum Orientation=Orient_Landscape;
    ResolutionEnum Resolution=Resolution_2400;
	CompatibleEnum Compatible=Compatible_PDF14;
	ColorCompressMethodEnum ColorCompMethod=CCM_JPEG2000_LOW;
	ReSampleMethodEnum ReSampleMethod=Sub_Sample;
	MonoCompressMethodEnum MonoCompMethod=MCM_RunLength;
	VARIANT_BOOL bCustomPageSize, bViewPDF, bOptimizePDF, bAutoCompressionColor;
	VARIANT_BOOL bCompressColor, bResampleColor;
	CPreferenceDlg PrfrsDlg;
	m_pPDFGeneralSetting->get_Orientation(&Orientation);
    PrfrsDlg.m_int_Orientation = Orientation-1;
	m_pPDFGeneralSetting->get_StandardPageSize(&Standard);
	PrfrsDlg.m_int_StandardSize = Standard;
	m_pPDFGeneralSetting->get_UseCustomPageSize(&bCustomPageSize);
	PrfrsDlg.m_int_PaperSize = -bCustomPageSize;
	m_pPDFGeneralSetting->get_Width(&PrfrsDlg.m_double_Width);
	m_pPDFGeneralSetting->get_Height(&PrfrsDlg.m_double_Height);
	m_pPDFGeneralSetting->get_Margin(&PrfrsDlg.m_double_Margin);
	m_pPDFGeneralSetting->get_Unit(&Unit);
	PrfrsDlg.m_int_Unit = Unit;
	m_pPDFGeneralSetting->get_Resolution(&Resolution);
	PrfrsDlg.m_int_Resolution = Resolution;
	m_pPDFGeneralSetting->get_Compatible(&Compatible);
	PrfrsDlg.m_int_Compatible = Compatible;
	m_pPDFGeneralSetting->get_ZoomScale(&PrfrsDlg.m_long_Scale);
	m_pPDFGeneralSetting->get_ViewPDF(&bViewPDF);
	PrfrsDlg.m_BOOL_ViewPDF = -bViewPDF;
	m_pPDFGeneralSetting->get_OptimizePDF(&bOptimizePDF);
	PrfrsDlg.m_BOOL_OptimizePDF = -bOptimizePDF;
	m_pPDFCompSetting->get_AutoCompression(&bAutoCompressionColor);
	PrfrsDlg.m_int_ColorCompression = bAutoCompressionColor+1;
	m_pPDFCompSetting->get_AutoCompressionRate(&PrfrsDlg.m_long_ColorAutoRate);
	m_pPDFCompSetting->get_CompressColor(&bCompressColor);
	PrfrsDlg.m_BOOL_CompressColor = -bCompressColor;
	m_pPDFCompSetting->get_ColorCompressMethod(&ColorCompMethod);
	if(ColorCompMethod<=5)
	{
		PrfrsDlg.m_int_ColorCmprsMethod = ColorCompMethod;
	}
	else
	{
		PrfrsDlg.m_int_ColorCmprsMethod = ColorCompMethod - 9;
	}
	m_pPDFCompSetting->get_ReSampleColor(&bResampleColor);
	PrfrsDlg.m_BOOL_ResampleColor = -bResampleColor;
	m_pPDFCompSetting->get_ColorReSampleMethod(&ReSampleMethod);
	PrfrsDlg.m_int_ColorRsmpMethod = ReSampleMethod;
	m_pPDFCompSetting->get_ColorReSampleResolution(&PrfrsDlg.m_long_ColorRsmpResolution);
	if(PrfrsDlg.DoModal() == IDOK)
	{
		if(PrfrsDlg.m_int_Orientation)
		{
			m_pPDFGeneralSetting->put_Orientation(Orient_Landscape);
		}
		else
		{
			m_pPDFGeneralSetting->put_Orientation(Orient_Portrait);
		}
        switch(PrfrsDlg.m_int_StandardSize) 
		{
		case 0:
			m_pPDFGeneralSetting->put_StandardPageSize(SP_Letter);
			break;
		case 1:
			m_pPDFGeneralSetting->put_StandardPageSize(SP_Legal);
			break;
		case 2:
			m_pPDFGeneralSetting->put_StandardPageSize(SP_Tabloid);
			break;
		case 3:
			m_pPDFGeneralSetting->put_StandardPageSize(SP_A4);
			break;
		case 4:
			m_pPDFGeneralSetting->put_StandardPageSize(SP_A3);
			break;
		case 5:
			m_pPDFGeneralSetting->put_StandardPageSize(SP_Executive);
			break;
		case 6:
			m_pPDFGeneralSetting->put_StandardPageSize(SP_B4);
			break;
		case 7:
			m_pPDFGeneralSetting->put_StandardPageSize(SP_B5);
			break;
		case 8:
			m_pPDFGeneralSetting->put_StandardPageSize(SP_Screen);
            break;
		default:
			m_pPDFGeneralSetting->put_StandardPageSize(SP_A4);
			break;
		}
		m_pPDFGeneralSetting->put_UseCustomPageSize(-PrfrsDlg.m_int_PaperSize);
		m_pPDFGeneralSetting->put_Width(PrfrsDlg.m_double_Width);
		m_pPDFGeneralSetting->put_Height(PrfrsDlg.m_double_Height);
		m_pPDFGeneralSetting->put_Margin(PrfrsDlg.m_double_Margin);
		switch(PrfrsDlg.m_int_Unit) 
		{
		case 0:
			m_pPDFGeneralSetting->put_Unit(Unit_Inches);
			break;
		case 1:
			m_pPDFGeneralSetting->put_Unit(Unit_MM);
			break;
		case 2:
			m_pPDFGeneralSetting->put_Unit(Unit_Points);
			break;
		}
		switch(PrfrsDlg.m_int_Resolution) 
		{
		case 0:
			m_pPDFGeneralSetting->put_Resolution(Resolution_72);
			break;
		case 1:
			m_pPDFGeneralSetting->put_Resolution(Resolution_150);
			break;
		case 2:
			m_pPDFGeneralSetting->put_Resolution(Resolution_300);
			break;
		case 3:
			m_pPDFGeneralSetting->put_Resolution(Resolution_600);
			break;
		case 4:
			m_pPDFGeneralSetting->put_Resolution(Resolution_1200);
			break;
		case 5:
			m_pPDFGeneralSetting->put_Resolution(Resolution_2400);
			break;
		default:
			break;
		}
		switch(PrfrsDlg.m_int_Compatible) 
		{
		case 0:
            m_pPDFGeneralSetting->put_Compatible(Compatible_PDF13);
			break;
		case 1:
			m_pPDFGeneralSetting->put_Compatible(Compatible_PDF14);
			break;
		case 2:
			m_pPDFGeneralSetting->put_Compatible(Compatible_PDF15);
			break;
		default:
			break;
		}
		m_pPDFGeneralSetting->put_ZoomScale(PrfrsDlg.m_long_Scale);
		m_pPDFGeneralSetting->put_ViewPDF(-PrfrsDlg.m_BOOL_ViewPDF);
		m_pPDFGeneralSetting->put_OptimizePDF(-PrfrsDlg.m_BOOL_OptimizePDF);
		m_pPDFCompSetting->put_AutoCompression(PrfrsDlg.m_int_ColorCompression-1);
		m_pPDFCompSetting->put_AutoCompressionRate(PrfrsDlg.m_long_ColorAutoRate);
		m_pPDFCompSetting->put_CompressColor(-PrfrsDlg.m_BOOL_CompressColor);
		switch(PrfrsDlg.m_int_ColorCmprsMethod) 
		{
		case 0:
			m_pPDFCompSetting->put_ColorCompressMethod(CCM_JPEG_HIGH);
			break;
		case 1:
			m_pPDFCompSetting->put_ColorCompressMethod(CCM_JPEG_MEDIUMHIGH);
			break;
		case 2:
			m_pPDFCompSetting->put_ColorCompressMethod(CCM_JPEG_MEDIUM);
			break;
		case 3:
			m_pPDFCompSetting->put_ColorCompressMethod(CCM_JPEG_MEDIUMLOW);
			break;
		case 4:
			m_pPDFCompSetting->put_ColorCompressMethod(CCM_JPEG_LOW);
			break;
		case 5:
			m_pPDFCompSetting->put_ColorCompressMethod(CCM_ZIP);
			break;
		case 6:
			m_pPDFCompSetting->put_ColorCompressMethod(CCM_JPEG2000_HIGH);
			break;
		case 7:
			m_pPDFCompSetting->put_ColorCompressMethod(CCM_JPEG2000_MEDIUMHIGH);
			break;
		case 8:
			m_pPDFCompSetting->put_ColorCompressMethod(CCM_JPEG2000_MEDIUM);
			break;
		case 9:
			m_pPDFCompSetting->put_ColorCompressMethod(CCM_JPEG2000_MEDIUMLOW);
			break;
		case 10:
			m_pPDFCompSetting->put_ColorCompressMethod(CCM_JPEG2000_LOW);
			break;
		}
		m_pPDFCompSetting->put_ReSampleColor(-PrfrsDlg.m_BOOL_ResampleColor);
		switch(PrfrsDlg.m_int_ColorRsmpMethod) 
		{
		case 0:
			m_pPDFCompSetting->put_ColorReSampleMethod(Down_Sample);
			break;
		case 1:
			m_pPDFCompSetting->put_ColorReSampleMethod(Sub_Sample);
			break;
		}
		m_pPDFCompSetting->put_ColorReSampleResolution(PrfrsDlg.m_long_ColorRsmpResolution);
	}
}

void CPDFCMDSampleDlg::OnDocuInfomation() 
{
	CGetDocInfo getdocinfodlg;
	CGetDocInfo *dlgt=&getdocinfodlg;
	BSTR titlename;
	VARIANT Key,Value;
	if(bFileOpened)
	{
		hr=m_pPDFDocInfo->get_Title(&titlename);
		char strtitle[2048] = {0} ;
		wsprintf( strtitle,	"%S",titlename);
		getdocinfodlg.m_title=strtitle;
		m_pPDFDocInfo->get_Author(&titlename);
		wsprintf( strtitle,	"%S",titlename);
		getdocinfodlg.m_author =strtitle;
		m_pPDFDocInfo->get_Keyword(&titlename);
		wsprintf( strtitle,	"%S",titlename);
		getdocinfodlg.m_keyword=strtitle;
		m_pPDFDocInfo->get_Subject(&titlename);
		wsprintf( strtitle,	"%S",titlename);
		getdocinfodlg.m_subject=strtitle;
		getdocinfodlg.m_pagenum = m_pPDFFileEdit->GetPageNum();
		CString strout2;
		long dicount=0;
		dicount = m_pPDFDocInfo->GetCustomDocInfoCount();
		getdocinfodlg.m_cdocinfocount=dicount;
		for(int i=0;i<dicount;i++)
		{
			m_pPDFDocInfo->GetCustomDocInfo(i , &Key , &Value);
			getdocinfodlg.titlename1[i].Format("%S", Key.pcVal);
			getdocinfodlg.titlename2[i].Format("%S", Value.pcVal);
		}
		if(Key.pcVal != NULL)
		{
			strout2.Format( "%S",getdocinfodlg.titlename1[0]);
			getdocinfodlg.m_cdocinfokey=strout2;
			strout2.Format( "%S",getdocinfodlg.titlename2[0]);
			getdocinfodlg.m_cdocinfo=strout2;
		}
		if(getdocinfodlg.DoModal()==IDOK)
		{
			for(int di=0;di<getdocinfodlg.delkeyi;di++)
			{
				bSave = TRUE;
				BSTR bstrdeldey=_bstr_t(getdocinfodlg.delkey[di]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -