PDFATest.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 PDFATest
  9. {
  10. internal class PDFATest
  11. {
  12. static private string outputPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()))) + "\\Output\\PDFA";
  13. static void Main(string[] args)
  14. {
  15. #region Perparation work
  16. Console.WriteLine("Running PDFA test sample…\r\n");
  17. SDKLicenseHelper.LicenseVerify();
  18. CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
  19. if (!Directory.Exists(outputPath))
  20. {
  21. Directory.CreateDirectory(outputPath);
  22. }
  23. #endregion
  24. #region PDF/A-1a
  25. if (CovertToPDFA1a(document))
  26. {
  27. Console.WriteLine("Convert to PDF/A-1a done.");
  28. }
  29. else
  30. {
  31. Console.WriteLine("Convert to PDF/A-1a failed.");
  32. }
  33. document.Release();
  34. Console.WriteLine("--------------------");
  35. #endregion
  36. #region PDF/A-1b
  37. document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
  38. if (CovertToPDFA1b(document))
  39. {
  40. Console.WriteLine("Convert to PDF/A-1b done.");
  41. }
  42. else
  43. {
  44. Console.WriteLine("Convert to PDF/A-1b failed.");
  45. }
  46. document.Release();
  47. Console.WriteLine("--------------------");
  48. #endregion
  49. Console.WriteLine("Done!");
  50. Console.WriteLine("--------------------");
  51. Console.ReadLine();
  52. }
  53. /// <summary>
  54. /// Save PDF as PDFA1a
  55. /// </summary>
  56. /// <param name="document">Regular document</param>
  57. static public bool CovertToPDFA1a(CPDFDocument document)
  58. {
  59. string convertToPDFA1aPath = outputPath + "\\ConvertToPDFA1aTest.pdf";
  60. if (!document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1a, convertToPDFA1aPath))
  61. {
  62. return false;
  63. }
  64. Console.WriteLine("Browse the changed file in " + convertToPDFA1aPath);
  65. return true;
  66. }
  67. /// <summary>
  68. /// Save PDF as PDFA1b
  69. /// </summary>
  70. /// <param name="document">Regular document</param>
  71. static public bool CovertToPDFA1b(CPDFDocument document)
  72. {
  73. string convertToPDFA1bPath = outputPath + "\\ConvertToPDFA1bTest.pdf";
  74. if (!document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1b, convertToPDFA1bPath))
  75. {
  76. return false;
  77. }
  78. Console.WriteLine("Browse the changed file in " + convertToPDFA1bPath);
  79. return true;
  80. }
  81. }
  82. }