PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 11:47 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
PostPosted: Mon Mar 07, 2016 9:22 am 
Offline

Joined: Mon Mar 07, 2016 8:42 am
Posts: 1
I'll create a watermark diagonal, centered and an other watermark horizontally on each page, but I had some problems on some files.
After some time of debugging I found the error...
I get problems with pages wehre was croped or rotated, so i changed my code as followed:
Code:
XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);
XPoint center = new XPoint(page.Width / 2, page.Height / 2);
if (page.Elements.ContainsKey("/CropBox"))
{
    //consider crop offset
    center = new XPoint(center.X - page.CropBox.X1, center.Y - page.CropBox.Y1);
}
if (page.Rotate != 0)
{
    //consider rotation of the page
    gfx.TranslateTransform(center.X, center.Y);
    gfx.RotateTransform(-page.Rotate);
}

gfx.DrawString("horizontally watermark text", font, brush, bottomRight, XStringFormats.BottomRight);

if (page.Rotate == 0)
     gfx.TranslateTransform(center.X, center.Y);
gfx.RotateTransform(-Math.Atan(page.Rotate == 90 ? page.Width / page.Height : page.Height / page.Width) * 180 / Math.PI);
gfx.TranslateTransform(-center.X, -center.Y);

gfx.DrawString("diagonal watermark text", font, brush, center, XStringFormats.Center);


It works fine, but in one case I found a bug of the library.
If there is a file with one rectangular page, 90° rotated, it gets croped into square.
In the followed code i open a rectangular file (one 90° rotated page) with PDFSharp, save it and get a squared file:
Code:
PdfDocument doc = PdfReader.Open(filepath, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Modify);
doc.Save(filepath);


Maby there is a confusion between X and Y coordinates?
I found also a strange error in the watch of the PdfPage:
Attachment:
error.jpg
error.jpg [ 142.04 KiB | Viewed 6018 times ]


Top
 Profile  
 
PostPosted: Mon Mar 07, 2016 10:17 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
Probably a duplicate entry:
viewtopic.php?f=3&t=3247

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 70 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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group