Home Struts Struts Struts2.2.1 How to set pdf background color.

Ask Questions?

View Latest Questions


 
 

How to set pdf background color.
Posted on: February 17, 2011 at 12:00 AM
Advertisement
Here, we are going to introduce you to how to set background of pdf in struts.

How to set pdf background color.

In this example, you will see how to set back ground color of pdf in struts2. 

index.jsp

<html>

<head>

<title>SetBackGround</title>

</head>

<body>

<a href="setbackground.action">SetBackGround</a>

</body>

</html>

AddImageInPDF.java (Action Class)

package roseindia.action;

import java.io.FileOutputStream;

import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;

import com.lowagie.text.Document;

import com.lowagie.text.Paragraph;

import com.lowagie.text.Rectangle;

import com.lowagie.text.pdf.PdfWriter;

import com.opensymphony.xwork2.ActionSupport;

public class SetBaclkGroundNAddTable extends ActionSupport {

public String execute() throws Exception {

Rectangle pageSize = new Rectangle(200, 200);

pageSize.setBackgroundColor(new java.awt.Color(200, 100, 100));

Document document = new Document(pageSize);

ServletContext servletCxt = ServletActionContext.getServletContext();

String path = servletCxt.getRealPath("/");

String filePath = path + "PDFFile";

PdfWriter.getInstance(document, new FileOutputStream(filePath

+ "/BGColorInPDF.pdf"));

document.open();

document.add(new Paragraph("Hello Roseindia..."));

document.close();

return SUCCESS; }

}

struts.xml

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />

<package name="default" namespace="/" extends="struts-default">

<action name="setbackground" class="roseindia.action.SetBaclkGroundNAddTable">

<result>welcomepage/welcome.jsp</result>

</action>

</package>

</struts>

Welcome.jsp

<html>

<head><title>Insert title here</title></head>

<body>

<p>Background of file successfully change...</p>

</body>

</html>

Output

Download Source Code


Related Tags for How to set pdf background color.:


DMCA.com