Java tutorial
/* * Copyright (C) 2017 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.HTML; import static com.formkiq.core.form.dto.WorkflowOutputDocumentType.PDF; import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.text.PDFTextStripper; import com.formkiq.core.form.dto.WorkflowOutputDocumentType; import com.formkiq.core.util.Strings; /** * Converts DOCX to HTML. * */ public class PdfToHtmlFormatConverter implements FormatConverter { @Override public ConversionResult convert(final Object data, final WorkflowOutputDocumentType inputType, final WorkflowOutputDocumentType outputType) throws IOException { PDDocument doc = (PDDocument) data; String s = new PDFTextStripper().getText(doc); return new ConversionResult(Strings.getBytes(s)); } @Override public boolean isSupported(final Object data, final WorkflowOutputDocumentType inputType, final WorkflowOutputDocumentType outputType) { return PDF.equals(inputType) && HTML.equals(outputType) && data instanceof PDDocument; } }