SampleFiles.zip (190.8 KB)
Aspose Team,
We use the Aspose PDF java package to resize single page PDF files. We found out that the method PdfFileEditor.resizeContentsWithNormalization fails with some PDF files from version 22.4. The error is as follows:
class com.aspose.pdf.internal.ms.System.lv: Specified argument was out of the range of valid values.
Parameter name: Parameter name: index
com.aspose.pdf.internal.ms.System.Collections.Generic.l0t.get_Item(Unknown Source)
com.aspose.pdf.internal.l4if.l0h.lf(Unknown Source)
com.aspose.pdf.operators.SetRGBColor.fromCommand(Unknown Source)
com.aspose.pdf.Operator.(Unknown Source)
com.aspose.pdf.operators.SetColorOperator.(Unknown Source)
com.aspose.pdf.operators.SetRGBColor.(Unknown Source)
com.aspose.pdf.internal.l3f.lc.lI(Unknown Source)
com.aspose.pdf.Operator.lI(Unknown Source)
com.aspose.pdf.DefaultAppearance.lI(Unknown Source)
com.aspose.pdf.DefaultAppearance.(Unknown Source)
com.aspose.pdf.FreeTextAnnotation.getDefaultAppearanceObject(Unknown Source)
com.aspose.pdf.FreeTextAnnotation.lf(Unknown Source)
com.aspose.pdf.Annotation.lI(Unknown Source)
com.aspose.pdf.Annotation.updateAppearances(Unknown Source)
com.aspose.pdf.Annotation.changeAfterResize(Unknown Source)
com.aspose.pdf.facades.APdfFileEditor.resizeContents(Unknown Source)
com.aspose.pdf.facades.PdfFileEditor.resizeContents(Unknown Source)
com.aspose.pdf.facades.APdfFileEditor.resizeContentsWithNormalization(Unknown Source)
com.aspose.pdf.facades.PdfFileEditor.resizeContentsWithNormalization(Unknown Source)
Following is the sample code and attached are the sample files. Note that there are 4 pdf files. Two of them (tmp_6.pdf and tmp_7.pdf) work and the other two (tmp_8.pdf and tmp_9.pdf) fail.
The operating system is Ubuntu 20.04. Java version is 11. Aspose PDF java packages is 22.6.
public class Resize_21 {
public static void main(String[] args) {
Document pdfDocument = null;
try {
String inPath = "path-to-the-sample-file";
float horizontalMargin = 4.25f;
float maxHeightForUpperStamping = 11f;
float maxHeightForBottomStamping = 11f;
PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(
PdfFileEditor.ContentsResizeValue.units(horizontalMargin),
null,
PdfFileEditor.ContentsResizeValue.units(horizontalMargin),
PdfFileEditor.ContentsResizeValue.units(maxHeightForUpperStamping),
null,
PdfFileEditor.ContentsResizeValue.units(maxHeightForBottomStamping)
);
pdfDocument = new Document(inPath);
PdfFileEditor editor = new PdfFileEditor();
editor.resizeContentsWithNormalization(pdfDocument, parameters);
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (pdfDocument != null) {
pdfDocument.close();
}
}
}
}