PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Rotation of images and string https://forum.pdfsharp.net/viewtopic.php?f=2&t=3557 |
Page 1 of 1 |
Author: | Gagan DS Sohal [ Wed Mar 22, 2017 10:05 am ] |
Post subject: | Rotation of images and string |
I want to add 2 images and 1 string on existing PDF page . in case of normal working it is working fine. Here i want to rotate the text and images by 90 degree which is not working. It may be due to change in Co ordinate change as i rotated the Xgraphics object using rotate. please help me to implement above requirement. Please Help Thank you. |
Author: | Thomas Hoevel [ Wed Mar 22, 2017 10:16 am ] |
Post subject: | Re: Rotation of images and string |
Hi! Maybe the code in this question can help you get started: http://stackoverflow.com/q/42630276/162529 Gagan DS Sohal wrote: Here i want to rotate the text and images by 90 degree which is not working. You don't show what you tried.Maybe there is just a small oversight. |
Author: | Gagan DS Sohal [ Wed Mar 22, 2017 10:34 am ] | |||
Post subject: | Re: Rotation of images and string | |||
Thomas Hoevel wrote: Hi! Maybe the code in this question can help you get started: http://stackoverflow.com/q/42630276/162529 Gagan DS Sohal wrote: Here i want to rotate the text and images by 90 degree which is not working. You don't show what you tried.Maybe there is just a small oversight. string text = "this is dummy text to be printed"; string pathToFile = @"e:\temp\done.pdf"; using (PdfDocument Pdf = PdfReader.Open(@"e:\temp\1617.pdf")) { PdfPage page = Pdf.Pages[0]; double Height = page.Height; double Width = page.Width; float RectX = (float)(20 + 25 + 20 + 10); float RectY = (float)(Height - (20 + 10 + 25)); float RectL = (float)(Width - ((20 * 2) + 25 + 10 + 25 + 10)); float RectH = 35; XImage image = XImage.FromFile(@"e:\temp\Logo.png"); XGraphics gfx = XGraphics.FromPdfPage(page); XPoint objXpoint = new XPoint(50, 50); gfx.DrawImage(image, (int)RectX-35,(int)RectY, 25, 25); XFont font = new XFont("Times New Roman", 10, XFontStyle.Bold); XTextFormatter tf = new XTextFormatter(gfx); RectangleF objrect = new RectangleF(RectX, RectY, RectL, RectH); XRect rect = new XRect(objrect); gfx.DrawRectangle(XBrushes.SeaShell, rect); tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft); gfx.RotateTransform(90); Pdf.Save(pathToFile); } Process.Start(pathToFile); } above code is working fine but i am able to print image and string at right down at page. Now i want that image and text should be added at left side of pdf rotated by -90. by using same co - ordinate
|
Author: | Gagan DS Sohal [ Wed Mar 22, 2017 11:41 am ] |
Post subject: | Re: Rotation of images and string |
Thats how i was able to achieve the functionality. may be not the bast way to use Rotate Transform thrice.. string pathToFile = @"e:\temp\done.pdf"; using (PdfDocument Pdf = PdfReader.Open(@"e:\temp\1617.pdf")) { PdfPage page = Pdf.Pages[0]; double Height = page.Height; double Width = page.Width; float RectX = (float)(20 + 25 + 20 + 10); float RectY = (float)(Height - (20 + 10 + 25)); float RectL = (float)(Width - ((20 * 2) + 25 + 10 + 25 + 10)); float RectH = 35; XImage image = XImage.FromFile(@"e:\temp\Logo1.png"); XGraphics gfx = XGraphics.FromPdfPage(page); XPoint objXpoint = new XPoint(RectX-35, RectY); gfx.RotateAtTransform(-90, objXpoint); gfx.DrawImage(image, (int)RectX-35,(int)RectY, 25, 25); gfx.RotateAtTransform(90, objXpoint); XFont font = new XFont("Times New Roman", 10, XFontStyle.Bold); XTextFormatter tf = new XTextFormatter(gfx); RectangleF objrect = new RectangleF(RectX, RectY, RectL, RectH); XRect rect = new XRect(objrect); objXpoint = new XPoint(RectX, RectY); gfx.RotateAtTransform(-90, objXpoint); tf.DrawString(text, font, XBrushes.Black, rect, XStringFormats.TopLeft); Pdf.Save(pathToFile); |
Author: | Thomas Hoevel [ Wed Mar 22, 2017 12:33 pm ] |
Post subject: | Re: Rotation of images and string |
"gfx.RotateAtTransform" would have been my recommendation. It's better to use "Save()" and "Restore()" to undo a transformation. See also: http://www.pdfsharp.net/wiki/XForms-sample.ashx |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |