# User defined java class

**URL:** <https://community.automationedge.com/t/user-defined-java-class/151>\
**Category:** Get Help & Discuss\
**Created:** [February 12, 2018, 6:30am UTC](https://community.automationedge.com/t/user-defined-java-class/151 "2018-02-12T06:30:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ram](https://avatars.discourse-cdn.com/v4/letter/r/b9bd4f/32.png) [@ram](https://community.automationedge.com/u/ram)\
**Post date:** [February 12, 2018, 6:30am UTC](https://community.automationedge.com/t/user-defined-java-class/151/1 "2018-02-12T06:30:16Z")

</div>

How to convert image into pdf format in user defined java class.

---

<div class="post-metadata">

**Author:** ![poonam1996](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@poonam1996](https://community.automationedge.com/u/poonam1996)\
**Post date:** [January 28, 2019, 9:26am UTC](https://community.automationedge.com/t/user-defined-java-class/151/3 "2019-01-28T09:26:41Z")

</div>

Hi Ram,

Please find the below Java code in a user-defined java class.  
You can add respective jars in PS/lib folder. It will work.

import java.io.FileOutputStream;  
import com.itextpdf.text.Document;  
import com.itextpdf.text.pdf.PdfWriter;  
import com.itextpdf.text.Image;

public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws ProcessStudioException {  
if (first) {  
first = false;

```
/* TODO: Your code here. (Using info fields)

FieldHelper infoField = get(Fields.Info, "info_field_name");

RowSet infoStream = findInfoRowSet("info_stream_tag");

Object[] infoRow = null;

int infoRowCount = 0;

// Read all rows from info step before calling getRow() method, which returns first row from any
// input rowset. As rowMeta for info and input steps varies getRow() can lead to errors.
while((infoRow = getRowFrom(infoStream)) != null){

  // do something with info data
  infoRowCount++;
}
*/

```

}

Object[] r = getRow();

if (r == null) {  
setOutputDone();  
return false;  
}

// It is always safest to call createOutputRow() to ensure that your output row’s Object[] is large  
// enough to handle any new fields you are creating in this step.  
r = createOutputRow(r, data.outputRowMeta.size());

/\* TODO: Your code here. (See Sample)

// Get the value from an input field  
String foobar = get(Fields.In, “a\_fieldname”).getString®;

foobar += “bar”;

// Set a value in a new output field  
get(Fields.Out, “output\_fieldname”).setValue(r, foobar);

\*/  
// Send the row on to the next step.

Document document = new Document();  
String input = “C://Users//Admin//Documents//imagetopdf.jpeg”; //  
String output = “C://Users//Admin//Documents//imagetopdf.pdf”;  
try {  
FileOutputStream fos = new FileOutputStream(output);  
PdfWriter writer = PdfWriter.getInstance(document, fos);  
writer.open();  
document.open();  
document.add(Image.getInstance(input));  
document.close();  
writer.close();  
}  
catch (Exception e) {  
e.printStackTrace();  
}

putRow(data.outputRowMeta, r);

return true;  
}
