public static PdfFormat operator +(PdfFormat p1, PdfFormat p2) { PdfFormat res = new PdfFormat(p1.Formats + p2.Formats, p1.A4 + p2.A4, p1.A3 + p2.A3, p1.A2 + p2.A2, p1.A1 + p2.A1, p1.A0 + p2.A0); return(res); }
public static PdfFormat ProcessFolder(string path, bool flagAllDir) { String[] files; PdfFormat result = new PdfFormat(0, 0, 0, 0, 0, 0); if (flagAllDir) // Get files in child folders { files = Directory.GetFiles(path, "*.pdf", SearchOption.AllDirectories); } else { files = Directory.GetFiles(path, "*.pdf", SearchOption.TopDirectoryOnly); } foreach (String file in files) { result += ProcessFile(file); } return(result); }
public static PdfFormat ProcessFile(string path) // Counting formats in PDF { try { PdfDocument pdfDocument = new PdfDocument(new PdfReader(path)); int n = pdfDocument.GetNumberOfPages(); int Formats = 0, A4 = 0, A3 = 0, A2 = 0, A1 = 0, A0 = 0; for (int i = 1; i <= n; i++) // Cycle through pages { PdfPage pg = pdfDocument.GetPage(i); float pgHeight; float pgWidth; pgHeight = pg.GetCropBox().GetHeight(); pgWidth = pg.GetCropBox().GetWidth(); if (pgHeight < pgWidth) // Rotate page dimensions { float t = pgHeight; pgHeight = pgWidth; pgWidth = t; } int size = (int)Math.Round(pgHeight * pgWidth / 842 / 595 + 0.2F, MidpointRounding.AwayFromZero); // A4 = 842*595 pdf points, 0.2 is constant for scan size variety if (size > 1) { Formats += size; } else { Formats += 1; } if ((pgHeight > 2450) || (pgWidth > 1760)) { A0 += 1; } else if ((pgHeight > 1760) || (pgWidth > 1250)) { A1 += 1; } else if ((pgHeight > 1250) || (pgWidth > 900)) { A2 += 1; } else if ((pgHeight > 900) || (pgWidth > 650)) { A3 += 1; } else { A4 += 1; } } PdfFormat result = new PdfFormat(Formats, A4, A3, A2, A1, A0); return(result); } catch (Exception e) { Logger.LogException(e); return(new PdfFormat(0, 0, 0, 0, 0, 0)); } }