We are using Spire.Doc 11.1.0 to convert docx files to pdf with the following code:
- Code: Select all
public static void ConvertWordToPdf(string wordFilePath, string pdfFilePath, bool pdfACompliant = false)
{
var document = new Document();
document.LoadFromFile(wordFilePath);
document.UpdateTableOfContents();
if (pdfACompliant)
{
var toPdf = new ToPdfParameterList();
toPdf.PdfConformanceLevel = Spire.Pdf.PdfConformanceLevel.Pdf_A1B;
document.SaveToFile(pdfFilePath, toPdf);
}
else
{
document.SaveToFile(pdfFilePath, FileFormat.PDF);
}
}
The file is about 900 pages long and almost exclusively consists of text. The PDF file that results from above code, is about 18 MB. However, if you open the original file in Word and save it as a PDF with the option optimize for file size, the file is only about 5.6 MB.
I found out, that by opening the file generated by Spire.doc with Spire.pdf, setting the compression level to best and, way more importantly, setting IncrementalUpdate to false, I can reduce the file size to about 11.2 MB.
- Code: Select all
static public void MakePdfSmaller(string pdfFile)
{
var document = new PdfDocument(pdfFile);
document.FileInfo.IncrementalUpdate = false;
document.CompressionLevel = PdfCompressionLevel.Best;
document.SaveToFile(pdfFile + " small.pdf");
document.Close();
}
But that's still twice as large as the file Word produces. Is there a way to reduce the file size further?
Compressing the image doesn't help, that only saves about 20 kB and results in really bad image quality.
I can share the corresponding files, but they are too large to upload here.