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();