Hi ,

I am reading PDF documents with layers. The PDF I am talking about is created 
with adobe illustrator. All I want to do is read the layers from the
PDF documents and switch the layers on/ off time to time. I know there is a 
function called getPdfLayers() layers which suppose to return a map but

is not working. I tried many other ways to work it out but always got  an error 
like "Exception in thread "main" java.lang.ClassCastException:

com.itextpdf.text.pdf.PRIndirectReference cannot be cast to 
com.itextpdf.text.pdf.PdfDictionary". I tried to find the answer but no didn't 
get any. Here is my code . is there any way I can do the job what I  intended. 
I will really appreciate  the  if there is any work around.


Sincerely
Kabir

//=============================================================================


/*
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
 import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.parser.PdfContentReaderTool;
import java.awt.Color;
 import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Section;
import com.itextpdf.text.Anchor;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfImage;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfName;
import com.itextpdf.text.pdf.PdfNumber;
import java.io.PrintWriter;
*/

import com.itextpdf.text.pdf.PdfStamper;
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.*;
import java.util.Iterator;
import com.itextpdf.text.pdf.PdfLayer;
import java.util.Map;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfDictionary;


import java.lang.String;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfArray;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfLayer;
import com.itextpdf.text.pdf.parser.PdfContentReaderTool;
import java.io.FileNotFoundException;
import java.util.Set;
import java.util.HashMap;
import java.util.HashSet;

import com.itextpdf.text.pdf.PdfWriter;
import java.util.Dictionary;
import java.util.Iterator;
import com.itextpdf.text.pdf.PdfDictionary;
import com.itextpdf.text.pdf.PdfIndirectReference;
import com.itextpdf.text.pdf.PdfName;
import com.itextpdf.text.pdf.PdfSignatureAppearance;
import java.util.Collection;
import java.util.Hashtable;







public class info {

    public static void main(String[] args) throws FileNotFoundException, 
DocumentException,
IOException {



        PdfReader reader = new PdfReader("personalize.pdf");


        if (isWatermarked(reader))
            System.out.println("is marked");
        else
            System.out.println("is not marked");
         reader.close();
    }

    public static boolean isWatermarked(PdfReader reader) throws 
DocumentException, IOException{


 PdfStamper stamper = new PdfStamper (reader, new 
FileOutputStream("myTest2.pdf"));


Map<String, PdfLayer> layers =(Map) stamper.getPdfLayers();   //---> This is 
the line is giving me trouble I think



boolean wm=false;
        if (!layers.isEmpty()) {
            Set<String> keys = layers.keySet();
            for (String key : keys) {
                if(key.toString().equalsIgnoreCase("layout"))
                    wm=true;
                System.out.println("Layer name: " + key);
                //PdfLayer layer = layers.get(key);
                // do stuff with layer...
            }
        }





        stamper.close();
        return wm;


    }






}// end of class







------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to