How can I get PDF version number from the header? Also how can I save PDF with a different version number in the header?

Q:

I can see that PDFNet SDK supports all PDF revisions (everything from
PDF 1.0 to 1.7 and Acrobat 8). The problem I've run into is that our
input PDF's were created and maintained using the 1.2 or 1.3 revision
format (to maintain compatability with older Readers), but using
PDFNet to read, modify and save the output results in a 1.4 formatted
file.

How can I get PDF version number from the header? Also how can I save
PDF with a different version number in the header?
---

A:

To obtain PDF header string (i.e. PDF version number) you can use:

// C++
string pdfversion = pdfdoc.GetSDFDoc()->GetHeader();

// C#
String pdfversion = pdfdoc.GetSDFDoc().GetHeader();

GetHeader returns the header string identifying the document version
to which the file conforms. For a file conforming to PDF version 1.4,
the header should be %PDF-1.4. In general header strings have the
following syntax: %AAA-N.n where AAA identifies document specification
(i.e. PDF), N is the major version and n is the minor version. The new
header string can be set during a full save (see SDF::Doc::Save()).
For a document that is not serialized the function returns an empty
string.

To save a document using a different header string using
pdfdoc.GetSDFDoc().Save(...) instead of pdfdoc.Save(...). For example,
to save the file with 'PDF 1.3' in the header use the following code:

pdfdoc.GetRoot().Erase("Version");
pdfdoc.GetSDFDoc().Save("my.pdf", 0, "%PDF-1.3");

Please keep in mind that, the only difference is that the saved
document will have a different header and versioning information (in
document catalog). If the document contains features not available in
the target version, the features will not be discarded. In most cases
Acrobat Reader ignores or gracefully handles features that are not
recognized. So unless you are introducing (i.e. adding) some features
that are not supported in the target version, the document will render
properly.