package com.ob.expressions.document; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.Scanner; import javax.imageio.ImageIO; import org.apache.log4j.Logger; import com.appiancorp.services.ServiceContext; import com.appiancorp.suiteapi.common.LocalObject; import com.appiancorp.suiteapi.common.ServiceLocator; import com.appiancorp.suiteapi.common.exceptions.InvalidVersionException; import com.appiancorp.suiteapi.common.exceptions.PrivilegeException; import com.appiancorp.suiteapi.content.ContentConstants; import com.appiancorp.suiteapi.content.ContentService; import com.appiancorp.suiteapi.content.exceptions.InvalidContentException; import com.appiancorp.suiteapi.expression.annotations.Function; import com.appiancorp.suiteapi.expression.annotations.Parameter; import com.appiancorp.suiteapi.knowledge.DocumentDataType; import com.appiancorp.suiteapi.knowledge.DocumentOrFolderDataType; import com.appiancorp.suiteapi.knowledge.FolderDataType; import com.appiancorp.suiteapi.type.AppianType; @AppianDocumentFunctionsCategory public class GetImageFile { private static final Logger LOG = Logger.getLogger(GetImageFile.class); @Function @DocumentDataType public Long ImageWithText(ServiceContext sc, @Parameter String InputText, @Parameter @DocumentDataType Long InputFile, @Parameter @FolderDataType Long FileLoc) { ContentService cs = ServiceLocator.getContentService(sc); BufferedImage image = null; try { /*Scanner scan = new Scanner(System.in); String s = scan.next();*/ String s = InputText; String InputFile1; try { InputFile1 = cs.getInternalFilename(cs.getVersionId(InputFile, ContentConstants.VERSION_CURRENT)); URL url = new URL(InputFile1); image = ImageIO.read(url); /*"http://wwxc75.obwealthworx.com/suite/tempo/Background_Img.jpg"*/ Graphics g = image.getGraphics(); g.setFont(new Font("Calibri", Font.BOLD, 14)); g.setColor(Color.BLACK); g.drawString(s, 8, 20); g.dispose(); ImageIO.write(image, "jpg", new File(FileLoc + s+".jpg")); } catch (PrivilegeException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvalidContentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvalidVersionException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } return (Long) image.UndefinedProperty; } }