losLab Software

Scaling PDF Pages by 70% using losLab PDF Library, in Delphi, C# & VB.Net

Scale PDF pages by 70% through losLab PDF library

When working with PDFs, there are often requirements to scale the content for various purposes. In this scenario, we aim to reduce the size of all pages within a PDF by 70%. This guide walks through the necessary steps, addressing the relevant questions and providing solutions.

Problem Statement

We need to scale down each page of a PDF document by 70% while maintaining the original page order. This requires:

  1. Loading the PDF file.
  2. Capturing and scaling each page.
  3. Saving the scaled pages into a new PDF file.

Steps to Achieve the Goal

  1. Initialize the Environment:
    • Load the original PDF file.
    • Delete any previously existing output file to avoid conflicts.
  2. Set Up the Scaling Parameters:
    • Define the scaling factor (70%).
    • Calculate the borders required to center the scaled content.
  3. Process Each Page in a Loop:
    • Select the first page.
    • Capture the page content.
    • Create a new page with the original dimensions.
    • Draw the captured, scaled content onto the new page.
    • Repeat for all pages.
  4. Save the New PDF and Open it:
    • Save the modified pages into a new PDF file.
    • Automatically open the new PDF to review the results.

Code Implementation

Here is the C# code that performs the above steps:

[crayon-6718323d16d38536962488/]
Explanation and Justification
  • File Deletion: Ensures that any previous output is cleared to prevent errors or outdated content.
  • Scaling Factor: Set to 0.70, this reduces the size of the content to 70% of the original.
  • Border Calculation: Centers the scaled content within the original page dimensions.
  • Page Processing Loop: Iterates through all pages, capturing, scaling, and drawing each one in sequence.
  • File Saving and Opening: Finalizes the new document and opens it for the user to verify the changes.

By following this structured approach, we ensure that each page in the PDF is scaled consistently and maintains its original order, resulting in a professionally processed document.

Delphi edition:

Use Delphi to Scale PDF pages by 70%:
[crayon-6718323d16d41119961722/]

VB.Net edition

Here is the VB.Net code to perform the task:
[crayon-6718323d16d44732923947/]
Both VB.Net and Delphi versions of the code achieve the same result as the original C# code, ensuring that each page in the PDF is scaled down by 70% while maintaining the original order.

©2024 losLab Software Development