Compress(PdfCompression,PdfCompressionSettings) Метод (PdfImageResource)
Сжать ресурс изображения.
Parameters
- compression
- Сжатие, которое следует применить к ресурсу изображения.
- compressionSettings
- Настройки сжатия.
Return Value
True, если к ресурсу изображения применяется сжатие; в противном случае - false.
Вот пример, показывающий, как изменить алгоритм сжатия всех черно-белых ресурсов изображений PDF:
''' <summary>
''' Changes compression of all black-white image-resources of PDF document.
''' </summary>
''' <param name="pdfFilename">The filename of PDF document.</param>
Public Shared Sub ChangeCompressionBlackWhiteImages(pdfFilename As String)
' open PDF document
Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
' get collection of image-resources
Dim images As Vintasoft.Imaging.Pdf.Tree.PdfImageResource() = document.GetImages()
' create compression settings
Dim compressionSettings As New Vintasoft.Imaging.Pdf.PdfCompressionSettings()
' for each image-resource
For Each image As Vintasoft.Imaging.Pdf.Tree.PdfImageResource In images
' if image is black-white
If image.PixelFormat = Vintasoft.Imaging.PixelFormat.BlackWhite Then
' change compression of image-resource
image.Compress(Vintasoft.Imaging.Pdf.PdfCompression.CcittFax, compressionSettings)
End If
Next
' save changes to a file
document.SaveChanges()
End Using
End Sub
/// <summary>
/// Changes compression of all black-white image-resources of PDF document.
/// </summary>
/// <param name="pdfFilename">The filename of PDF document.</param>
public static void ChangeCompressionBlackWhiteImages(string pdfFilename)
{
// open PDF document
using (Vintasoft.Imaging.Pdf.PdfDocument document =
new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
{
// get collection of image-resources
Vintasoft.Imaging.Pdf.Tree.PdfImageResource[] images = document.GetImages();
// create compression settings
Vintasoft.Imaging.Pdf.PdfCompressionSettings compressionSettings =
new Vintasoft.Imaging.Pdf.PdfCompressionSettings();
// for each image-resource
foreach (Vintasoft.Imaging.Pdf.Tree.PdfImageResource image in images)
{
// if image is black-white
if (image.PixelFormat == Vintasoft.Imaging.PixelFormat.BlackWhite)
// change compression of image-resource
image.Compress(Vintasoft.Imaging.Pdf.PdfCompression.CcittFax, compressionSettings);
}
// save changes to a file
document.SaveChanges();
}
}
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5