001/* 002 * (C) Copyright 2006-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 * Tiry 018 * bstefanescu <bs@nuxeo.com> 019 * Estelle Giuly <egiuly@nuxeo.com> 020 */ 021package org.nuxeo.ecm.automation.core.operations.blob; 022 023import java.io.IOException; 024import org.nuxeo.ecm.automation.core.Constants; 025import org.nuxeo.ecm.automation.core.annotations.Context; 026import org.nuxeo.ecm.automation.core.annotations.Operation; 027import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 028import org.nuxeo.ecm.automation.core.util.BlobList; 029import org.nuxeo.ecm.core.api.Blob; 030import org.nuxeo.ecm.core.api.DocumentModel; 031import org.nuxeo.ecm.core.api.blobholder.BlobHolder; 032import org.nuxeo.ecm.core.convert.api.ConversionService; 033 034/** 035 * Save the input document 036 */ 037@Operation(id = BlobToPDF.ID, category = Constants.CAT_CONVERSION, label = "Convert To PDF", description = "Convert the input file to a PDF and return the new file.") 038public class BlobToPDF { 039 040 public static final String ID = "Blob.ToPDF"; 041 042 @Context 043 protected ConversionService service; 044 045 @OperationMethod 046 public Blob run(DocumentModel doc) throws IOException { 047 BlobHolder bh = doc.getAdapter(BlobHolder.class); 048 if (bh == null) { 049 return null; 050 } 051 return service.convertBlobToPDF(bh.getBlob()); 052 } 053 054 @OperationMethod 055 public Blob run(Blob blob) throws IOException { 056 return service.convertBlobToPDF(blob); 057 } 058 059 @OperationMethod 060 public BlobList run(BlobList blobs) throws IOException { 061 BlobList bl = new BlobList(); 062 for (Blob blob : blobs) { 063 bl.add(this.run(blob)); 064 } 065 return bl; 066 } 067 068}