你好,我使用如下代码将pdf文件的第一页转换成png图片,有如下两个问题:
1,只转换了一页,生成的速度很慢,大概要5到6秒,有没有办法改善生成的速度呢?(最好在1秒以内可以生成好)
2,有没有可以生成透明背景png图片的方法呢?
代码如下(只需要测试nPreViewPage=0的情况):
int GetPdfBkImage(int nPreViewPage, const TCHAR* pImageFile, int nWidth, int nHeight)
{
int nRet = PREVIEW_INIT_FAIL;
// 已经打开的文件句柄
if (m_docutment == nullptr)
{
return nRet;
}
// 待保存png文件的路径
if (pImageFile == nullptr)
{
return nRet;
}
std::wstring strTempFilePath = pImageFile;
System::String inputFilePath(strTempFilePath.c_str(), strTempFilePath.length());
if (nPreViewPage < m_docutment->get_Pages()->get_Count())
{
// 生成图片
System::SharedPtr<Aspose::Pdf::Devices::ImageDevice> pImageDevice = nullptr;
auto resolution = MakeObject<Aspose::Pdf::Devices::Resolution>(150);
pImageDevice = new Aspose::Pdf::Devices::PngDevice(nWidth, nHeight, resolution);
System::String strSavePath(pImageFile);
System::SharedPtr <System::IO::FileStream> imageStream = new System::IO::FileStream(strSavePath, System::IO::FileMode::Create);
std::clock_t start;
std::clock_t end;
start = clock();
pImageDevice->Process(m_docutment->get_Pages()->idx_get(nPreViewPage + 1), imageStream);
end = clock();
double endtime = (double)(end - start) / CLOCKS_PER_SEC;
std::string strLog;
strLog.append("背景渲染图片耗时:").append(std::to_string(endtime));
OutputDebugStringA(strLog.c_str());
}
return nRet;
}
测试使用的pdf文件:234.7z (7.1 KB)