Resize PDF document

You can change the document size by automatically scaling the content on its pages. You can scale the entire document or specific pages. There are three available methods:

  • bool PdfFileEditor.ResizeContents(string source, string destination, int[] pages, ContentsResizeParameters parameters)
  • void PdfFileEditor.ResizeContents(Document source, int[] pages, ContentsResizeParameters parameters)
  • void PdfFileEditor.ResizeContents(Document source, ContentsResizeParameters parameters)

Options Class Description

The resize parameters are defined by the options class — PdfFileEditor.ContentsResizeParameters.

Purpose

  • Configure margins around the content, target content dimensions, and page dimensions.
  • Support for both absolute units and percentages.
  • Optionally adjust the MediaBox to match the CropBox during resizing.

Main Entities

ContentsResizeParameters

A parameter container.

  • Properties:

    • ChangeMediaBox: when enabled, the MediaBox is adjusted to the current CropBox during resizing.
    • LeftMargin, RightMargin, TopMargin, BottomMargin: margins around the content (absolute or percentage).
    • ContentsWidth, ContentsHeight: target content area size (absolute or percentage).
  • Static configuration methods (create a new ContentsResizeParameters object):

    • Margins(left, right, top, bottom): margins in absolute page units.
    • MarginsPercent(left, right, top, bottom): margins in percentages.
    • ContentSize(width, height): target content size in absolute units.
    • ContentSizePercent(width, height): target content size in percentages.
    • PageResize(width, height): change page size in absolute units.
    • PageResizePct(widthPct, heightPct): change page size in percentages.

You can create a ContentsResizeParameters object using any of the static methods above and then additionally adjust its fields.

ContentsResizeValue

A universal container for a numeric parameter.

  • Value types:

    • Absolute (Units)
    • Percentage (Percents)
    • Automatic (Auto)
  • Key fields/flags:

    • Value: the numeric value.
    • IsPercent: indicates percentage interpretation; if false — absolute value.
  • Factory methods:

    • Units(value): create an absolute value.
    • Percents(value): create a percentage value.
    • Auto(): mark the value for automatic calculation.

Usage Recommendations

  • When margins around the content are important — use Margins or MarginsPercent.
  • When you need the content to match specific dimensions — use ContentSize or ContentSizePercent.
  • When you need to change the page size itself — use PageResize or PageResizePct.
  • You can combine absolute and percentage values.
  • Enable ChangeMediaBox if you need to align page geometry: the MediaBox will be set to the current CropBox.
  • Mark parameters as Auto when you want to delegate the calculation to the algorithm.

Examples

Example of resizing a page

Increase page margins by 10% on all sides:

Set content size to 500 x 700 in page units and leave margins as auto:

Scale page by 120% width and 110% height:

Notes

  • Percentages are interpreted relative to the corresponding original size.
  • Absolute values are specified in page units (e.g., points).
  • When margins and target content size are set together, the final values are calculated considering all constraints; unspecified parameters may be computed automatically.