001/* 002 * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Thibaud Arguillere 018 * Miguel Nixo 019 */ 020package org.nuxeo.ecm.platform.pdf.operations; 021 022import org.nuxeo.ecm.automation.core.Constants; 023import org.nuxeo.ecm.automation.core.annotations.Operation; 024import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 025import org.nuxeo.ecm.automation.core.annotations.Param; 026import org.nuxeo.ecm.automation.core.util.BlobList; 027import org.nuxeo.ecm.core.api.DocumentModel; 028import org.nuxeo.ecm.platform.pdf.PDFPageExtractor; 029 030/** 031 * Converts each page of a PDF into a picture. 032 * <p> 033 * Returns Blob list of pictures. 034 * 035 * @since 8.10 036 */ 037@Operation(id = PDFConvertToPicturesOperation.ID, category = Constants.CAT_CONVERSION, 038 label = "PDF: Convert to Pictures", 039 description = "Convert each page of a PDF into a picture. Returns Blob list of pictures.") 040public class PDFConvertToPicturesOperation { 041 042 public static final String ID = "PDF.ConvertToPictures"; 043 044 @Param(name = "fileName", required = false) 045 protected String fileName = ""; 046 047 @Param(name = "xpath", required = false, values = {"file:content"}) 048 protected String xpath = ""; 049 050 @Param(name = "password", required = false) 051 protected String password = null; 052 053 @OperationMethod 054 public BlobList run(DocumentModel inDoc) { 055 PDFPageExtractor pe = new PDFPageExtractor(inDoc, xpath); 056 pe.setPassword(password); 057 return pe.getPagesAsImages(fileName); 058 } 059 060}