Forum Discussion

_ivanovich_'s avatar
_ivanovich_
Frequent Contributor
5 years ago

How to write http status code in red or green in a file?

Hi,

I'm trying to generate a pdf file for my report.

I need to display status code in green if it's 200 otherwise in red.

i tried this:

i get status from a project property 

if(status == '200'){
Chunk statuscode = new Chunk ("Status is: "+status, smallBold)
status.setBackground(BaseColor.GREEN)
Paragraph p =  new Paragraph(status)
}else if (status != '200'){
Chunk statuscode = new Chunk ("Status is: "+status, smallBold)
status.setBackground(BaseColor.RED)
Paragraph p =  new Paragraph(status)
}else{
log.info "ERROR"
}

document.add(p)

It creates file with 0k.Cannot open it

 

1 Reply

  • _ivanovich_'s avatar
    _ivanovich_
    Frequent Contributor

    Problem resolved.

    The last line as outside the test.

    I added this 

    document.add(p)

    Now it works:

    It gets the httpcode of my request then writes in pdf file with color chunk red or green depending the status.