解决了什么问题? 在一些扫描版电子书中, 扫描的不是很清晰, 如果在PS中处理一下就好了
以下代码段实现功能:
从指定的PDF文件中读取每一页, 并且自动执行所指定的Action. 再另存到一个目录中去.
1
2 const char* szActionSetName = m_strSetName;
3 const char* szActionName = m_strActionName;
4 const char* szPsAppID = "Photoshop.Application";
5 const char* szPsPdfID = "Photoshop.PDFOpenOptions";
6 CString savePath = m_strOutputDir;
7 CApplication* pPhotoshopApplication = new CApplication;
8 pPhotoshopApplication->CreateDispatch(szPsAppID);
9 pPhotoshopApplication->put_Visible(false);
10 CDocuments* pPhotoshopDocuments= new CDocuments(
11 pPhotoshopApplication->get_Documents());
12 for( unsigned int i=m_iStartPage; i<=m_iEndPage; ++i)
13 {
14 CPDFOpenOptions* PdfOpenOpt = new CPDFOpenOptions();
15 PdfOpenOpt->CreateDispatch(szPsPdfID);
16 PdfOpenOpt->put_Page(i);
17 VARIANT OpenOptions;
18 OpenOptions.vt= VT_DISPATCH;
19 OpenOptions.pdispVal= PdfOpenOpt->m_lpDispatch;
20 pPhotoshopApplication->Open( m_strInputPdfFile, OpenOptions);
21 delete PdfOpenOpt;
22 pPhotoshopApplication->DoAction(szActionName, szActionSetName);
23 LPDISPATCH docItem= pPhotoshopApplication->get_ActiveDocument();
24 CDocument0 SingleDocument(docItem);
25 CString name= SingleDocument.get_Name();
26 char filebuff[256];
27 sprintf_s(filebuff, 256, "%s//%04d.gif", savePath, i);
28 CString strFullName= filebuff;
29 CGIFSaveOptions GifSaveOpt;
30 GifSaveOpt.CreateDispatch("Photoshop.GIFSaveOptions");
31 GifSaveOpt.put_Transparency(FALSE);
32 VARIANT SaveOptions, SaveAsCopy, ExtentType;
33 SaveOptions.vt = VT_DISPATCH;
34 SaveOptions.pdispVal = GifSaveOpt.m_lpDispatch;
35 SaveAsCopy.vt = VT_BOOL;
36 SaveAsCopy.boolVal = false;
37 ExtentType.vt = VT_EMPTY;
38 SingleDocument.SaveAs(strFullName, SaveOptions, SaveAsCopy, ExtentType);
39 VARIANT CloseOptions;
40 CloseOptions.vt= VT_EMPTY;
41 SingleDocument.Close(CloseOptions);
42 char buff[256];
43 sprintf_s(buff, 256, "Page: %d / %d", i, m_iEndPage);
44 SetWindowText(buff);
45 }
46 delete pPhotoshopDocuments;
47 pPhotoshopApplication->Quit();
48 delete pPhotoshopApplication;
posted on 2012-03-29 16:21
shaojingliu 阅读(1045)
评论(0) 编辑 收藏 引用