I commented before that I avoided using saveState() and restoreState() to 
implement clipping in my PdfGraphics code because it generated invalid files 
more often than not...now I know partially why.  The following code uses the 
PdfGraphics2D code in iText 0.91 to set a clipping region and draw a circle 
in a template at the bottom of the page; the result displays fine in Acrobat 
Reader 5 and GSview on Windows, and in xpdf and kghostview on Linux, but 
produces "There was an error processing a page. Invalid restore." in Acrobat 
Reader 4 on both platforms.  If the PdfGraphics2D is created directly from 
the base PdfContentByte instead of a template, it works fine even in Acrobat 
4.

Could somebody more enlightened than I about the save/restore functionality 
see if there's a way to avoid this problem?  Or if it's an inherent bug in 
Acrobat 4, at least document this in the FAQ?

Jeremy

----------------------------------------------------

import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import java.awt.Graphics2D;
import java.io.FileOutputStream;

public class ClipTest {

    public static void main(String[] args) {
        try {
            Document doc = new Document(PageSize.A4, 18, 18, 18, 18);
            FileOutputStream os = new FileOutputStream("cliptest.pdf");
            PdfWriter writer = PdfWriter.getInstance(doc, os);
            doc.open();
            PdfContentByte cb = writer.getDirectContent();
            PdfTemplate template = cb.createTemplate(300, 300);
            Graphics2D g2d = template.createGraphics(300, 300);
            g2d.setClip(50, 50, 200, 200);
            g2d.fillOval(30, 30, 220, 220);
            cb.addTemplate(template, 0, 0);
            doc.close();
        }
        catch (Exception e) {
            System.err.println(e.getMessage());
            e.printStackTrace(System.err);
        }
    }
}

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

Reply via email to