12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using ComPDFKit.PDFDocument;
- using ComPDFKit.PDFPage;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FlattenTest
- {
- internal class FlattenTest
- {
- static private string outputPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()))) + "\\Output\\Flatten";
- static void Main(string[] args)
- {
- Console.WriteLine("Running Flatten test sample…\r\n");
- SDKLicenseHelper.LicenseVerify();
- CPDFDocument document = CPDFDocument.InitWithFilePath("Annotations.pdf");
- if (!Directory.Exists(outputPath))
- {
- Directory.CreateDirectory(outputPath);
- }
- if (Flatten(document))
- {
- Console.WriteLine("Flatten done.");
- }
- else
- {
- Console.WriteLine("Flatten failed.");
- }
- Console.WriteLine("--------------------");
- Console.WriteLine("Done");
- Console.WriteLine("--------------------");
- Console.ReadLine();
- }
- static private bool Flatten(CPDFDocument document)
- {
- int annotationCount = 0;
- for (int i = 0; i < document.PageCount; i++)
- {
- CPDFPage page = document.PageAtIndex(i);
- annotationCount += page.GetAnnotCount();
- }
- Console.Write("{0} annotations in the file. ", annotationCount);
- string flattenPath = outputPath + "\\FlattenTest.pdf";
- if (document.WriteFlattenToFilePath(flattenPath))
- {
- Console.WriteLine("Browse the changed file in " + flattenPath);
- }
- else
- {
- return false;
- }
- CPDFDocument flattenDocument = CPDFDocument.InitWithFilePath(flattenPath);
- int newCount = 0;
- for (int i = 0; i < flattenDocument.PageCount; i++)
- {
- CPDFPage page = flattenDocument.PageAtIndex(i);
- newCount += page.GetAnnotCount();
- }
- Console.WriteLine("{0} annotations in the new file. ", newCount);
- if (newCount == 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
|