protected string GetAreasText(string directory, PdfAreaType areaType, string fileMask) { var watch = System.Diagnostics.Stopwatch.StartNew(); string[] fileNames = System.IO.Directory.GetFiles(directory, searchPattern: string.IsNullOrEmpty(fileMask) ? @"*.pdf" : fileMask); double sumArea = 0.0; StringBuilder builder = new StringBuilder(); foreach (string fileName in fileNames) { double fileArea = PdfAreaCalcCommon.PdfAreaCalc.GetFileAreaM2(fileName, areaType); sumArea += fileArea; builder.Append(string.Format("{0}: File: {1},\t Area: {2:0.00} m2\r\n", areaType.ToString(), fileName.Replace(directory + @"\", ""), fileArea)); } builder.Append(string.Format("Directory {0},\t Sum Area: {1:0.00} m2\r\n", directory, sumArea)); watch.Stop(); builder.Append(string.Format("{0} files,\t used {1} millisecs\r\n", fileNames.Length, watch.ElapsedMilliseconds)); return(builder.ToString()); }
/// <summary> /// Computes printing area of a pdf file /// </summary> /// <param name="fileNameWithPath"> </param> /// <param name="areaType"></param> /// <returns></returns> public static double GetFileAreaM2(string fileNameWithPath, PdfAreaType areaType) { using (StreamReader reader = File.OpenText(fileNameWithPath)) { if (reader.EndOfStream) { return(0.0); } return(GetFileAreaM2(reader.ReadToEnd(), areaType.ToString())); } }
protected void GetAreasData(string directory, PdfAreaType areaType, string fileMask) { var watch = System.Diagnostics.Stopwatch.StartNew(); ResultTable.Rows.Clear(); string[] fileNames = System.IO.Directory.GetFiles(directory, searchPattern: string.IsNullOrEmpty(fileMask) ? @"*.pdf" : fileMask); double sumArea = 0.0; Int64 sumFileSize = 0; // Header row ResultTable.Controls.Add(AddRowCells( new string[] { "Areatyp", "Fil", "Area m2", "Size KB", "Modifierad" }, bold: true)); foreach (string fileName in fileNames) { double fileArea = PdfAreaCalcCommon.PdfAreaCalc.GetFileAreaM2(fileName, areaType); DateTime modified = System.IO.File.GetLastWriteTime(fileName); System.IO.FileInfo fi = new System.IO.FileInfo(fileName); Int64 fileSize = fi.Length; TableRow tRow = AddRowCells(new string[] { areaType.ToString(), fileName.Replace(directory + @"\", ""), fileArea.ToString("#.##"), (fileSize / 1000.0).ToString("0.00"), modified.ToString("yyyy-MM-dd") }); ResultTable.Controls.Add(tRow); sumArea += fileArea; sumFileSize += fileSize; } watch.Stop(); // Totals row ResultTable.Controls.Add(AddRowCells(new string[] { "", string.Format("Total {0} fil(er),     förbrukade {1} ms ", fileNames.Length, watch.ElapsedMilliseconds), sumArea.ToString("0.00"), (sumFileSize / 1000.0).ToString("0.00"), "" }, true)); }
private static void DecodeOneArg(string arg) { switch (arg.TrimStart().Substring(1, 1).ToUpper()) { case "B": areaType = PdfAreaType.BleedBox; break; case "C": areaType = PdfAreaType.CropBox; break; case "T": areaType = PdfAreaType.TrimBox; break; default: areaType = PdfAreaType.MediaBox; break; } }
private static void HandleOneFile(string fileName, PdfAreaType areaType) { double area = PdfAreaCalc.GetFileAreaM2(fileName, areaType); System.Console.WriteLine("{0}\t{1}", fileName, area.ToString("#.##")); }