Question
RABO Bank
NL
Last activity: 17 Aug 2015 9:51 EDT
How to acheive PDF output from PRPC V6.2 scanning feature?
We are using PRPC V6.2 scanning feature which scans the document and gives us TIF image file and displays using Image Viewer. But we need the file in PDF format which is available in PRPC V6.3 onwards.
Is it possible to convert the TIF to PDF in PEGA using Java or any other methods? Please assist us.
-
Like (0)
Rahul U Tharana Gunawardena -
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Pegasystems Inc.
IN
Hi,
This is not possible to achieve in out of the box way. There is an existing thread which talks about the same requirement. Please take a look : TIFF binary To PDF binary Conversion
RABO Bank
NL
Hi Santanu, I get it we need the external tool to acheive TIFF to PDF conversion. After a lot of research I found iText provides this functionality but I am not aware of how to import external jar into PEGA and use it to convert TIFF to PDF. Can you please help me with the steps of how to do this?
This is my first time working with java classes, libraries and functions. Please guide me in this.
Pegasystems Inc.
CA
iText is shipped with standard Pega distribution. You can reference iText classes using the fully qualified name from within activity Java steps, or add them as imports on the library rule if you want to use these classes in functions.
RABO Bank
NL
Hi Praneeth,
You mean to say I dont have to import iText jar files in PEGA?
Also how do i use the iText classes to acheive this in PEGA.. Currently in 6.2 after scanning we get the TIFF base64 encoded stream in a property and i can save this as an attachment to open the TIFF file. In iText they supply the entire TIFF file to acheive the conversion but from PEGA its stored as stream in DB. Please guide me here.
Pegasystems Inc.
CA
What input does the iText API accept? If it is a byte stream, you can base64 decode the value in the property as bytes and pass the bytes to the iText API. So these bytes constitute "the entire TIFF file” you mentioned.
RABO Bank
NL
Hi Praneeth,
iText accepts a physical location of TIFF file as input like a directory and converts the file to PDF and place it in a directory. I am not sure how to acheive this in PEGA. I do have the tiff base64 stream and need a java code to convert tiff base64 to pdf base64. Till now i couldnt accomplish it with iText. Can you able to give me a solution?
Pegasystems Inc.
CA
Have you looked at examples here: http://thinktibits.blogspot.in/2011/06/convert-tiff-to-pdf-itext-java-example.html and here: http://www.mindfiresolutions.com/How-to-convert-a-TIFF-file-to-pdf-using-iText-library-in-Java-1765.php? If you look at iText javadocs here: http://api.itextpdf.com/itext/, the class RandomAccessFileOrArray, as the name indicates, has overloaded constructors which accept both - file path and byte array. Since you have base64 encoded TIFF content, you can base64 decode it into a byte array and pass the array to the constructor of RandomAccessFileOrArray. Likewise, if all you need is base64 encoded PDF content, you can use PdfWriter.getInstance() with a ByteArrayOutputStream instead of FileOutputStream as given in the examples in the two links above. You can then call ByteArrayOutputStream.toByteArray() and call Base64Util.encodeToString() passing the byte array.
RABO Bank
NL
I could able to write a function based on your suggestions thanks for that. But I receive a nullpointer exception it may be because I am missing something or doing it wrong. Basicallly I am not good in java wrote a code just based on your inputs and able to compile the function correctly in PEGA. Please take a look at my code.
I could able to write a function based on your suggestions thanks for that. But I receive a nullpointer exception it may be because I am missing something or doing it wrong. Basicallly I am not good in java wrote a code just based on your inputs and able to compile the function correctly in PEGA. Please take a look at my code.
try {
//String parameter 'base64decoded' will contain base64 decoded TIFF image string at runtime
byte[] tiffBytes=base64decoded.getBytes();
RandomAccessFileOrArray myTiffFile=new RandomAccessFileOrArray(tiffBytes);
int numberOfPages=TiffImage.getNumberOfPages(myTiffFile);
Document TifftoPDF=new Document();
ByteArrayOutputStream bOutput = new ByteArrayOutputStream();
PdfWriter.getInstance(TifftoPDF, bOutput);
TifftoPDF.open();
//Run a for loop to extract images from Tiff file
//into a Image object and add to PDF recursively
for(int i=1;i<=numberOfPages;i++){
Image tempImage=TiffImage.getTiffImage(myTiffFile, i);
TifftoPDF.add(tempImage);
}
TifftoPDF.close();
byte[] pdfoutputinbytes=bOutput.toByteArray();
String finalPDF=Base64Util.encodeToString(pdfoutputinbytes);
return finalPDF;
}
catch (DocumentException e) {
oLog.error(e);
return "ERROR";
}
Please give your comments.