@Test public void imageWithoutExifMetadata() throws Exception { JpegToPdfParameters parameters = new JpegToPdfParameters(); parameters.addSource(customNonPdfInputAsFileSource("image/no_exif.JPG")); testContext.pdfOutputTo(parameters); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); execute(parameters); testContext.assertTaskCompleted(); }
@Test public void withMargin() throws Exception { JpegToPdfParameters parameters = new JpegToPdfParameters(); parameters.setMarginInches(0.5f); parameters.addSource(customNonPdfInputAsFileSource("image/no_exif.JPG")); testContext.pdfOutputTo(parameters); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); execute(parameters); testContext.assertTaskCompleted(); testContext.forEachPdfOutput(d -> { assertImageAtLocation(d, d.getPage(0), new Point(42, 13), 757, 567); }); }
@Test public void imageWithExifOrientation() throws Exception { JpegToPdfParameters parameters = new JpegToPdfParameters(); parameters.addSource(customNonPdfInputAsFileSource("image/with_exif_orientation.JPG")); testContext.pdfOutputTo(parameters); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); execute(parameters); testContext.assertTaskCompleted(); testContext.forEachPdfOutput(d -> { assertEquals(d.getPage(0).getRotation(), 90); }); }
@Test public void pageOrientationAuto() throws Exception { JpegToPdfParameters parameters = new JpegToPdfParameters(); parameters.addSource(customNonPdfInputAsFileSource("image/no_exif.JPG")); testContext.pdfOutputTo(parameters); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); execute(parameters); testContext.assertTaskCompleted(); testContext.forEachPdfOutput(d -> { assertEquals(d.getPage(0).getMediaBox(), PDRectangle.A4.rotate()); }); }
@Test public void pageOrientationPortrait() throws Exception { JpegToPdfParameters parameters = new JpegToPdfParameters(); parameters.setPageOrientation(PageOrientation.PORTRAIT); parameters.addSource(customNonPdfInputAsFileSource("image/no_exif.JPG")); testContext.pdfOutputTo(parameters); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); execute(parameters); testContext.assertTaskCompleted(); testContext.forEachPdfOutput(d -> { assertEquals(d.getPage(0).getMediaBox(), PDRectangle.A4); }); }
@Test public void pageOrientationLandscape() throws Exception { JpegToPdfParameters parameters = new JpegToPdfParameters(); parameters.setPageOrientation(PageOrientation.LANDSCAPE); parameters.addSource(customNonPdfInputAsFileSource("image/no_exif.JPG")); testContext.pdfOutputTo(parameters); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); execute(parameters); testContext.assertTaskCompleted(); testContext.forEachPdfOutput(d -> { assertEquals(d.getPage(0).getMediaBox(), PDRectangle.A4.rotate()); }); }
@Test public void pageSizeShouldMatchImageSize() throws Exception { JpegToPdfParameters parameters = new JpegToPdfParameters(); parameters.setPageSizeMatchImageSize(true); parameters.addSource(customNonPdfInputAsFileSource("image/draft.tiff")); parameters.addSource(customNonPdfInputAsFileSource("image/no_exif.JPG")); testContext.pdfOutputTo(parameters); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); execute(parameters); testContext.assertTaskCompleted(); testContext.forEachPdfOutput(d -> { PDPage p1 = d.getPage(0); assertEquals(p1.getMediaBox().getWidth(), 248.0, 0.0); assertEquals(p1.getMediaBox().getHeight(), 103.0, 0.0); PDPage p2 = d.getPage(1); assertEquals(p2.getMediaBox().getWidth(), 3264.0, 0.0); assertEquals(p2.getMediaBox().getHeight(), 2448.0, 0.0); }); }
@Test public void specificPageSize() throws Exception { JpegToPdfParameters parameters = new JpegToPdfParameters(); parameters.setPageSize(PageSize.A0); parameters.addSource(customNonPdfInputAsFileSource("image/draft.tiff")); testContext.pdfOutputTo(parameters); parameters.setExistingOutputPolicy(ExistingOutputPolicy.OVERWRITE); execute(parameters); testContext.assertTaskCompleted(); testContext.forEachPdfOutput(d -> { for(PDPage page: d.getPages()){ assertEquals(page.getMediaBox().getWidth(), parameters.getPageSize().getWidth(), 0.0); assertEquals(page.getMediaBox().getHeight(), parameters.getPageSize().getHeight(), 0.0); } }); }