Hi Guzs,

I have a pdf form, that I can fill out. My only problem is, that I cannot
embed file in it at the end. The pdf is not generated if I try to embed.
I highlighted the problem in the code.
Could you help me out please? Thanks a lot!
Here is the source code:

import com.itextpdf.text.pdf.AcroFields;
import com.itextpdf.text.pdf.PdfName;
import com.itextpdf.text.pdf.PdfFileSpecification;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfStamper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

public class formPdfServlet extends HttpServlet
{

    /** 
     * Processes requests for both HTTP <code>GET</code> and
<code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */

    //get current system date with GetCurrentDate() call
    protected String GetCurrentDate(){
            Calendar cal = new GregorianCalendar();
            int month = cal.get(Calendar.MONTH);
            int year = cal.get(Calendar.YEAR);
            int day = cal.get(Calendar.DAY_OF_MONTH);
            String date = year + "." + (month+1) + "." + day;
            return date;
    }

    protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
            throws ServletException, IOException
    {
        try
        {
            // create simple doc and write to a ByteArrayOutputStream
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            String pdfFile = getServletContext().getRealPath(
"/includes/gaz.pdf" );
            PdfReader reader = new PdfReader(pdfFile);
            PdfStamper stamper = new PdfStamper(reader, baos);

            AcroFields form = stamper.getAcroFields();

            form.setField("kelt", GetCurrentDate());
            form.setField("3", "3");
            form.setField("4", new
String("ÖÜÓŐÚÉÁŰöüóőúéáű".getBytes("8859_2")));
            
            stamper.addFileAttachment("/includes/ips.xml", null);

            stamper.setFormFlattening(true);
            stamper.close();

            // setting some response headers
            response.setHeader("Expires", "0");
            response.setHeader("Cache-Control", "must-revalidate,
post-check=0, pre-check=0");
            response.setHeader("Pragma", "public");
            // setting the content type
            response.setContentType("application/pdf");
            // the contentlength is needed for MSIE!!!
            response.setContentLength(baos.size());
            // write ByteArrayOutputStream to the ServletOutputStream
            ServletOutputStream out = response.getOutputStream();
            baos.writeTo(out);
            out.flush();
        }
        catch (Exception e2)
        {
            System.out.println("Error in " + getClass().getName() + "\n" +
e2);
        }
    }
-- 
View this message in context: 
http://old.nabble.com/embed-XML-in-PDF-tp28395499p28395499.html
Sent from the iText - General mailing list archive at Nabble.com.


------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to