PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Mar 28, 2024 8:37 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: Thu Jan 10, 2008 9:48 am 
Offline

Joined: Thu Sep 20, 2007 1:06 pm
Posts: 15
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.


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

Joined: Thu Sep 20, 2007 1:06 pm
Posts: 15
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);


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

Joined: Thu Sep 20, 2007 1:06 pm
Posts: 15
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.


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

Joined: Thu Sep 20, 2007 1:06 pm
Posts: 15
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.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Jan 21, 2008 1:52 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3095
Location: Cologne, Germany
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


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 142 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