c++示例代码如下:
static void test_Render()
{
PDFDoc doc(L"D:/下载/test.pdf");
doc.Load(NULL);
//设置图片的dpi
int dpi_x = 96;
int dpi_y = 96;
PDFPage page = doc.GetPage(0);
page.StartParse(0, NULL, true);
//规范化页面,取消页面旋转和pageBox带来的影响
page.Normalize();
page.StartParse(0, NULL, true);
//设置要截图的区域RectF,这里是右上角1/4的区域
RectF rectf(page.GetWidth() / 2, page.GetHeight() / 2, page.GetWidth(), page.GetHeight());
float pro_x = dpi_x / 72;
float pro_y = dpi_y / 72;
Matrix matrix = page.GetDisplayMatrix(-1 * (rectf.left), -(page.GetHeight() – rectf.top), page.GetWidth()*pro_x, page.GetHeight()*pro_y, e_Rotation0);//page.GetDisplayMatrix(0,0, width, height, page.GetRotation());
rectf.left = rectf.left * pro_x;
rectf.right = (rectf.right * pro_x);
rectf.bottom = (rectf.bottom * pro_y);
rectf.top = rectf.top * pro_y;
Bitmap bitmap((int)rectf.Width(), (int)rectf.Height(), Bitmap::e_DIBArgb);
// Render page
Renderer render(bitmap, false);
//开始渲染
render.StartRender(page, matrix, NULL);
{
Image image;
image.AddFrame(bitmap);
image.SetDPIs(dpi_x, dpi_y);
//保存图片
image.SaveAs(L"D:/下载/test.jpg");
}
return;
}