PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Nov 11, 2024 7:37 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sat Sep 28, 2024 8:43 pm 
Offline

Joined: Sat Sep 28, 2024 8:28 pm
Posts: 2
I have a PDF document that has pages from different sources. When iterating through the pages and outputting the page height and width, they are all portrait dimensions. However, some are being displayed landscape.

When outputting the rotation of the pages, the ones being displayed in portrait have no rotation, the ones displayed as landscape have a 90 degree rotation.

I am trying to draw a rectangular overlay of white at the bottom of the page to overwrite existing page numbers, then draw new pages numbers on top of the overlay.

This is working fine for the pages with no rotation value.

The pages with rotation value this is not working.

Messing around with RotateAtTransform I have been able to get the overlay and page numbers to appear on the page (it seems to be off page most of the time), but no matter what values I have tried, I cannot for the life of me get the overlay to appear at bottom of the page, and the text centered horizontally and vertically within the overlay.

Can anyone offer some working c# .net code that will work?


Top
 Profile  
Reply with quote  
PostPosted: Sat Sep 28, 2024 10:33 pm 
Offline

Joined: Sat Sep 28, 2024 8:28 pm
Posts: 2
No idea why this works, but this is seemingly working...

Basically set the transform to be at point 0, for the width I used height instead, and used a negative pageHeight value for the X coordinate.

Code:
 if (isLandscape)
            {
                bottomMargin = 10;
                overlayHeight = 38;
                overlayWidth = pageHeight;
                overlayX = -pageHeight;
                overlayY = pageWidth - overlayHeight - bottomMargin;
                textX = (overlayX - textSize.Width) / 2;
                textY = overlayY + (overlayHeight - textSize.Height) / 2;

                XRect rectOverlay = new XRect(overlayX, overlayY, overlayWidth, overlayHeight);

                gfx.Save();
                gfx.RotateAtTransform(-90, new XPoint(0, 0));
                gfx.DrawRectangle(XBrushes.White, rectOverlay);
                gfx.DrawString(text, font, XBrushes.Black, new XPoint(textX, textY));
                gfx.Restore();
            }


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 59 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