Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Nov 19, 2024 12:18 pm

Hi,

We are splitting a PDF page by page and combining any selected pages to create a new PDF.
The file size of the merged PDF is large, but we would like to know if there is any way to reduce the file size.

Attached is a two-page PDF as a simple sample.
This was created as a sample, so the content is meaningless.
It is 1MB and the same image is used on multiple pages.
When we split this PDF page by page, the file size of each page is nearly 1MB. (This is not a problem.)
When we merge our split PDF, the file size is about 2MB.

With other PDF merging applications, the size of the merged PDF may be about 1MB.
(e.g. "pdf_as" https://forest.watch.impress.co.jp/libr ... re/pdf_as/
This application seems to use .NET Framework and iText.)

This sample is a simple one, though,
We sometimes use PDFs that have a very large number of pages,
The file size when merged can be very large.
Incidentally, setCompressionLevel(PdfCompressionLevel.Best) did not make it smaller.

We would like to reduce the file size when merging PDFs.

Thank you


Spire.PDF Version: 10.7.3
OS: Windows 11, Amazon Linux 2023
Code: Select all
// split pdf into pages
PdfDocument src = new PdfDocument(Paths.get(baseDirectoryPath, "src.pdf").toString());
PdfPageCollection pages = src.getPages();
int numPages = pages.getCount();
List<Path> pagePathList = new ArrayList<>(numPages);
for (int i = 0; i < numPages; i++) {
    Path tempPagePath = Paths.get(baseDirectoryPath, i + ".pdf");
    src.saveToFile(tempPagePath.toString(), i, i, FileFormat.PDF);
    pagePathList.add(tempPagePath);
}
src.dispose();

// merge pdf
PdfDocument dst = new PdfDocument();
for (Path pagePath : pagePathList) {
    PdfDocument page = new PdfDocument(pagePath.toString());
    dst.appendPage(page);
}
Path dstPdfPath = Paths.get(baseDirectoryPath, "dst.pdf");
dst.saveToFile(dstPdfPath.toString(), FileFormat.PDF);
dst.dispose();

team_ssb
 
Posts: 24
Joined: Fri Nov 26, 2021 1:30 pm

Fri Nov 22, 2024 1:36 am

Hi,

Thank you for bringing this issue to our attention and sorry for the delayed response.
I have tested and reproduced the issue you reported, and have logged it in our bug tracking system with the number SPIREPDF-7212. Our development team will investigate and fix the issue, and we will update you once it has been resolved. Sorry for any inconvenience caused.

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 460
Joined: Mon Nov 07, 2022 8:10 am

Return to Spire.PDF

cron