Java tutorial
/* * Copyright (C) 2018 FormKiQ Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.formkiq.core.service.conversion; import static com.formkiq.core.form.dto.WorkflowOutputDocumentType.PDF; import static com.formkiq.core.form.dto.WorkflowOutputDocumentType.PNG; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.junit.Test; import com.formkiq.core.util.Resources; /** * Unit Tests for {@link ConversionService}. * */ public class ConversionServiceTest { /** {@link ConversionService}. */ private ConversionService cs = new ConversionService(); /** * sample-form2.pdf to PNG. * @throws IOException IOException */ @Test public void testPdfToPngFormatConverter01() throws IOException { // given byte[] data = Resources.getResourceAsBytes("/sample-form2.pdf"); PDDocument doc = PDDocument.load(data); // when ConversionResult result = this.cs.convert(doc, PDF, PNG); // then doc.close(); final int datalength = 128000; final int dataheight = 1584; final int datawidth = 612; final int x = 211; final int y = 992; assertEquals(1, result.getFields().size()); assertTrue(result.getData().length > datalength); assertEquals(dataheight, (int) result.getDataheight()); assertEquals(datawidth, (int) result.getDatawidth()); assertEquals(x, (int) result.getFields().get(0).getX()); assertEquals(y, (int) result.getFields().get(0).getY()); } }