void png2pdf(){
::CoInitialize(NULL);
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
std::vector<std::wstring> vec;
vec.push_back(L"aa");
vec.push_back(L"bb");
std::wstring sPath = L"C:\\Users\\qinxw\\Desktop\\png\\";
std::wstring sDst = L"C:\\Users\\qinxw\\Desktop\\11\\";
for (auto it : vec)
{
std::wstring filename = sPath + it + L".png";
std::wstring sSave = sDst + it + L".pdf";
Gdiplus::Bitmap* bitmap = Gdiplus::Bitmap::FromFile(filename.c_str());
DEVMODE dm;
ZeroMemory(&dm, sizeof(DEVMODE));
dm.dmSize = sizeof(DEVMODE);
dm.dmFields = DM_PAPERSIZE | DM_ORIENTATION;
dm.dmPaperSize = DMPAPER_A4_TRANSVERSE;
dm.dmOrientation = DMORIENT_LANDSCAPE;
dm.dmPrintQuality = DMRES_HIGH;
DOCINFO di;
ZeroMemory(&di, sizeof(DOCINFO));
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = L"My PDF Document";
di.lpszOutput = sSave.c_str();
HDC hdc = CreateDC(NULL, L"Microsoft Print to PDF", NULL, &dm);
StartDoc(hdc, &di);
StartPage(hdc);
Gdiplus::Graphics graphics(hdc);
graphics.DrawImage(bitmap, 0, 0);
EndPage(hdc);
EndDoc(hdc);
DeleteDC(hdc);
delete bitmap;
}
::CoUninitialize();
Gdiplus::GdiplusShutdown(gdiplusToken);
}
通过调用Microsoft Print to PDF 把png 打印成pdf
最新推荐文章于 2024-07-02 22:25:52 发布