PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Dec 26, 2024 4:34 pm

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 Nov 20, 2024 2:18 pm 
Offline

Joined: Fri Aug 09, 2024 5:06 am
Posts: 16
Hi All,
I am trying to draw a string in the center of the page. The below code is working for almost all the file. for the specific file attached its not positioning the graphics object correctly. Its drawing the string somewhere. Any help would be appreciated.

The below is the code snippet:
====================
Code:
  XFont font = new XFont(fontFamilyName, FontSize, XFontStyleEx.Regular); //"Times New Roman" ,22 is fontsize
 PdfDocument doc = PdfReader.Open(sourceFileName, PdfDocumentOpenMode.Modify);
  XBrush brush = new XSolidBrush(XColor.FromArgb(128, 127, 127, 127));  //50%
  foreach (PdfPage page in doc.Pages)
   {
                     using (XGraphics graphics = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append))
                    {
                        double dwPageWidthInPoints = mediabox.Width;
                        double dwpageHeightInPoints = mediabox.Height;

                        // Convert dimensions to inches
                        double dwpageWidthInInches = dwPageWidthInPoints / 72;
                        double dwpageHeightInInches = dwpageHeightInPoints / 72;
                        double centerX = dwPageWidthInPoints / 2;
                        double centerY = dwpageHeightInPoints / 2;
        graphics.DrawString("CONFIDENTIAL",, font, brush, new XPoint(centerX, centerY));
                     }


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 20, 2024 2:31 pm 
Offline

Joined: Fri Aug 09, 2024 5:06 am
Posts: 16
Sorry , i could not able to attach the file here as it is size is >256KB, How to send the file


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 20, 2024 2:42 pm 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 349
hsikkandar wrote:
Sorry , i could not able to attach the file here as it is size is >256KB, How to send the file
See here:
https://docs.pdfsharp.net/General/Issue-Reporting.html

Bear in mind that MediaBox has four members. Your code only uses 2.

You may have to take the clipping box or other boxes into account.

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 20, 2024 3:16 pm 
Offline

Joined: Fri Aug 09, 2024 5:06 am
Posts: 16
Thanks Thomas. I will check the option you mentioned. Regarding the sample file, i have sent the same file to "issues@pdfsharp.net" for the other topics last week(Nov 14, 2024) with the subject "Error in opening file"(Forwarded again today also). It was UTF16-LE file. I will also try to upload the issue submission form.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 21, 2024 8:48 am 
Offline
PDFsharp Expert
User avatar

Joined: Wed Dec 09, 2009 8:59 am
Posts: 349
() => true wrote:
You may have to take the clipping box or other boxes into account.
Take the values of the TrimBox into account.
viewtopic.php?p=14569#p14569

_________________
Öhmesh Volta ("() => true")
PDFsharp Team Holiday Substitute


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: Google [Bot] and 28 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