using it.stefanochizzolini.clown.documents;
using it.stefanochizzolini.clown.documents.contents.composition;
using it.stefanochizzolini.clown.documents.contents.entities;
using it.stefanochizzolini.clown.documents.contents.fonts;
using it.stefanochizzolini.clown.documents.contents.xObjects;
using it.stefanochizzolini.clown.documents.interaction.actions;
using it.stefanochizzolini.clown.documents.interaction.navigation.document;
using it.stefanochizzolini.clown.files;
using System;
using System.Collections.Generic;
using System.Drawing;
namespace it.stefanochizzolini.clown.samples{
/**
<summary>This sample demonstrates how to apply actions to a document.</summary>
<remarks>In this case, on document opening a go-to-page-2 action is triggered;
then on page 2 opening a go-to-URI action is triggered.</remarks>
*/
public class ActionSample
: ISample
{
#region dynamic
#region interface
#region public
#region ISample
public void Run(
SampleLoader loader
)
{
// (boilerplate user choice -- ignore it)
string filePath = loader.GetPdfFileChoice("Please select a PDF file");
// 1. Open the PDF file!
File file = new File(filePath);
// Get the PDF document!
Document document = file.Document;
// 2. Applying actions...
// 2.1. Local go-to.
{
DocumentActions documentActions = document.Actions;
if(documentActions == null)
{
document.Actions = documentActions = new DocumentActions(document);
document.Update();
}
/*
NOTE: This statement instructs the PDF viewer to go to page 2 on document opening.
*/
documentActions.OnOpen = new GoToLocal(
document,
new LocalDestination(
document.Pages[1],
Destination.ModeEnum.Fit,
null
)
);
documentActions.Update();
}
// 2.2. Remote go-to.
{
Page page = document.Pages[1];
PageActions pageActions = page.Actions;
if(pageActions == null)
{
page.Actions = pageActions = new PageActions(document);
page.Update();
}
try
{
/*
NOTE: This statement instructs the PDF viewer to navigate to the given URI on page 2 opening.
*/
pageActions.OnOpen = new GoToURI(
document,
new Uri("http://www.sourceforge.net/projects/clown")
);
pageActions.Update();
}
catch(Exception exception)
{throw new Exception("Remote goto failed.",exception);}
}
// (boilerplate metadata insertion -- ignore it)
loader.BuildAccessories(document,this.GetType(),"Actions","applying actions");
// 3. Serialize the PDF file (again, boilerplate code -- see the SampleLoader class source code)!
loader.Serialize(file,this.GetType().Name,false);
}
#endregion
#endregion
#endregion
#endregion
}
}
|