You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Andrea Vacondio <an...@gmail.com> on 2015/03/04 14:15:42 UTC

Question about PDDocument.setVersion

Hi, about 2.0.0-SNAPSHOT I was setting version on an existing document and
I noticed the version was set on the Catalog but not in the header so I
took a look at the code and I think there's something odd there (or I'm
missing something).
It first makes sure we are not downgrading the version and then we have the
following code (see my comment):

        if (newVersion >= 1.4f)
        {
            getDocumentCatalog().setVersion(Float.toString(newVersion));
//isn't this always false? We already know newVersion is greater...
            if (getDocument().getVersion() > newVersion)
            {
                getDocument().setVersion(newVersion);
            }
        }
        else
        {
            // versions < 1.4f have a version header only
            getDocument().setVersion(newVersion);
        }

I'm not fully sure what's the expected behaviour but I guess it's something
like "if newVer is less then 1.4 then set the header else set both header
and catalog so something like:
if (newVersion >= 1.4f)
        {

getDocumentCatalog().setVersion(Float.toString(newVersion));
        }
            getDocument().setVersion(newVersion);

Am I missing something?

Re: Question about PDDocument.setVersion

Posted by Andrea Vacondio <an...@gmail.com>.
Hi,
yes true, but still there's a dead "if" in the method so it's likely not
behaving as it was intended to.

On Wed, Mar 4, 2015 at 4:36 PM, Maruan Sahyoun <sa...@fileaffairs.de>
wrote:

> Hi,
>
> from PDF 1.4 on the Version entry in the document catalog may override the
> version specified in the header. As a result they could have different
> versions and don't need to be in sync. That's especially useful when doing
> an incremental update as the header can not change as part of that but the
> Version entry in the document catalog can as part of the new increment.
>
> BR
> Maruan
>
> Am 04.03.2015 um 14:15 schrieb Andrea Vacondio <andrea.vacondio@gmail.com
> >:
>
> > Hi, about 2.0.0-SNAPSHOT I was setting version on an existing document
> and
> > I noticed the version was set on the Catalog but not in the header so I
> > took a look at the code and I think there's something odd there (or I'm
> > missing something).
> > It first makes sure we are not downgrading the version and then we have
> the
> > following code (see my comment):
> >
> >        if (newVersion >= 1.4f)
> >        {
> >            getDocumentCatalog().setVersion(Float.toString(newVersion));
> > //isn't this always false? We already know newVersion is greater...
> >            if (getDocument().getVersion() > newVersion)
> >            {
> >                getDocument().setVersion(newVersion);
> >            }
> >        }
> >        else
> >        {
> >            // versions < 1.4f have a version header only
> >            getDocument().setVersion(newVersion);
> >        }
> >
> > I'm not fully sure what's the expected behaviour but I guess it's
> something
> > like "if newVer is less then 1.4 then set the header else set both header
> > and catalog so something like:
> > if (newVersion >= 1.4f)
> >        {
> >
> > getDocumentCatalog().setVersion(Float.toString(newVersion));
> >        }
> >            getDocument().setVersion(newVersion);
> >
> > Am I missing something?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
>

Re: Question about PDDocument.setVersion

Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,

from PDF 1.4 on the Version entry in the document catalog may override the version specified in the header. As a result they could have different versions and don't need to be in sync. That's especially useful when doing an incremental update as the header can not change as part of that but the Version entry in the document catalog can as part of the new increment.

BR
Maruan

Am 04.03.2015 um 14:15 schrieb Andrea Vacondio <an...@gmail.com>:

> Hi, about 2.0.0-SNAPSHOT I was setting version on an existing document and
> I noticed the version was set on the Catalog but not in the header so I
> took a look at the code and I think there's something odd there (or I'm
> missing something).
> It first makes sure we are not downgrading the version and then we have the
> following code (see my comment):
> 
>        if (newVersion >= 1.4f)
>        {
>            getDocumentCatalog().setVersion(Float.toString(newVersion));
> //isn't this always false? We already know newVersion is greater...
>            if (getDocument().getVersion() > newVersion)
>            {
>                getDocument().setVersion(newVersion);
>            }
>        }
>        else
>        {
>            // versions < 1.4f have a version header only
>            getDocument().setVersion(newVersion);
>        }
> 
> I'm not fully sure what's the expected behaviour but I guess it's something
> like "if newVer is less then 1.4 then set the header else set both header
> and catalog so something like:
> if (newVersion >= 1.4f)
>        {
> 
> getDocumentCatalog().setVersion(Float.toString(newVersion));
>        }
>            getDocument().setVersion(newVersion);
> 
> Am I missing something?


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Question about PDDocument.setVersion

Posted by Andreas Lehmkühler <an...@lehmi.de>.
Hi Andrea,

> Andrea Vacondio <an...@gmail.com> hat am 4. März 2015 um 14:15
> geschrieben:
> 
> 
> Hi, about 2.0.0-SNAPSHOT I was setting version on an existing document and
> I noticed the version was set on the Catalog but not in the header so I
> took a look at the code and I think there's something odd there (or I'm
> missing something).
> It first makes sure we are not downgrading the version and then we have the
> following code (see my comment):
> 
>         if (newVersion >= 1.4f)
>         {
>             getDocumentCatalog().setVersion(Float.toString(newVersion));
> //isn't this always false? We already know newVersion is greater...
>             if (getDocument().getVersion() > newVersion)
>             {
>                 getDocument().setVersion(newVersion);
>             }
>         }
>         else
>         {
>             // versions < 1.4f have a version header only
>             getDocument().setVersion(newVersion);
>         }
> 
> I'm not fully sure what's the expected behaviour but I guess it's something
> like "if newVer is less then 1.4 then set the header else set both header
> and catalog so something like:
> if (newVersion >= 1.4f)
>         {
> 
> getDocumentCatalog().setVersion(Float.toString(newVersion));
>         }
>             getDocument().setVersion(newVersion);
> 
> Am I missing something?
You're right there is some room for improvements. I've already reopened the
related ticket PDFBOX-2099

Thanks for the pointer

BR
Andreas Lehmkühler

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org