diff --git a/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/README.md b/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/README.md index 6ef8507e..ac2d94c4 100644 --- a/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/README.md +++ b/Compression/Compress-the-existing-PDF-document/.NET/Compress-the-existing-PDF-document/README.md @@ -20,34 +20,38 @@ Step 3: **Add required namespaces**: Include the following namespaces in your `P Step 4: **Implement PDF compression**: Use the following code snippet in `Program.cs` to compress PDF files: ```csharp - // Open a file stream to read the input PDF file. - using (FileStream fileStream = new FileStream(Input.pdf", FileMode.Open, FileAccess.Read)) - { - // Create a new PdfLoadedDocument object from the file stream. - using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream)) - { - // Create a new PdfCompressionOptions object. - PdfCompressionOptions options = new PdfCompressionOptions(); - - //Enable the compress image. - options.CompressImages = true; - - //Set the image quality. - options.ImageQuality = 50; - - // Compress the PDF document. - loadedDocument.Compress(options); - - //Create file stream. - using (FileStream outputFileStream = new FileStream("Output/Output.pdf", FileMode.Create, FileAccess.ReadWrite)) - { - //Save the PDF document to file stream. - loadedDocument.Save(outputFileStream); - } - //Close the document. - loadedDocument.Close(true); - } - } + // Open a file stream to read the input PDF file + using (FileStream fileStream = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read)) + { + // Load the PDF document from the file stream + using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream)) + { + // Create a new PdfCompressionOptions object + PdfCompressionOptions options = new PdfCompressionOptions(); + + // Enable image compression and set the image quality + options.CompressImages = true; + options.ImageQuality = 50; + + // Enable font optimization + options.OptimizeFont = true; + + // Enable page content optimization + options.OptimizePageContents = true; + + // Remove metadata from the PDF + options.RemoveMetadata = true; + + // Compress the PDF document + loadedDocument.Compress(options); + + // Save the document into a memory stream + using (MemoryStream outputStream = new MemoryStream()) + { + loadedDocument.Save(outputStream); + } + } + } ``` You can download a complete working sample from the [GitHub repository](https://github.com/SyncfusionExamples/PDF-Examples/tree/master/Compression/Compress-the-existing-PDF-document). diff --git a/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Data/Output.pdf b/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Data/Output.pdf index 731be86e..806b5b41 100644 Binary files a/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Data/Output.pdf and b/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Data/Output.pdf differ diff --git a/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Data/file1.pdf b/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Data/file1.pdf index 6d10bb53..319bea3b 100644 Binary files a/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Data/file1.pdf and b/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Data/file1.pdf differ diff --git a/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Data/file2.pdf b/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Data/file2.pdf index da082542..a032f24c 100644 Binary files a/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Data/file2.pdf and b/Merge PDFs/Merge-multiple-documents-from-stream/.NET/Merge-multiple-documents-from-stream/Data/file2.pdf differ