Foxit Quick PDF Library

Shrink the content on the page to leave a margin around the edges

Using Foxit Quick PDF Library it is possible to scale down or shrink the content on a page in order to leave a margin on the sides and the top and bottom. This means that you can shrink the content on the page in order to make room for adding new content, such as page size, along the margins of the page.

Here is some C# code that demonstrates how to scale down the content of a page to make room for new content along the margins.

double pageWidth, pageHeight, horizBorder, vertBorder;
double scaleFactor = 0.70;     // 70 % scaling reduction.
int capturedPageId;
int ret;

DPL.LoadFromFile("Pages.pdf");
DPL.SetOrigin(1);

int numPages = DPL.PageCount();
int pageId;

for (int i = 1; i <= numPages; i++)
{
DPL.SelectPage(1);
pageWidth = DPL.PageWidth();
pageHeight = DPL.PageHeight();
horizBorder = pageWidth * (1.0 - scaleFactor) / 2;
vertBorder = pageHeight * (1.0 - scaleFactor) / 2;

capturedPageId = DPL.CapturePage(1); // This deletes the page from the document.

pageId = DPL.NewPage();
DPL.SetPageDimensions(pageWidth, pageHeight);

ret = DPL.DrawCapturedPage(capturedPageId, horizBorder, vertBorder, pageWidth - 2 * 
horizBorder, pageHeight - 2 * vertBorder);
}

DPL.SaveToFile("newpages.pdf");
System.Diagnostics.Process.Start(@"newpages.pdf");

This article refers to a deprecated product. If you are looking for support for Foxit PDF SDK, please click here.

Updated on May 16, 2022

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: