Hello,
here am I again with code snippets for my problem (below the code is the 
description of the problem).

Here is how I open new document:

    public void open() {
        try {
            writer = PdfWriter.getInstance(document, out);
            document.open();
            isOpen = true;
            
            cb = writer.getDirectContent();
            
            try {
                baseFont = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, 
BaseFont.EMBEDDED);
               
                mapper = new DefaultFontMapper();
                mapper.insertDirectory("c:\\Windows\\fonts");
                
                DefaultFontMapper.BaseFontParameters pp = 
mapper.getBaseFontParameters("Arial");
                if (pp != null) pp.encoding = BaseFont.IDENTITY_H;
                
                pp = mapper.getBaseFontParameters("Arial Bold");
                if (pp != null) pp.encoding = BaseFont.IDENTITY_H;
                
                pp = mapper.getBaseFontParameters("Arial Italic");
                if (pp != null) pp.encoding = BaseFont.IDENTITY_H;
            } catch (IOException e1) {
                e1.printStackTrace();
            }
            
            g = cb.createGraphics(pageWidth, pageHeight, mapper);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }

And this is the code for starting new page:
    private void startNewPage() throws Exception {
        try {
            document.newPage();
            
            
            
            pageNumber++;
            pageColumnCounter = 0;
            
            if(hasFooter) {
                drawFooter();
            }
            
            if(hasHeader) {
                drawHeader();
            }
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        
        y = topMargin;
        
        if(titleRowList != null) {
            drawTableTitle();
        }
    }

The old message:
>I'm struggling with this problem for a long time. I have read all 
>resources about this problem, but to no avail.
>
>The one and only area of iText I'm using, is to obtain the graphics 
>context. After that, i do my own drawing and do not depend on the itext 
>components. When there is only one page in the PDF, everything is ok. 
>But, if there are more, I get the Invalid save/restore state exception. 
>I'm aware that the number of PdfContentByte.saveState() and 
>PdfContentByte.restoreState() should be balanced, but the weird thing is 
>that I am not in any case using niether save nor restore. I'm just 
>adding new page to the document, creating the graphics context object, 
>and drawing to it. I do not even have the need to save the current 
>graphic state.

>How can i get around this problem?


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
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