PDFATest.cs 2.9 KB

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