If you pass any PDF object into PdfReader.getObject(...) you can be sure
that the return value is a "direct" object, not a reference.
However, I strongly prefer the getAs* functions for various reasons,
automatic indirect object lookup is just one of them:
PdfDictionary root = reader.getCatalog();
PdfDictionary ocProps = root.getAsDict(PdfName.OCGPROPERTIES);
PdfArray ocgs = ocProps.getAsArray(PdfName.OCGS);
for (int i = 0; i < ocgs.size(); ++i) {
PdfDictionary curOCG = ocgs.getAsDict(i);
System.out.println(curOCG);
}
Compare that to:
PdfDictionary root = reader.getCatalog();
PdfDictionary ocProps = (PdfDictionary)PdfReader.getObject(
root.get(PdfName.OCGPROPERTIES));
PdfArray ocgs =
(PdfArray)PdfReader.getObject(ocProps.get(PdfName.OCGS));
for (int i = 0; i < ocgs.size(); ++i) {
PdfDictionary curOCG =
(PdfDictionary)PdfReader.getObject(ocgs.getPdfObject(i));
System.out.println(curOCG);
}
Type safety, cleaner code, AND you don't have to worry about indirect
references. Good stuff.
--Mark Storer
Senior Software Engineer
Cardiff.com
import legalese.Disclaimer;
Disclaimer<Cardiff> DisCard = null;
> -----Original Message-----
> From: Segev, Eli [mailto:[email protected]]
> Sent: Monday, July 19, 2010 9:09 AM
> To: Post all your questions about iText here
> Subject: Re: [iText-questions] Showing Invisible Layrers
>
> I don't see any PdfReader.getObject( myRef ) in the API. There is
> PdfReader.getObject( PdfObject ), though.
>
> I still have not found any PdfLayer (or PDFOCG) objects in the
catalog.
> There are dictionaries and arrays that do not contain these objects.
>
> -------------------
> Eli Segev
> 781-370-6096
> -----Original Message-----
> From: Mark Storer [mailto:[email protected]]
> Sent: Thursday, July 15, 2010 6:15 PM
> To: Post all your questions about iText here
> Subject: Re: [iText-questions] Showing Invisible Layrers
>
> PRIndirectReference and it's parent, PdfIndirectReference, are
> references to another object. To look up that object, you call
> PdfReader.getObject( myRef ).
>
> THAT object will be of the required type (or at least should be).
>
> You can let dict.getAs* or array.getAt* do the indirect lookups and
type
> checking for you. I sure do.
>
> --Mark Storer
> Senior Software Engineer
> Cardiff.com
>
> import legalese.Disclaimer;
> Disclaimer<Cardiff> DisCard = null;
>
>
> > -----Original Message-----
> > From: Segev, Eli [mailto:[email protected]]
> > Sent: Thursday, July 15, 2010 12:46 PM
> > To: Post all your questions about iText here
> > Subject: Re: [iText-questions] Showing Invisible Layrers
> >
> > I have read section 8.11.2 in the ISO 32000-1 and it says that there
> are
> > 4 entries in optional content group and they are Type, Name, Intent
> and
> > Usage. I see all these entries. Type and Name are fine. But
Intent
> > should be a name array and it is a PRIndirectReference. Usage
should
> be
> > a dictionary, but it is PRIndirectReference. Does anyone understand
> > this?
> >
> > -------------------
> > Eli Segev
> >
> >
> > -----Original Message-----
> > From: Leonard Rosenthol [mailto:[email protected]]
> > Sent: Thursday, July 15, 2010 9:42 AM
> > To: Post all your questions about iText here
> > Subject: Re: [iText-questions] Showing Invisible Layrers
> >
> > Have you read ISO 32000-1? You NEED to read the spec. Doing this
w/o
> > reading and understanding the spec is just trouble!
> >
> > -----Original Message-----
> > From: Segev, Eli [mailto:[email protected]]
> > Sent: Thursday, July 15, 2010 3:23 PM
> > To: Post all your questions about iText here
> > Subject: Re: [iText-questions] Showing Invisible Layrers
> >
> > Mark,
> >
> > Thanks.
> >
> > In the dictionary "OCProperties" I see a dictionary "OCGs" and in
> "OCGs"
> > there is an array, which seems to have 6 dictionaries. There are 6
> > layers in the original PDF. I assume that the 6 dictionary items
are
> > related to the 6 llayers. Each dictionary item has two
> > PRIndirectReference objects, a PdfString and a PdfName. The PdfName
> is
> > 'OCG'. The PdfString holds the name of the layer.
> >
> > My question is how do I get from a PRIndirectReference object to a
> > PDFOCG object?
> > Can I see in the PRIndirectReference object that it is an invisible
> > layer?
> > Is the visibility information in the PdfName object? I don't see
it.
> >
> > -------------------
> > Eli Segev
> >
> > -----Original Message-----
> > From: Mark Storer [mailto:[email protected]]
> > Sent: Wednesday, July 14, 2010 12:26 PM
> > To: Post all your questions about iText here
> > Subject: Re: [iText-questions] Showing Invisible Layrers
> >
> > First of all, let me introduce you to your new best friend, the Pdf
> > Specification:
> >
> > http://www.adobe.com/devnet/acrobat/pdfs/PDF32000_2008.pdf
> >
> > It's an ISO spec, and you normally have to pay for it. However,
Adobe
> > hosts a publicly available copy that is fairly well buried on their
> web
> > site. That's why I keep a copy of the URL handy for folks like
> > yourself.
> >
> > You'll need to learn about the basic PDF object types (name, string,
> > number, boolean, dictionary, array, stream, and indirect reference).
> > It's all in chapter 7.3. Nothing terribly complicated. You don't
> need
> > to know the exact syntax (which the spec goes into at length), iText
> > takes care of that for you. It will be Very Useful however to know
> how
> > to read it, because the spec has quite a few examples listed in that
> > syntax.
> >
> > Then you'll need to know what a layer looks like. The PDF Spec
calls
> > them Optional Content Groups.
> >
> > As it turns out, optional content is stored at the document level.
> >
> > PdfDictionary root = myPdfReader.getCatalog();
> >
> > "Root" and "catalog" are used interchangeably as the term for the
top
> > level object of a PDF, from which all other objects are referenced.
> >
> > The option content information is stored in the OCProperties key of
> the
> > root dictionary:
> >
> > PdfDictionary ocProps = root.getAsDict(new PdfName("OCProperties"));
> >
> > According to 8.11.4.2, that dictionary will have two required keys,
> OCGs
> > and D. OCGs is an array of optional content groups, and D is a
> > dictionary specifying the default OC configuration.
> >
> > I'll leave the rest to you... but feel free to ask more questions if
> you
> > get stuck.
> >
> > --Mark Storer
> > Senior Software Engineer
> > Cardiff.com
> >
> > import legalese.Disclaimer;
> > Disclaimer<Cardiff> DisCard = null;
> >
> >
> > > -----Original Message-----
> > > From: Segev, Eli [mailto:[email protected]]
> > > Sent: Wednesday, July 14, 2010 8:44 AM
> > > To: Post all your questions about iText here
> > > Subject: Re: [iText-questions] Showing Invisible Layrers
> > >
> > >
> > > >The visibility of the layers is defined in the OC groups. This
> > > structure is present in the root
> > > >object of the PDF.
> > > >So you need at least copy that structure to the root of the new
> PDF.
> > > >(And maybe copy some more stuff, but that is a minimum
> requirement.)
> > >
> > > How do you copy the structure of the PDF? Do you use the
PdfReader
> > > object or the PdfImportedObject object?
> > > How do you know that the file being read has invisible layers?
> > >
> > > -------------------
> > > Eli Segev
> > >
> > > -----Original Message-----
> > > From: Segev, Eli [mailto:[email protected]]
> > > Sent: Tuesday, July 13, 2010 4:38 PM
> > > To: Post all your questions about iText here
> > > Subject: [iText-questions] Showing Invisible Layrers
> > >
> > > I use the following code to add PDF images to a PDF page:
> > >
> > > import com.itextpdf.text.*;
> > > import com.itextpdf.text.pdf.*;
> > >
> > > String file = ...
> > > PdfReader reader = new PdfReader(file);
> > > PdfImportedPage page =
> writer.getImportedPage(reader,
> > > 1);
> > > Image img = Image.getInstance(page);
> > >
> > > When I use a particular multi-layer PDF file, the invisible layers
> > > become visible in the result image. Is there any trick to keep
the
> > > invisible layers invisible?
> > >
> > > -------------------
> > > Eli Segev
> > >
> > >
> >
>
------------------------------------------------------------------------
> > > ------
> > > This SF.net email is sponsored by Sprint
> > > What will you do first with EVO, the first 4G phone?
> > > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> > > _______________________________________________
> > > 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/
> > >
> > >
> >
>
------------------------------------------------------------------------
> > > ------
> > > This SF.net email is sponsored by Sprint
> > > What will you do first with EVO, the first 4G phone?
> > > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> > > _______________________________________________
> > > 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/
> > >
> > >
> >
>
------------------------------------------------------------------------
> > --
> > > ----
> > > This SF.net email is sponsored by Sprint
> > > What will you do first with EVO, the first 4G phone?
> > > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> > > _______________________________________________
> > > 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/
> > >
> > >
> > > No virus found in this incoming message.
> > > Checked by AVG - www.avg.com
> > > Version: 9.0.830 / Virus Database: 271.1.1/3003 - Release Date:
> > 07/13/10
> > > 11:36:00
> >
> >
>
------------------------------------------------------------------------
> > ------
> > This SF.net email is sponsored by Sprint
> > What will you do first with EVO, the first 4G phone?
> > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> > _______________________________________________
> > 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/
> >
> >
>
------------------------------------------------------------------------
> > ------
> > This SF.net email is sponsored by Sprint
> > What will you do first with EVO, the first 4G phone?
> > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> > _______________________________________________
> > 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/
> >
> >
>
------------------------------------------------------------------------
> > ------
> > This SF.net email is sponsored by Sprint
> > What will you do first with EVO, the first 4G phone?
> > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> > _______________________________________________
> > 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/
> >
> >
>
------------------------------------------------------------------------
> --
> > ----
> > This SF.net email is sponsored by Sprint
> > What will you do first with EVO, the first 4G phone?
> > Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> > _______________________________________________
> > 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/
>
>
>
------------------------------------------------------------------------
> ------
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> _______________________________________________
> 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/
>
>
------------------------------------------------------------------------
--
> ----
> This SF.net email is sponsored by Sprint
> What will you do first with EVO, the first 4G phone?
> Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
> _______________________________________________
> 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/
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
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/