cancel
Showing results for 
Search instead for 
Did you mean: 

add a logo into a pdf in IFLOW

0 Kudos

Hello Experts,

I need to add company logo into the pdf file, picked up from SFTP.

Could you suggest some groovy script to achieve this please.

regards, Avinash

0 Kudos

7a519509aed84a2c9e6f627841825b5a Could you help me here please!!

Accepted Solutions (0)

Answers (1)

Answers (1)

kuznetsov_in2
Explorer

Hi Avinash,

I used itext5 (or fourth? version) for similar task, it works on CPI environment (JDK8 etc).

Latest itext7 could ask more fresher JDK and it's commercial (some royalti is required).

0 Kudos

Hello Ilya,

thanks for the hint. i will check it.

would you mind sharing code ?

Reg, Avinash

kuznetsov_in2
Explorer

Well, it works with itext7. Your client MUST buy the license for using it!

The PoC is simple and works on CF trial CPI:

The resources with itext7 and custom new logo:

Script:

import com.sap.gateway.ip.core.customdev.util.Message as CpiMsg
import com.itextpdf.kernel.pdf.PdfDocument
import com.itextpdf.kernel.pdf.PdfReader
import com.itextpdf.kernel.pdf.PdfWriter
import com.itextpdf.kernel.utils.PdfMerger

import java.util.zip.ZipInputStream

CpiMsg addCover(CpiMsg msg) {
    ZipInputStream zis = new ZipInputStream(getClass().getResourceAsStream("/lib/hero.jar"))    // zipped new cover
    zis.nextEntry
    PdfDocument cover = new PdfDocument(new PdfReader(zis))
    
    ByteArrayOutputStream dest = new ByteArrayOutputStream()
    PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest))
    PdfDocument input = new PdfDocument(new PdfReader(msg.getBody(InputStream)))

    PdfMerger merger = new PdfMerger(pdfDoc)
    merger.merge(cover, 1, 1)
    merger.merge(input, 1, input.getNumberOfPages())
    cover.close()
    input.close()
    merger.close()
    dest.close()

    msg.headers."content-type" = "application/pdf"
    msg.setBody(dest.toByteArray())
    
    
    return msg
}

Postman: POST https://92022ebbtrial.it-cpitrial03-rt.cfapps.ap21.hana.ondemand.com/http/itext7 with some pages.pdf as input

Expected behaviour: Response is hero.pdf + pages.pdf concatenated into new pdf.

0 Kudos

Hi,

Thanks a lot.

I want to build a poc and show to my client. how did you upload the itext7 file into your iflow, i dont find any document or steps to do it.

can you help here?

Reg, Avinash

0 Kudos

Hi Again,

thanks for the piece of code.

somehow same code is not working from me. i get error as unable to find pdf header.

Reg, Avinash

kuznetsov_in2
Explorer
0 Kudos

Hi Avinash,

all our in-staff telepats are on vacation.