// For complete examples and data files, please go to https://github.com/groupdocsannotation/GroupDocs_Annotation_NET
class CommonUtilities
{
private const string SourceFolderPath = "../../../../Data/Samples/";
private const string DestinationFolderPath = "../../../../Data/Output/";
private const string LicenseFilePath = "Groupdocs.Annotation.lic";
/// <summary>
/// Maps source file path
/// </summary>
/// <param name="SourceFileName">Source File Name</param>
/// <returns>Returns complete path of source file</returns>
public static string MapSourceFilePath(string SourceFileName)
{
try
{
return SourceFolderPath + SourceFileName;
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
return exp.Message;
}
}
/// <summary>
/// Maps destination file path
/// </summary>
/// <param name="DestinationFileName">Destination File Name</param>
/// <returns>Returns complete path of destination file</returns>
public static string MapDestinationFilePath(string DestinationFileName)
{
try
{
return DestinationFolderPath + DestinationFileName;
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
return exp.Message;
}
}
/// <summary>
/// Saves output document
/// </summary>
public static void SaveOutputDocument(Stream inputFile, List<AnnotationInfo> annotations, DocumentType type)
{
try
{
// Initialize annotator
IAnnotator annotator = new Annotator();
// Export annotations to file stream
Stream result = annotator.ExportAnnotationsToDocument(inputFile, annotations, DocumentType.Pdf);
// Save result stream to file.
using (FileStream fileStream = new FileStream(MapDestinationFilePath("Annotated.pdf"), FileMode.Create))
{
byte[] buffer = new byte[result.Length];
result.Seek(0, SeekOrigin.Begin);
result.Read(buffer, 0, buffer.Length);
fileStream.Write(buffer, 0, buffer.Length);
fileStream.Close();
}
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
}
}
/// <summary>
/// Applies product license
/// </summary>
public static void ApplyLicense()
{
try
{
// initialize License
License lic = new License();
// apply license
lic.SetLicense(LicenseFilePath);
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
}
}
}