View previous topic :: View next topic |
Author |
Message |
tranquillo
Joined: 20 Sep 2007 Posts: 15
|
Posted: Thu Jan 10, 2008 9:48 am Post subject: resize pdfpage and center content |
|
|
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 |
|
|
tranquillo
Joined: 20 Sep 2007 Posts: 15
|
Posted: Mon Jan 14, 2008 1:33 pm Post subject: |
|
|
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 |
|
|
tranquillo
Joined: 20 Sep 2007 Posts: 15
|
Posted: Mon Jan 21, 2008 8:24 am Post subject: |
|
|
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 |
|
|
tranquillo
Joined: 20 Sep 2007 Posts: 15
|
Posted: Mon Jan 21, 2008 1:09 pm Post subject: |
|
|
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 |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: Mon Jan 21, 2008 1:52 pm Post subject: |
|
|
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 |
|
|
|