PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index PDFsharp - moved to http://forum.pdfsharp.net/
Please visit the new PDFsharp forum at http://forum.pdfsharp.net/
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

resize pdfpage and center content

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/
View previous topic :: View next topic  
Author Message
tranquillo



Joined: 20 Sep 2007
Posts: 15

PostPosted: Thu Jan 10, 2008 9:48 am    Post subject: resize pdfpage and center content Reply with quote

Hi.

What I want to do:
Increase Width and Height Properites of a PdfPage and keep the original content in the center of the page.
Example: if I increase width and height with 10 points, the original document gets a 5 point margin.

I've tried to simply set new values to the Widht and Height properties, but the added points are added to the top and right side of the page, wich "pushes" the content down to the bottom left corner.
Back to top
View user's profile Send private message
tranquillo



Joined: 20 Sep 2007
Posts: 15

PostPosted: Mon Jan 14, 2008 1:33 pm    Post subject: Reply with quote

I found a solution to the problem, not a good one, but it works...


######################
Adding margins to the document:
######################

using(PdfDocument doc = PdfReader.Open(path))
{

foreach (PdfPage page in doc.Pages)
{

XPoint newLocation = new XPoint(-((printSize.Width - page.Width) / 2), -((printSize.Height - page.Height) / 2));

PdfRectangle newMediaBox = new PdfRectangle(newLocation, new XSize(printSize.Width, printSize.Height));

page.MediaBox = newMediaBox;

}

doc.Save(documentPath);

}


######################################
Then you have to do this to get the x and y back to normal
######################################

double newX = -((page.Width - contentSize.Width)/2);
double newY = (page.Height - contentSize.Height)/2;

xGraphics.TranslateTransform(newX, newY);
Back to top
View user's profile Send private message
tranquillo



Joined: 20 Sep 2007
Posts: 15

PostPosted: Mon Jan 21, 2008 8:24 am    Post subject: Reply with quote

I've got a new problem with this code... could someone pleeaase take a look at it.

the problem is that the code works fine on pdf's generated by pdfsharp. but if I create a pdf with one page in indesign and run it through this method nothing happens... I've stepped through the process and all the values looks right, there is a change in the height and widht properties, but when I open the file there's no change.
Back to top
View user's profile Send private message
tranquillo



Joined: 20 Sep 2007
Posts: 15

PostPosted: Mon Jan 21, 2008 1:09 pm    Post subject: Reply with quote

some new info... pdf's generated from word with "pdf complete" works fine, pdf's created in Photoshop CS2 does not work...

is there some attribute that can be set to "enable" pdfsharp to change the size.
Back to top
View user's profile Send private message
Thomas Hoevel



Joined: 16 Oct 2006
Posts: 387
Location: Cologne, Germany

PostPosted: Mon Jan 21, 2008 1:52 pm    Post subject: Reply with quote

I can't say what's wrong with your approach.

I probably would have used the TwoPagesOnOne sample as a template to create a OnePageWithMarginsOnOne application.
This allows you to draw the old page anywhere on the new page.
_________________
Regards
Thomas Hoevel
PDFsharp Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    PDFsharp - moved to http://forum.pdfsharp.net/ Forum Index -> Support - moved to http://forum.pdfsharp.net/ All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © phpBB Group. Hosted by phpBB.BizHat.com


Start Your Own YouTube Clone

Free Web Hosting | Free Forum Hosting | FlashWebHost.com | Image Hosting | Photo Gallery | FreeMarriage.com

Powered by PhpBBweb.com, setup your forum now!
For Support, visit Forums.BizHat.com