Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Create PDF file using java servlet

    • 0
    • 3
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 1.33k
    Comment on it

    Here, We are going to create pdf file using servlet in java technology help of darwinsys api.

    Darwinsys api is most important for creating pdf file at runtime in servlet, in which we can set page no., auther, header, footer and page contents etc. according requirement.

    Following pdf api need to use for pdf file creation in servlet.

    http://mvnrepository.com/artifact/com.darwinsys/darwinsys-api/1.0.3

    Below example will help you for batter understanding to create runtime pdf file.

    import java.io.*;  
    import java.util.*;  
    import javax.servlet.*;  
    import javax.servlet.http.*;  
    import com.darwinsys.spdf.PDF;  
    import com.darwinsys.spdf.Page;  
    import com.darwinsys.spdf.Text;  
    import com.darwinsys.spdf.MoveTo;  
    
    public class ServletPDF extends HttpServlet {  
    
    public void doGet(HttpServletRequest request,  
            HttpServletResponse response) throws IOException {  
    
    PrintWriter out = response.getWriter();  
    response.setContentType("application/pdf");  
    
    response.setHeader("Content-disposition","inline; filename='bhagwan.pdf'");  
    
    PDF p = new PDF(out);  
    Page p1 = new Page(p);  
    p1.add(new MoveTo(p, 200, 700));  
    p1.add(new Text(p, "File contents"));  
    
    
    p.add(p1);  
    p.setAuthor("Bhagwan Singh");  
    
    p.writePDF();  
    
    }  
    }   
    

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: