PDFsharp & MigraDoc Forum

PDFsharp - A .NET library for processing PDF & MigraDoc - Creating documents on the fly
It is currently Fri May 16, 2025 5:57 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules

Also see our new Tailored Support & Services site.



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Feb 18, 2025 7:30 am 
Offline

Joined: Fri Aug 09, 2024 5:06 am
Posts: 19
Hi Team,
In one of the file we received when we try get the graphics object we got the Error WidthandHeightCannotbeNegative . Upon analysis the height value calculated from mediabox rectangle is negative. Is there a way to handle this. Why it's coming as negative value. Any hint would be helpful


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 19, 2025 3:12 am 
Offline

Joined: Fri Aug 09, 2024 5:06 am
Posts: 19
not sure if we take the absolute value and assign will make any problem in future. Its working fine when we assign absolute value.


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 20, 2025 9:33 am 
Offline
PDFsharp Guru
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 1044
Location: CCAA
Hi!
hsikkandar wrote:
Upon analysis the height value calculated from mediabox rectangle is negative.
You cannot have -5 Euros in your purse. You cannot cut a page to a height of -5 cm.
IMHO negative values make no sense for width and height. Co-ordinates are a different story.
If you think that PDFsharp handles the MediaBox incorrectly, please use the IssueSubmissionTemplate so we can replicate the issue.

See also:
http://forum.pdfsharp.net/viewtopic.php?f=2&t=832

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 20, 2025 4:06 pm 
Offline

Joined: Fri Aug 09, 2024 5:06 am
Posts: 19
Hi Thomas,
PDFSharp throw the error correctly. The below place in the source the value for height with negative value assigned for the mentioned file
Is it the problem with PDF Generator which generates this particular file?

..\PDFsharp\src\foundation\src\PDFsharp\src\PdfSharp\Pdf\PdfPage.cs
============================================
// Setup page size from MediaBox.
var rectangle = Elements.GetRectangle(InheritablePageKeys.MediaBox, true);
_width = XUnit.FromPoint(rectangle.X2 - rectangle.X1);
_height = XUnit.FromPoint(rectangle.Y2 - rectangle.Y1);

Thanks
Hyder


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

All times are UTC


Who is online

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