PDFATest.cs 2.5 KB

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