PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Dec 12, 2017 6:27 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Mar 22, 2017 10:05 am 
Offline

Joined: Wed Mar 22, 2017 7:55 am
Posts: 3
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.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 22, 2017 10:16 am 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2740
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 22, 2017 10:34 am 
Offline

Joined: Wed Mar 22, 2017 7:55 am
Posts: 3
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


Attachments:
File comment: My actual requirement is this. but when i use Xgraphics.rotate function. the text or image are either not showing or added at wrong co ordinates.
13.png
13.png [ 37.6 KiB | Viewed 812 times ]
File comment: working fine
12.png
12.png [ 27.47 KiB | Viewed 812 times ]
Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 22, 2017 11:41 am 
Offline

Joined: Wed Mar 22, 2017 7:55 am
Posts: 3
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);


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 22, 2017 12:33 pm 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2740
Location: Cologne, Germany
"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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group