PDFATest.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. Console.WriteLine("Running PDFA test sample…\r\n");
  16. SDKLicenseHelper.LicenseVerify();
  17. CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
  18. if (!Directory.Exists(outputPath))
  19. {
  20. Directory.CreateDirectory(outputPath);
  21. }
  22. #region PDF/A-1a
  23. if (CovertToPDFA1a(document))
  24. {
  25. Console.WriteLine("Convert to PDF/A-1a done.");
  26. }
  27. else
  28. {
  29. Console.WriteLine("Convert to PDF/A-1a failed.");
  30. }
  31. #endregion
  32. Console.WriteLine("--------------------");
  33. document.Release();
  34. document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
  35. #region PDF/A-1b
  36. if (CovertToPDFA1b(document))
  37. {
  38. Console.WriteLine("Convert to PDF/A-1b done.");
  39. }
  40. else
  41. {
  42. Console.WriteLine("Convert to PDF/A-1b failed.");
  43. }
  44. #endregion
  45. Console.WriteLine("--------------------");
  46. Console.WriteLine("Done!");
  47. Console.WriteLine("--------------------");
  48. Console.ReadLine();
  49. }
  50. static public bool CovertToPDFA1a(CPDFDocument document)
  51. {
  52. string convertToPDFA1aPath = outputPath + "\\ConvertToPDFA1aTest.pdf";
  53. if (!document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1a, convertToPDFA1aPath))
  54. {
  55. return false;
  56. }
  57. Console.WriteLine("Browse the changed file in " + convertToPDFA1aPath);
  58. return true;
  59. }
  60. static public bool CovertToPDFA1b(CPDFDocument document)
  61. {
  62. string convertToPDFA1bPath = outputPath + "\\ConvertToPDFA1bTest.pdf";
  63. if (!document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1b, convertToPDFA1bPath))
  64. {
  65. return false;
  66. }
  67. Console.WriteLine("Browse the changed file in " + convertToPDFA1bPath);
  68. return true;
  69. }
  70. }
  71. }