mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-23 16:05:09 +00:00

* Add image support to multi-tool page Related to #278 * changes to support image types * final touches * final touches * final touches Signed-off-by: a <a> * final touches Signed-off-by: a <a> * final touches Signed-off-by: a <a> * final touches Signed-off-by: a <a> * final touches Signed-off-by: a <a> * final touches Signed-off-by: a <a> * final touches Signed-off-by: a <a> * Update translation files (#1888) Signed-off-by: GitHub Action <action@github.com> Co-authored-by: GitHub Action <action@github.com> --------- Signed-off-by: a <a> Signed-off-by: GitHub Action <action@github.com> Co-authored-by: a <a> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: GitHub Action <action@github.com>
54 lines
1.8 KiB
Java
54 lines
1.8 KiB
Java
package stirling.software.SPDF.utils;
|
|
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
import org.apache.pdfbox.pdmodel.PDPage;
|
|
import org.apache.pdfbox.pdmodel.PDResources;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.mockito.Mockito;
|
|
import stirling.software.SPDF.model.PdfMetadata;
|
|
|
|
import java.io.IOException;
|
|
import java.util.Collections;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
import org.apache.pdfbox.pdmodel.common.PDRectangle;
|
|
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
|
|
import org.apache.pdfbox.cos.COSName;
|
|
|
|
public class PdfUtilsTest {
|
|
|
|
@Test
|
|
void testTextToPageSize() {
|
|
assertEquals(PDRectangle.A4, PdfUtils.textToPageSize("A4"));
|
|
assertEquals(PDRectangle.LETTER, PdfUtils.textToPageSize("LETTER"));
|
|
assertThrows(IllegalArgumentException.class, () -> PdfUtils.textToPageSize("INVALID"));
|
|
}
|
|
|
|
@Test
|
|
void testHasImagesOnPage() throws IOException {
|
|
// Mock a PDPage and its resources
|
|
PDPage page = Mockito.mock(PDPage.class);
|
|
PDResources resources = Mockito.mock(PDResources.class);
|
|
Mockito.when(page.getResources()).thenReturn(resources);
|
|
|
|
// Case 1: No images in resources
|
|
Mockito.when(resources.getXObjectNames()).thenReturn(Collections.emptySet());
|
|
assertFalse(PdfUtils.hasImagesOnPage(page));
|
|
|
|
// Case 2: Resources with an image
|
|
Set<COSName> xObjectNames = new HashSet<>();
|
|
COSName cosName = Mockito.mock(COSName.class);
|
|
xObjectNames.add(cosName);
|
|
|
|
PDImageXObject imageXObject = Mockito.mock(PDImageXObject.class);
|
|
Mockito.when(resources.getXObjectNames()).thenReturn(xObjectNames);
|
|
Mockito.when(resources.getXObject(cosName)).thenReturn(imageXObject);
|
|
|
|
assertTrue(PdfUtils.hasImagesOnPage(page));
|
|
}
|
|
|
|
|
|
}
|