- Home
- Forum
- ASP.NET Core - EJ 2
- I have a question regarding the rotation of PdfImage
I have a question regarding the rotation of PdfImage
I'm trying to use DrawImage in the PDF library,
and when I use the rotation function in the code below,
the rotation location does not appear in x, y coordinates.
Please look at the code below and let me know how to solve this problem.
PdfDocument pdoc = new PdfDocument();
...
PdfPage page = pdoc.Pages.Add();
PdfPageLayer lay = page.Layers.Add();
PdfImage pimg = PdfImage.FromFile(@"D:\test.jpg");
lay.Graphics.TranslateTransform(pimg.Width / 2, pimg.Height / 2);
lay.Graphics.RotateTransform(-27);
lay.Graphics.DrawImage(pimg, x, y, pimg.Width, pimg.Height); // x, y are Image File Location Coordinates
// -- end
// used Library DLL (Version : 18.3400.0.35)
Syncfusion.Compression.Base.dll
Syncfusion.Pdf.Base.dll
SIGN IN To post a reply.
5 Replies
GK
Gowthamraj Kumar
Syncfusion Team
January 5, 2021 03:59 PM UTC
Hi sweetbook,
Thank you for contacting Syncfusion products.
We have the checked the reported image position issue with the provided code and we can able to reproduce the issue. Actually this is not an issue in PDF library, it can be resolved in sample level. We need to mention the location in translatetransform(location.x,location.y) and the angle in rotatetransform(angle) and there is no need to mention the location in DrawImage(). We can just set the 0,0 as location and draw the image.
Please refer below code snippet to resolve that issue.
|
PdfDocument pdoc = new PdfDocument();
PdfPage page = pdoc.Pages.Add();
PdfPageLayer lay = page.Layers.Add();
PdfImage pimg = PdfImage.FromFile("logo.jpg");
//Translate the coordinate system’s to where you want draw the text position
lay.Graphics.TranslateTransform(100,100);
//Rotate the coordinate system’s
lay.Graphics.RotateTransform(-27);
//set 0,0 as location to draw the image in rotated position
lay.Graphics.DrawImage(pimg,0,0,pimg.Width,pimg.Height);
pdoc.Save("output.pdf");
pdoc.Close();
|
Please let us know if you need any further assistance with this.
Regards,
Gowthamraj K
SW
sweetbook
January 6, 2021 04:54 AM UTC
Hello, I checked the comments.
Attachment: ImageToPDFSample_4d81cefe.zip
I tested it before using the method you told me,
but I couldn't figure out the cause.
So, I downloaded the sample code source from the link below and tested it by modifying it a little bit.
https://www.syncfusion.com/kb/11635/how-to-rotate-an-image-around-its-center-in-pdf-document-using-c
(The modified code is attached as a zip.)
When you run a built app,
a PDF is created in the bin\Debug folder with result.pdf.
The first page of the result.pdf created is the page before the Rotate operation.
Page 2 is the page after the Rotate operation.
The image position is rapidly changing, and in this case, how do I change the code?
I'd like you to let me know in detail.
Attachment: ImageToPDFSample_4d81cefe.zip
GK
Gowthamraj Kumar
Syncfusion Team
January 7, 2021 11:36 AM UTC
Hi sweetbook,
As we said earlier, we need to mention the location of the image in translatetransform(location.x,location.y) and the angle in rotatetransform(angle). We have modified the provided sample with proper translateTransform(), now its added properly. Kindly please try the below sample in your end and let us know the result.
Please let us know if you need any further assistance with this.
Regards,
Gowthamraj K
SW
sweetbook
January 8, 2021 02:04 AM UTC
Thank you for your comments and Source Code.
Attachment: result_be3a9674.zip
As I checked, it appears that the PdfPageLayer is rotating while keeping the size of the PdfPage.
What I want to do is to run Rotate on the center of the image on the first page,
based on the blue circle.
I'm sorry for asking so many questions.
It's because this problem is a challenge for us.
Attachment: result_be3a9674.zip
GK
Gowthamraj Kumar
Syncfusion Team
January 8, 2021 02:44 PM UTC
Hi Sweetbook,
Thank you for your update.
We have modified the sample for achieving your requirement in our end and please find the modified sample from below link,
Please let us know if you need further assistance on this.
Regards,
Gowthamraj K
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
SW sweetbook
- Jan 5, 2021 12:45 AM UTC
- Jan 8, 2021 02:44 PM UTC