Jump to content

Water mark overlaps the Text in PDF


kumarjasper

Recommended Posts

Hi

i am trying to get the waternark on my pdf. But the water mark overlaps the Text on PDF.But i want the water mark to be translucent. i m using the below code to get watermark on PDF.

 

public byte[] addWatermark(byte[] bytes) {

ByteArrayOutputStream bos = new ByteArrayOutputStream();

try {

PdfReader reader = new PdfReader(bytes);

int n = reader.getNumberOfPages();

PdfStamper stamp = new PdfStamper(reader, bos);

int i = 0;

PdfContentByte under;

BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,BaseFont.WINANSI, BaseFont.EMBEDDED);

while (i < n) {

i++;

under = stamp.getUnderContent(i);

under.setGrayFill(0.9f);

under.beginText();

under.setFontAndSize(bf, 40);

under.showTextAligned(PdfContentByte.ALIGN_CENTER, "PREVIEW ONLY",300, 500, 0);

under.endText();

}

stamp.close();

} catch (Throwable de) {

de.printStackTrace();

}

return

 

if anyone knows about how to make watermark transparetn so that the text will be visisble to users.

 

Thanks

Kumar

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Well we don't have the UltimateGuide but I learned a lot whith Trial&Error!:P

 

Well here you go:

open your JRXML in iReport.

go to the band-properties dialog

select the BACKGROUND Band (first band)

set a band height (e.g. half page-height, or even whole page-height --> see report properties (paper size) depends where you want to place your watermark)

put your Text/graphic etc at this band

voilá that's it.B)

[/ol]

 

just try!

 

hth

C-Box

Link to comment
Share on other sites

i tried it but still it overlaps the Text. Here i am attaching the sample picture of it.

 

Here is the code i used it for in the background band.

 

<background>

<band height="731" isSplitAllowed="true">

<rectangle>

<reportElement key="rectangle" positionType="Float" x="0" y="0" width="572" height="731"/>

<graphicElement/>

</rectangle>

<staticText>

<reportElement x="56" y="163" width="452" height="60" mode="Transparent">

<printWhenExpression><![CDATA[new Boolean($F{previewOnly}.equals("PREIVIEW"))]]></printWhenExpression>

</reportElement>

<textElement textAlignment="Center">

<font fontName="Book Antiqua" isBold="false" isItalic="true" size="48"/>

</textElement>

<text><![CDATA[PREVIEW ONLY]]></text>

</staticText>

</band>

</background>

Post edited by: kumarjasper, at: 2006/10/05 19:07

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...