On 9/08/2011 16:57, William Bell wrote:
If you would care to read the email you will see that 80%+ is just code - surely someone of your magnificence is not fazed by a little snippet of code? It would take you all of about 1 minute to read it - surely you're not that desperate for money?
For the sake of completeness, I'm attaching the original ("short") question and the answer that was given.
--- Begin Message ---
Good afternoon,

 

I hope you won't be too inconvenienced by me emailing this address directly
rather than the list - you are the only one who has previously been able to
help.  Also, it's quite long - sorry for that.

 

But first let me answer your 2 questions on consultancy and time.  Regarding
consultancy it's a simple case of office politics.  Regarding time, although
it may seem like a long time has been spent on this, the retrieval of
settings is just one part of a larger project and there are a number of
projects.  So much less time has been spent than would appear.

 

That said, we have made progress but are stuck on a number of points...

 

1. Initial View Tab

 

Here, we have managed to confirm all but Magnification and Open to page
settings. To achieve it we used code like...

 

if((reader.SimpleViewerPreferences & PdfWriter.PageModeUseNone) != 0)

{

    appendResultext("Navigation tab", "Page Only");

}

 

and

 

PdfObject obj = reader.GetViewerPreferences.get(PdfName)

if (((PdfBoolean)obj).BooleanValue)

{

    .......

}

 

The above is working fine.  However, we just cannot seem to identify the two
missing settings above (Magnification and Open to page). We have performed
an electronic search of PDF Specification 1.7, iText in Action and the
iTextSharp source code but do not seem to be able to identify the 2
settings.

 

We'd be grateful if you would point us in the right direction and also
perhaps advise if there is a quicker way to find this information out
without having to manual read all 756 pages of the 1.7 PDF specification!

 

 

2. Code to identify dictionaries and entries

 

To try and answer 1 above we have constructed some test code to list out the
dictionaries.  So for example, to list the catalog...

 

Console.WriteLine("Dictionary == reader.Catalog");

PdfDictionary dic = reader.Catalog;

foreach (KeyValuePair<PdfName, PdfObject> kvp in dic)

{

    Console.WriteLine ("Key = {0}, Value = {1}", kvp.key, kvp.value);

}

 

This produces the following output:

 

Dictionary == reader.Catalog

Key = /AcroForm, Value = 4719 0 R

Key = /Metadata, Value = 4714 0 R

Key = /Names, Value = 4720 0 R

Key = /OpenAction, Value = 4915 0 R

Key = /Outlines, Value = 4746 0 R

Key = /PageLayout, Value = /SinglePage

Key = /PageMode, Value = /UseOC

Key = /Pages, Value = 4691 0 R

Key = /Type, Value = /Catalog

Key = /ViewerPreferences, Value = Dictionary

 

 

This is fine but we then wanted to iterate through the various
sub-dictionaries like so:

 

Console.WriteLine("Dictionary == reader.Catalog");

PdfDictionary dic = reader.Catalog;

iterateDictionaries(dic);

...

private void iterateDictionaries (PdfDictionary pdfDictionary)

{

  foreach (KeyValuePair<PdfName, PdfObject> kvp in dic)

  { 

    PdfDictionary d = dic.GetAsDict(kvp.key);

      if (d != null))

      {

        if (d.IsDictionary())

        {

           iterateDictionaries(d);

        }

        else

        {

          Console.WriteLine("Dictionary == " + kvp.key.ToString());

          foreach (KeyValuePair<PdfName, PdfObject> kvp2 in d)

          {

            Console.WriteLine ("Key = {0}, Value = {1}", kvp2.key,
kvp2.value);

          }

....

 

This results in the following output:

 

Dictionary == reader.Catalog

Key = /AcroForm, Value = 4719 0 R

Key = /Fields, Value =
System.Collections.Generic.List`1[iTextSharp.text.pdf.PdfObject]

Key = /DA, Value = /Helv 0 Tf 0 g 

Key = /DR, Value = Dictionary

Key = /Font, Value = Dictionary

Key = /Helv, Value = 2123 0 R

Key = /Subtype, Value = /Type1

Key = /Name, Value = /Helv

Key = /BaseFont, Value = /Helvetica

Key = /Encoding, Value = 2122 0 R

Key = /Differences, Value =
System.Collections.Generic.List`1[iTextSharp.text.pdf.PdfObject]

Key = /Type, Value = /Encoding

Key = /Type, Value = /Font

Key = /ZaDb, Value = 2124 0 R

Key = /Subtype, Value = /Type1

Key = /Name, Value = /ZaDb

Key = /BaseFont, Value = /ZapfDingbats

Key = /Type, Value = /Font

Key = /Encoding, Value = Dictionary

Key = /PDFDocEncoding, Value = 2122 0 R

Key = /Differences, Value =
System.Collections.Generic.List`1[iTextSharp.text.pdf.PdfObject]

Key = /Type, Value = /Encoding

Key = /Metadata, Value = 4714 0 R

Key = /Names, Value = 4720 0 R

Key = /Dests, Value = 2125 0 R

Key = /Kids, Value =
System.Collections.Generic.List`1[iTextSharp.text.pdf.PdfObject]

Key = /JavaScript, Value = 4879 0 R

Key = /OpenAction, Value = 4915 0 R

Key = /D, Value =
System.Collections.Generic.List`1[iTextSharp.text.pdf.PdfObject]

Key = /S, Value = /GoTo

Key = /Outlines, Value = 4746 0 R

Key = /First, Value = 4747 0 R

Key = /Parent, Value = 4746 0 R

Key = /First, Value = 4747 0 R

Key = /Parent, Value = 4746 0 R

Key = /First, Value = 4747 0 R

 

 

This continues repeating the last 2 lines until a stack overflow is
produced!

 

Perhaps you could explain what is going on here and what the code should
look like?

 

Many thanks indeed.

 

Kind regards

William

William Bell

[email protected]

 


--- End Message ---
--- Begin Message ---
On 9/08/2011 16:23, William Bell wrote:

Good afternoon,

I hope you won't be too inconvenienced by me emailing this address directly rather than the list - you are the only one who has previously been able to help. Also, it's quite long - sorry for that.


You knew the rules: http://lowagie.com/rule1
You admit that I'm the only one who has previously been able to help.
Now you deliberately punish me for having helped you in the past by inconveniencing me. When you don't get the answer you expect, you threaten me and you tell other people that our help isn't worth anything. Please explain how all of this makes sense? Why are you threatening the one person who has helped you?

Here, we have managed to confirm all but /Magnification/ and /Open to page/ settings.


Let me remove the code up to the snippet that is interesting:

Key = /OpenAction, Value = 4915 0 R


See table 28 for the meaning of this entry:
OpenAction (array or dictionary): A value specifying a destination that shall be displayed or an action that shall be performed when the document is opened. The value shall be either an array defining a destination (see 12.3.2, "Destinations") or an action dictionary representing an action (12.6, "Actions"). If this entry is absent, the document shall be opened to the top of the first page at the default magnification factor.

If you look at 12.3.2, you see that page and magnification are combined into a "destination". You can also jump to a page using a JavaScript action, but usually actions are defined for other reasons (for instance: to load data from a site into a RichMedia annotation, to set up an object that sets up a communication with an HTML page, to show an alert to the user,...).

we then wanted to iterate through the various sub-dictionaries like so:
(...)

This results in the following output:

(...)

This continues repeating the last 2 lines until a stack overflow is produced!

Perhaps you could explain what is going on here and what the code should look like?

One object (with number 4746) has a reference to a child (/First => object 4747).
This child object has a reference to its parent (4746).

If you write a process that asks the child for its parent, and that parent for its child, and that child for its parent, and that parent for its child,... You create an endless loop.

If you look at how RUPS is written, you'll see that we stop iterating as soon as
we encounter an object that was already "in the loop".

It's a pity you didn't want to answer your phone. I really want to know why in the span of an hour you say that "the only one who has previously been able to help" and "I just hope the person who you turn to for help is rude and as unhelpful as you."
--- End Message ---
------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model 
configuration take the hassle out of deploying and managing Subversion and 
the tools developers use with it. Learn more about uberSVN and get a free 
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
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