在PDF标准中,“旋转PDF页面中的图形对象”是指默认以PDF页面坐标原点(即PDF页面左下角)为基准的旋转图形对象。
但在实际应用场景中,有些用户会希望以图形对象为中心进行旋转。示例代码如下:
RectF org_rect = graphics_obj.GetRect();
PointF org_centre_point = new PointF();
org_centre_point.x = org_rect.left + org_rect.Width() / 2;
org_centre_point.y = org_rect.bottom + org_rect.Height() / 2;
// Calculate the matrix which is used to transform image object to be rotated with its own centre.
Matrix2D matrix = new Matrix2D();
const float PI = 3.14f;
float radian = PI / 2; // Equals to 90 degrees (in angle).
// Matrix2D::Rotate will do the rotation in counter-clockwise
// and based on the origin point of PDF coordinate — that means the lower-left corner of the page.
matrix.Rotate(radian, false);
// After being rotated, the "centre" point should be moved back to the original centre position for this case.
float temp_x = org_centre_point.x;
float temp_y = org_centre_point.y;
matrix.TransformPoint(ref temp_x, ref temp_y);
matrix.Translate(org_centre_point.x – temp_x, org_centre_point.y – temp_y, false);
graphics_obj.Transform(matrix, false);
// # Related PDF page should generate content
page.GenerateContent();
… // If to render PDF page then, please re-parse PDF page. Please refer to comment of PDFPage::GenerateContent in API reference for more details.