PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

Center an Image on Page
http://forum.pdfsharp.de/viewtopic.php?f=2&t=374
Page 1 of 1

Author:  polygonwindow [ Mon Apr 21, 2008 7:32 am ]
Post subject:  Center an Image on Page

Hello Everybody,

I'm having trouble centering a loaded jpg-file (72dpi) on the DIN A4 page. I mean i could calculate its position but there's the issue with page size in Point s or millimeters and Image size in pixels. Is there a way to put it in a Table or similar and center it vertically and horizontally?

Another thing: am I just a bit dumb or isn't there really a doumentaion/reference on pdfsharp? i checked all the links like sourceforge, pdfsharp.org and the wiki.

Thx for any hints.

Cheers,
Poly

Author:  Thomas Hoevel [ Mon Apr 21, 2008 8:04 am ]
Post subject: 

Hello, Poly,

Calculating the image position should be no problem since XUnit can do all the conversions.
This also allows you to resize images (make 'em smaller, maybe even make 'em larger).

Documentation is a weak point. But the samples give you an idea how PDFsharp works in general, and Intellisence will show you the available methods.

Author:  polygonwindow [ Mon Apr 21, 2008 8:45 am ]
Post subject: 

Hello Thomas,

Thanks a lot for the quick reply. I thought XUnit could be the way but didn't know it can handle pixels as well, i'll give it a try.

A nice reference would be really nice, the only thing i'm missing - but i can imagine how much work that is.

By the way: You guys are doing a really great job on PDFsharp - it's a really cool piece of software and works really nice and fast so far.

Thanks,
poly

Author:  polygonwindow [ Mon Apr 21, 2008 4:28 pm ]
Post subject: 

Hello again,

sorry, i can't figure out how i can get the pixel-to-point-conversion using XUnit.

Can someone give me a hint?

XUnit has only .fromCentimeter .fromMillimeter .fromInch .fromPoint

Thanks for any help,
Poly

Author:  Thomas Hoevel [ Tue Apr 22, 2008 7:52 am ]
Post subject: 

Hello!
polygonwindow wrote:
sorry, i can't figure out how i can get the pixel-to-point-conversion using XUnit.

Sorry, my mistake (will be included in PDFsharp 1.1).

Here's how to get it done with PDFsharp 1.0:
Quote:
XImage img = XImage.FromFile(filename);
Unit height = Unit.FromInch(img.PixelHeight / img.VerticalResolution);
Unit width = Unit.FromInch(img.PixelWidth / img.HorizontalResolution);

Author:  polygonwindow [ Tue Apr 22, 2008 12:15 pm ]
Post subject: 

Ahh super! this will work..

Thanks a lot for the help.

Poly

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/