PDF Viewer Preferences

Manipulate PDF
11/2/2011

Downloads

The following code sample shows how to set the viewer preferences of a PDF document.

C# code sample

1 using (FileStream inFile = new FileStream(@"..\..\..\inputDocuments\PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read)) 2 { 3 // open the source document 4 Document document = new Document(inFile); 5 6 // remove the current security settings 7 document.Security = null; 8 9 // assign a new ViewerPreferences object to document 10 document.ViewerPreferences = new ViewerPreferences(); 11 12 // set viewer preferences 13 document.ViewerPreferences.CenterWindow = true; 14 document.ViewerPreferences.DisplayDocTitle = true; 15 16 // hide UI elements in the viewer application 17 document.ViewerPreferences.HideMenubar = true; 18 document.ViewerPreferences.HideToolbar = true; 19 document.ViewerPreferences.HideWindowUI = true; 20 21 // show pages in two columns 22 document.ViewerPreferences.PageLayout = PageLayout.TwoColumnLeft; 23 24 // do not show the thumbnails or the bookmark tree 25 document.ViewerPreferences.PageMode = PageMode.None; 26 27 // write the modified document back to disk 28 using (FileStream outFile = new FileStream(@"..\..\viewerpreferences.pdf", FileMode.Create, FileAccess.Write)) 29 { 30 document.Write(outFile); 31 } 32 }

VB.NET code sample

1 Using inFile As New FileStream("..\..\..\inputDocuments\PackingLightBrochure.pdf", FileMode.Open, FileAccess.Read) 2 ' open the source document 3 Dim document As New Document(inFile) 4 5 ' remove the current security settings 6 document.Security = Nothing 7 8 ' assign a new ViewerPreferences object to document 9 document.ViewerPreferences = New TallComponents.PDF.Navigation.ViewerPreferences() 10 11 ' set viewer preferences 12 document.ViewerPreferences.CenterWindow = True 13 document.ViewerPreferences.DisplayDocTitle = True 14 15 ' hide UI elements in the viewer application 16 document.ViewerPreferences.HideMenubar = True 17 document.ViewerPreferences.HideToolbar = True 18 document.ViewerPreferences.HideWindowUI = True 19 20 ' show pages in two columns 21 document.ViewerPreferences.PageLayout = PageLayout.TwoColumnLeft 22 23 ' do not show the thumbnails or the bookmark tree 24 document.ViewerPreferences.PageMode = PageMode.None 25 26 ' write the modified document back to disk 27 Using outFile As New FileStream("..\..\viewerpreferences.pdf", FileMode.Create, FileAccess.Write) 28 document.Write(outFile) 29 End Using 30 End Using