
com.pdftools.optimization.profiles.MinimalFileSize Maven / Gradle / Ivy
/****************************************************************************
*
* File: MinimalFileSize.java
*
* Description: PDFTOOLS MinimalFileSize Class
*
* Author: PDF Tools AG
*
* Copyright: Copyright (C) 2023 - 2024 PDF Tools AG, Switzerland
* All rights reserved.
*
* Notice: By downloading and using this artifact, you accept PDF Tools AG's
* [license agreement](https://www.pdf-tools.com/license-agreement/),
* [privacy policy](https://www.pdf-tools.com/privacy-policy/),
* and allow PDF Tools AG to track your usage data.
*
***************************************************************************/
package com.pdftools.optimization.profiles;
import com.pdftools.sys.*;
import com.pdftools.internal.*;
import java.util.EnumSet;
import java.time.OffsetDateTime;
/**
* The optimization profile producing a minimal file size
*
* This profile optimizes the output PDF for minimal file size.
* This is achieved by using a varied palette of image compression
* algorithms, appropriate resolution setting and higher
* compression rates at the price of slightly lower image quality.
*
* The output file size is further reduced by converting Embedded
* Type1 (PostScript) fonts to Type1C (Compact Font Format) and
* removing metadata and output intents
* (see {@link Profile#getRemovalOptions }).
* Also Spider (web capture) information is removed.
*
* Images above 182 DPI are down-sampled and recompressed to 130 DPI.
* This leads to smaller output files. The property
* {@link MinimalFileSize#setResolutionDPI } has influence on both values.
*
* When an image is recompressed, the
* {@link com.pdftools.optimization.CompressionAlgorithmSelection#BALANCED pdftools.optimization.CompressionAlgorithmSelection.BALANCED}
* strategy is used; this can be overridden through the
* property {@link Profile#getImageRecompressionOptions }.
*
* With this profile, the output PDF version is updated to PDF 1.7 or higher and
* PDF/A conformance removed.
*
*/
public class MinimalFileSize extends com.pdftools.optimization.profiles.Profile
{
protected MinimalFileSize(long handle)
{
super(handle);
}
/**
* @hidden
*/
public static MinimalFileSize createDynamicObject(long handle)
{
return new MinimalFileSize(handle);
}
/**
*
*/
public MinimalFileSize()
{
this(newHelper());
}
private static long newHelper()
{
long handle = newNative();
if (handle == 0)
{
switch (getLastErrorCode())
{
case 0: throw new RuntimeException("An unexpected error occurred");
default: throwLastRuntimeException();
}
}
return handle;
}
/**
* The target resolution of images in DPI (Getter)
*
* The target resolution in DPI (dots per inch) for color and grayscale images.
*
* Images with a resolution above {@link MinimalFileSize#getThresholdDPI } are down-sampled.
*
* Valid values are in the range 1.0 to 10000.
*
* If {@code null}, then resolution setting is disabled.
*
* Default: {@code 130}.
*
*/
public Double getResolutionDPI()
{
Double retVal = getResolutionDPINative(getHandle());
if (retVal == null)
{
switch (getLastErrorCode())
{
case 0: break;
default: throwLastRuntimeException();
}
}
return retVal;
}
/**
* The target resolution of images in DPI (Setter)
*
* The target resolution in DPI (dots per inch) for color and grayscale images.
*
* Images with a resolution above {@link MinimalFileSize#getThresholdDPI } are down-sampled.
*
* Valid values are in the range 1.0 to 10000.
*
* If {@code null}, then resolution setting is disabled.
*
* Default: {@code 130}.
*
*
* @throws IllegalArgumentException The given value is outside of range 1.0 to 10000.0.
*/
public void setResolutionDPI(Double value)
{
boolean retVal = setResolutionDPINative(getHandle(), value);
if (!retVal)
{
switch (getLastErrorCode())
{
case 0: throw new RuntimeException("An unexpected error occurred");
case 3: throw new IllegalArgumentException(getLastErrorMessage());
default: throwLastRuntimeException();
}
}
}
/**
* The threshold resolution of images in DPI. (Getter)
*
* The threshold resolution in DPI (dots per inch) to selectively activate downsampling for color and grayscale images.
*
* Valid values are in the range 1.0 to 10000.
* To deactivate down-sampling of images set {@link MinimalFileSize#getResolutionDPI } to {@code null}.
*
* Default: {@code 1.4} times {@link MinimalFileSize#getResolutionDPI }.
*
*/
public double getThresholdDPI()
{
double retVal = getThresholdDPINative(getHandle());
if (retVal == 0)
{
switch (getLastErrorCode())
{
case 0: break;
default: throwLastRuntimeException();
}
}
return retVal;
}
/**
* The threshold resolution of images in DPI. (Setter)
*
* The threshold resolution in DPI (dots per inch) to selectively activate downsampling for color and grayscale images.
*
* Valid values are in the range 1.0 to 10000.
* To deactivate down-sampling of images set {@link MinimalFileSize#getResolutionDPI } to {@code null}.
*
* Default: {@code 1.4} times {@link MinimalFileSize#getResolutionDPI }.
*
*
* @throws IllegalArgumentException The given value is outside of range 1.0 to 10000.0.
*/
public void setThresholdDPI(double value)
{
boolean retVal = setThresholdDPINative(getHandle(), value);
if (!retVal)
{
switch (getLastErrorCode())
{
case 0: throw new RuntimeException("An unexpected error occurred");
case 3: throw new IllegalArgumentException(getLastErrorMessage());
default: throwLastRuntimeException();
}
}
}
private static native long newNative();
private native Double getResolutionDPINative(long handle);
private native boolean setResolutionDPINative(long handle, Double value);
private native double getThresholdDPINative(long handle);
private native boolean setThresholdDPINative(long handle, double value);
}