コード例 #1
0
ファイル: PdfProcessing.cs プロジェクト: AlexeyYa/stprrequest
        public static PdfFormat FromString(string str)
        {
            PdfFormat pdfFormat = new PdfFormat();
            int       result    = 0;

            if (str.Contains("("))
            {
                int d1 = str.IndexOf("(");
                int d2 = str.IndexOf(",");
                int d3 = str.IndexOf(",", d2 + 1);
                int d4 = str.IndexOf(",", d3 + 1);
                int d5 = str.IndexOf(",", d4 + 1);
                int d6 = str.IndexOf(")", d5 + 1);
                Int32.TryParse(str.Substring(0, d1), out result);
                pdfFormat.Formats = result;
                Int32.TryParse(str.Substring(d1 + 1, d2 - d1 - 1), out result);
                pdfFormat.A4 = result;
                Int32.TryParse(str.Substring(d2 + 1, d3 - d2 - 1), out result);
                pdfFormat.A3 = result;
                Int32.TryParse(str.Substring(d3 + 1, d4 - d3 - 1), out result);
                pdfFormat.A2 = result;
                Int32.TryParse(str.Substring(d4 + 1, d5 - d4 - 1), out result);
                pdfFormat.A1 = result;
                Int32.TryParse(str.Substring(d5 + 1, d6 - d5 - 1), out result);
                pdfFormat.A0 = result;
            }
            else if (Int32.TryParse(str, out result))
            {
                pdfFormat.Formats = result;
            }
            return(pdfFormat);
        }
コード例 #2
0
ファイル: PdfProcessing.cs プロジェクト: AlexeyYa/stprrequest
        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);
        }
コード例 #3
0
ファイル: PdfProcessing.cs プロジェクト: AlexeyYa/stprrequest
 public PdfFormat(PdfFormat src)
 {
     Formats = src.Formats;
     A4      = src.A4;
     A3      = src.A3;
     A2      = src.A2;
     A1      = src.A1;
     A0      = src.A0;
 }
コード例 #4
0
 public void SizeCorAdd(PdfFormat p)
 {
     if (SizeCor != null)
     {
         SizeCor += p;
     }
     else
     {
         SizeCor = p;
     }
 }
コード例 #5
0
 public void SizeAdd(PdfFormat p)
 {
     if (Size != null)
     {
         Size += p;
     }
     else
     {
         Size = p;
     }
 }
コード例 #6
0
ファイル: PdfProcessing.cs プロジェクト: AlexeyYa/stprrequest
        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);
        }
コード例 #7
0
ファイル: PdfProcessing.cs プロジェクト: AlexeyYa/stprrequest
        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)
            {
                return(new PdfFormat(0, 0, 0, 0, 0, 0));
            }
        }
コード例 #8
0
ファイル: PdfProcessing.cs プロジェクト: AlexeyYa/stprrequest
 public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 {
     return(PdfFormat.FromString((string)value));
 }