AnnotationImportExportTest.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using ComPDFKit.PDFDocument;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace AnnotationImportExportTest
  9. {
  10. internal class AnnotationImportExportTest
  11. {
  12. private static string outputPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()))) + "\\Output\\AnnotationImportExportTest";
  13. private static string tempPath = outputPath + "//temp";
  14. static void Main(string[] args)
  15. {
  16. Console.WriteLine("Running header and footer test sample…\r\n");
  17. SDKLicenseHelper.LicenseVerify();
  18. if (!Directory.Exists(outputPath))
  19. {
  20. Directory.CreateDirectory(outputPath);
  21. }
  22. if (!Directory.Exists(tempPath))
  23. {
  24. Directory.CreateDirectory(tempPath);
  25. }
  26. CPDFDocument annotationsDocument = CPDFDocument.InitWithFilePath("Annotations.pdf");
  27. if (ExportAnnotaiton(annotationsDocument))
  28. {
  29. Console.WriteLine("Export annotaiton done.");
  30. }
  31. else
  32. {
  33. Console.WriteLine("Export annotaiton failed.");
  34. }
  35. Console.WriteLine("--------------------");
  36. CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
  37. if (ImportAnnotaiton(document))
  38. {
  39. Console.WriteLine("Import annotaiton done.");
  40. }
  41. else
  42. {
  43. Console.WriteLine("Import annotaiton failed.");
  44. }
  45. Console.WriteLine("--------------------");
  46. Console.WriteLine("Done");
  47. Console.WriteLine("--------------------");
  48. Console.ReadLine();
  49. }
  50. static private bool ImportAnnotaiton(CPDFDocument document)
  51. {
  52. var path = outputPath + "//ImportAnnotationTest.pdf";
  53. if (!document.ImportAnnotationFromXFDFPath("Annotations.xfdf", tempPath))
  54. {
  55. return false;
  56. }
  57. if (!document.WriteToFilePath(path))
  58. {
  59. return false;
  60. }
  61. Console.WriteLine("Browse the changed file in " + path);
  62. return true;
  63. }
  64. static private bool ExportAnnotaiton(CPDFDocument document)
  65. {
  66. var path = outputPath+ "//ExportAnnotationTest.xfdf";
  67. if (document.ExportAnnotationToXFDFPath(path, tempPath))
  68. {
  69. return false;
  70. }
  71. Console.WriteLine("Xfdf file in " + path);
  72. return true;
  73. }
  74. }
  75. }