如何使用iText在jsp中动态地实现图像作为pdf水印?

如何使用iText在jsp中动态地实现图像作为pdf水印?,jsp,netbeans,web-applications,itext,Jsp,Netbeans,Web Applications,Itext,我可以动态地(使用onedpage方法)创建指定的文本作为jsp中pdf的水印,但是如何在“jsp”中建立图像作为水印呢?我希望图像是pdf的水印,使用jsp动态生成。额外信息: *我正在使用netbeans。 *图像存储在web应用程序中名为IMG的文件夹下。 *响应是带有图像水印的PDF 代码: Jsp页面 你试过什么?毕竟,它本质上与文本水印的典型实现相同。在onedpage方法中,水印文本column.showTextAligned()只需要一条语句。但对于图像,我不知道如何执行,也不

我可以动态地(使用onedpage方法)创建指定的文本作为jsp中pdf的水印,但是如何在“jsp”中建立图像作为水印呢?我希望图像是pdf的水印,使用jsp动态生成。额外信息:

*我正在使用netbeans。 *图像存储在web应用程序中名为IMG的文件夹下。 *响应是带有图像水印的PDF

代码:


Jsp页面

你试过什么?毕竟,它本质上与文本水印的典型实现相同。在onedpage方法中,水印文本column.showTextAligned()只需要一条语句。但对于图像,我不知道如何执行,也不知道如何从web应用程序中的文件夹检索图像,网页,至少听起来你已经开始正确的。Sill请提供您的帧代码,以便其他人可以帮助您填写。好的,先生,我会这样做,但如何在堆栈溢出中发布我的编码,通过按add comment和post t code,它是否正确发布我的代码,或者是否以其他方式在您的问题下方发布我的codeClick edit。在那里,您可以编辑您的问题,以可读的格式添加缺少的信息。
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Jsp Page</title>
</head>
    <%
    //'working' text-watermark,

    //generation of text-watermark dynamically,"response.getOutputStream"
    class Watermark extends PdfPageEventHelper
    {     
        private Font font=new Font(Font.FontFamily.HELVETICA,40,Font.BOLD,new GrayColor(0.75f));

        public void onEndPage(PdfWriter writer, Document document)
        {
            ColumnText.showTextAligned(writer.getDirectContentUnder(), Element.ALIGN_CENTER,new Phrase("Airport Authority of India",font),300, 400, 45);    
        }

    }

    //'not working' image-watermark,the coding part where i cannot generate image-watermark        
            //the coding that i tried for the watermark,'image-watermark' which is drawn down as follows,

    ////necessary constituents for the image as per the textual Bruto's\\\\

        /*

        class Watermark extends PdfPageEventHelper
        {

        protected Phrase watermark=new Phrase("watermark");            
        protected PdfTemplate total;
        protected BaseFont helv;
        protected PdfGState gstate;
        protected Image image;

        */

        //      public void onEndPage(PdfWriter writer,Document document)
        {
            //watermark for the image constituents which is as followed, as far as known knowledge of mine;

            /*
            PdfContentByte canvas=writer.getDirectContentUnder();
            Image bg=Image.getInstance("");

            bg.setAbsolutePosition(335,770);
            bg.scaleAbsolute(125,42);
            document.add(bg);

            float w=(document.getPageSize().getWidth())/5;
            float h=(document.getPageSize().getHeight())/5;
            writer.getDirectContentUnder().addImage(bg, w, 0, 0, h, 0, 0);

            */
        }

            /*
            gstate=new PdfGState();
            gstate.setFillOpacity(0.3f);
            gstate.setStrokeOpacity(0.3f);
        }*/

        /*
         My desire is to generate image-watermark with OutputStream as response.getOutputStream:
        ========================================================================================================

        *How to position the watermark image,image-watermark in the center of the pdf..?
        *How to retrieve the image from the following folder, for setting up the Image.getInstance("???")               
            Image Location:   "sertest1(web application in netbeans)->Web Pages->IMG->watermarkimg.jpg".

        *How to dynamically generate image-watermark for jsp,"response.getOutputStream;response.setContentType('application/pdf'))"

        *creation on user-click html button, ... ???

        *in order to generate image-watermark should it be written into the memory ... ???, if yes ,how to do so?? 
        */

%>
<body>
    <%

        response.setContentType("application/pdf");

        //ResultSet rs;
        //PreparedStatement ps; ---> implemented using PreparedStatement
        //Statement st;
        //Class.forName("com.mysql.jdbc.Driver");
        //Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/project","root","password");

        //st=conn.createStatement();
        //rs=st.executeQuery("select * from login l");

        //Document mypdf=new Document(PageSize.A4,108,72,30,72);
        Document mypdf=new Document();

        PdfWriter writer=PdfWriter.getInstance(mypdf,response.getOutputStream());
        writer.setPageEvent(new Watermark());

        mypdf.open();
        mypdf.add(new Paragraph("Maran Manisekar needs help to generate centered image-watermark and thanks in advance"));