Crop PDF via C++

PDF cropping programmatically using Aspose.PDF for C++ Library

Crop PDF with C++

Do you need to crop PDF? Programmatic modification of PDF documents is an essential part of modern digital workflows. With C++ libraries like Aspose.PDF – are stand-alone solutions that don’t rely on other software and are ready for commercial use. They cover all possible needs of professional C++ developers.

This C++ library enables developers to crop PDF documents quickly and efficiently through programming. With this library, you can easily crop PDF with a number of properties, such as the width, height, bleed-, crop- and trimbox. Aspose.PDF allows you to access these properties. It is a standalone solution for processing PDF documents in C++ that does not require the installation of any third-party software.

In order to to crop PDF file, we’ll use Aspose.PDF for C++ API which is a feature-rich, powerful and easy-to-use document manipulation API for CPP platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

How to Crop PDF via C++


You need Aspose.PDF for C++ to try the code in your environment.

  1. Open a PDF document using Document object.
  2. Choose the type of box and create new Box Rectagle
  3. Save the updated document to the new path using the Save() method.

If you want to crop a PDF page, a cropping solution can help. With this powerful Aspose.PDF C++ library, you can change your PDF while keeping its quality. This professional tool uses C++ to crop PDF effectively. The following example demonstrates how to modify a PDF document in C++:

Crop PDF Files - C++

This sample code shows how to Crop PDF Page - C++

Input file:

File not added

Output format:

Output file:


void CropPagesPDF()
{
    String _dataDir("C:\\Samples\\");
    String inputFileName("crop_page.pdf");
    String outputFileName("crop_page_out.pdf");

    // Open source document
    auto document = MakeObject<Document>(_dataDir + inputFileName);

    Console::WriteLine(document->get_Pages()->idx_get(1)->get_CropBox());
    Console::WriteLine(document->get_Pages()->idx_get(1)->get_TrimBox());
    Console::WriteLine(document->get_Pages()->idx_get(1)->get_ArtBox());
    Console::WriteLine(document->get_Pages()->idx_get(1)->get_BleedBox());
    Console::WriteLine(document->get_Pages()->idx_get(1)->get_MediaBox());

    // Create new Box Rectagle
    auto newBox = MakeObject<Rectangle>(100, 100, 80, 10);
    document->get_Pages()->idx_get(1)->set_CropBox(newBox);
    document->get_Pages()->idx_get(1)->set_TrimBox(newBox);
    document->get_Pages()->idx_get(1)->set_ArtBox (newBox);
    document->get_Pages()->idx_get(1)->set_BleedBox (newBox);

    // Save updated document
    document->Save(_dataDir + outputFileName);
}

About Aspose.PDF for C++ API

Aspose.PDF for C++ is a powerful processing library that enables developers to create, read and manipulate PDF documents without using Adobe Acrobat. It provides a wide range of features such as creating forms, adding/cropping text, manipulating PDF pages, adding annotations, handling custom fonts and much more.

Aspose.PDF for C++ is a library that enables the developers to add PDF processing capabilities to their applications. API can be used to build any type of 32-bit and 64-bit applications to generate or read, convert and manipulate PDF files without the use of Adobe Acrobat.

You can find detailed explanation & examples for every class & method in Aspose.PDF for C++ library in the API reference. And also recommend to view a Documentation.