Introduction
Every PDF document can have a
handful of information regarding its author, title, summary, associated
keywords and so on. All these records are stored in so-called Document Information Dictionary described
in section 14.3.3 Document Information
Dictionary of the PDF specification. It’s possible to alter this
information in order to provide the document with descriptive metadata suitable
for further automated analysis and identification. E.g. a search engine may
quickly analyze the Keywords set
instead of indexing the complete document. These predefined “fields” are
standardized, and can be used for various purposes by all applications in
addition to custom document form fields.
Besides setting document’s Author
or Title, you can also set its default appearance when it becomes opened in a
conforming PDF reader. E.g. indicate full-screen mode or whether the toolbars
should be visible. See the section 12.2 Viewer
Preferences for details. It’s
worth mentioning that some readers don’t respect these settings, so don’t be
surprised
The Apitron PDF Kit .NET component
provides an easy access to document’s information, and its API can be used to
change or add it when needed. See the code samples in the corresponding
sections showing how to work with document information and set viewer
preferences.
Setting PDF document information
This operation is easy and simple, see the code below:
public void SetDocumentInfomation()
{
// open
document
using (Stream stream = File.Open("document.pdf", FileMode.Open))
{
//
create document object
FixedDocument doc = new FixedDocument(stream);
// set
document information
doc.Author = "Apitron";
doc.Title = "Sample document";
doc.Subject = "Apitron PDF Kit API usage sample";
doc.Keywords = "document information,c# sample,apitron pdf
kit";
// save
as incremental update
doc.Save();
}
}
If you open this document in
Adobe Reader, you’ll be able to see its new properties (click on File ->
Properties and select Description tab)
Pic. 1 Setting document properties
|
Setting PDF viewer preferences
The code below shows how to change viewer preferences:
public void SetPDFViewerPrerences()
{
// open
document
using (Stream stream = File.Open("document.pdf", FileMode.Open))
{
//
create document object
FixedDocument doc = new FixedDocument(stream);
// set
viewer and page preferences
doc.ViewerPreferences.HideToolbar = true;
doc.ViewerPreferences.DisplayDocTitle =
true;
doc.PageMode = PageMode.FullScreen;
doc.PageLayout = PageLayout.SinglePage;
// save
as incremental update
doc.Save();
}
}
When you run this sample and open
the changed document in Acrobat Reader, it may warn you that document tries to
go to full screen mode. It’s normal, and you can proceed and allow or disallow this
behavior. It will also take into account the other settings, so there will be
no toolbar visible and so on.
Conclusion
When it comes to setting the PDF
information and viewer settings, you may rely on Apitron PDF Kit .NET component,
it does its job flawlessly. If you are interested in more complex PDF
manipulation scenarios, you can read our other posts or the free book
which contains lots of useful information and ready to use samples. If you have
questions regarding the API or PDF manipulation, contact us and our support
will be happy to help you.
Downloadable version of this article can be found by the following link [PDF].
Downloadable version of this article can be found by the following link [PDF].
No comments:
Post a Comment