Matrix_Rotate API

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Stefan - PDF-XChange

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
aleksand
User
Posts: 15
Joined: Tue Apr 24, 2018 6:55 am

Matrix_Rotate API

Post by aleksand »

I need convert PDF page to png with fixed crop. I found example of like code in you examples in CSharp and convert it to c++. I use following following code.
g_MathHelper->Matrix_Scale(&matrix, cx / w, -cy / h, &matrix);
g_MathHelper->Matrix_Translate(&matrix, 0, cy, &matrix);
hr = page->DrawToIXCPage(iPage, &rc, &matrix, param, nullptr, nullptr);
...
CComPtr<PXC::IIXC_Image> img;
hr = g_ImgCore->CreateEmptyImage(&img);
hr = img->InsertPage(iPage, 0);
It is working, but now I need convert rotated page (rotate it and then convert).
I try add following methods but has not good result:
g_MathHelper->Matrix_Rotate(&matrix, rotateView , &matrix);
One of the main problem that I could not find examples and your documentation is very poor (https://sdkhelp.pdf-xchange.com/view/PX ... rix_Rotate). In the description parameter ”nAngle” is ”double” but as I understand The parameter is in degrees, not radians (no any description about it and in most of other library ”double” is radians and ”int” is degrees). I can not find any description or example how to use rotate. The point around which the turn is made is not specified.
Could you please write a code to get a rotated page (90,180 and 270) degrees inscribed in the required dimensions?
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2445
Joined: Thu Jun 30, 2005 4:11 pm

Re: Matrix_Rotate API

Post by Vasyl - PDF-XChange »

Hi Aleksand,

Please try this:

Code: Select all

int calcPageDrawMatrix(IPXC_Page* pPage, IMathHelper* pMH, const RECT& ir, double advRotation, PXC_Matrix& dm)
{
	int iw = ir.right - ir.left;
	int ih = ir.bottom - ir.top;

	PXC_Matrix pm; // page-matrix
	pPage->GetMatrix(PXC_BoxType::PBox_ViewBox, &pm);

	if (advRotation != 0.0) // 90, 180, 270
		pMH->Matrix_Rotate(&pm, advRotation, &pm);

	PXC_Rect pb;
	pPage->get_Box(PXC_BoxType::PBox_ViewBox, &pb); // unrotated page box

	pMH->Rect_Transform(&pm, &pb); // apply page-matrix, with advRotation included

	// visible width/height of page, in pt
	double pw = pb.right - pb.left;
	double ph = pb.top - pb.bottom;

	PXC_Matrix p2sm = {0}; // page to screen matrix
	p2sm.a = (double)iw / pw;
	p2sm.d = -(double)ih / ph;
	p2sm.e = -(double)ir.left;
	p2sm.f = (double)(ih - ir.top);
	
	pMH->Matrix_Multiply(&pm, &p2sm, &dm);
}
Note: to calculate the width/height of 'RECT& ir' properly, you need to calculate the pw/ph as above and then multiply it by your pt2px coefficient. Otherwise, the picture proportions can be distorted...
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
aleksand
User
Posts: 15
Joined: Tue Apr 24, 2018 6:55 am

Re: Matrix_Rotate API

Post by aleksand »

Hi,
Thanks I checked this code but it is working only for angle 0 (or I wrong understand parameters of your function calcPageDrawMatrix. I hope that const RECT& ir is size of output image).
For angle 90 I can found that it need move to w for get correct image (but for some reason, rotating 90 degrees rotates the image counterclockwise and not clockwise as usual). I think for other angle it need move image too, but now I do not find correct value.

For 90 I added following code for correct image:
if ((rotateView) % 90 == 0) {
g_MathHelper->Matrix_Translate(&dm, w, 0, &dm);
}

p.s. Your function should return "int" but has not "return" so I changed "int" to "void".

Thanks,
Evgeny.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 11036
Joined: Wed Jan 03, 2018 6:52 pm

Re: Matrix_Rotate API

Post by Daniel - PDF-XChange »

Hello, aleksand

I have just nudged the Dev team on this topic, they are in final preparations for our next release right now, so there may still be some delay in their response, but I expect Vasyl will probably return to help out again when he has time.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com