Ejemplo n.º 1
0
 public bool SaveTIF(string fpOut, int convdpi)
 {
     if (fpPDF != null)
     {
         return(PDFUt.PDF2TIF(fpPDF, fpOut, convdpi, null, 1 + index));
     }
     else
     {
         return(Tiffcp.Run(fpOut, fpTIF + "," + index, false, false));
     }
 }
Ejemplo n.º 2
0
        bool SaveThem()
        {
            List <PageItem> pageItems = this.pageItems;

            List <int[]> pageRefsArray = new List <int[]>();

            {
                List <int> pageRefs = new List <int>();
                for (int x = 0, cx = pageItems.Count; x < cx; x++)
                {
                    PageItem pageItem = pageItems[x];
                    if (pageRefs.Count != 0 && (pageItem.isSep))
                    {
                        pageRefsArray.Add(pageRefs.ToArray());
                        pageRefs.Clear();
                    }
                    if (!pageItem.isDeleted)
                    {
                        pageRefs.Add(x);
                    }
                    if (pageRefs.Count != 0 && (x == cx - 1))
                    {
                        pageRefsArray.Add(pageRefs.ToArray());
                        pageRefs.Clear();
                    }
                }
            }

            if (pageRefsArray.Count == 0)
            {
                MessageBox.Show(this, "出力するものはありません。", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            if (saveDir == null)
            {
                if (fbdSave.ShowDialog(this) != DialogResult.OK)
                {
                    return(false);
                }
                saveDir = fbdSave.SelectedPath;
            }

            bool anyPDF = false;

            foreach (int[] pageRefs in pageRefsArray)
            {
                foreach (int pageRef in pageRefs)
                {
                    anyPDF |= pageItems[pageRef].provider.IsPDF;
                }
            }

            if (anyPDF)
            {
                using (ConvDpiForm form = new ConvDpiForm()) {
                    if (form.ShowDialog() != DialogResult.OK)
                    {
                        return(false);
                    }
                }
            }

            int    nTotal = 0, nSuccess = 0;
            String errs = "";

            using (AH2 ah2 = new AH2())
                using (WaitNow wip = new WaitNow()) {
                    wip.Cover(this);

                    int fileNum = 1;
                    for (int t = 0; t < pageRefsArray.Count; t++)
                    {
                        int[] pageRefs = pageRefsArray[t];
                        for (int c = 0; c < 10000; c++, fileNum++)
                        {
                            String fpsave = Path.Combine(saveDir, String.Format("分割#{0:0000}.tif", fileNum));
                            if (File.Exists(fpsave))
                            {
                                continue;
                            }

                            for (int x = 0; x < pageRefs.Length; x++)
                            {
                                PageItem pageItem  = pageItems[pageRefs[x]];
                                String   fpTempTIF = tempFiles.NewFile(".tif");
                                nTotal++;
                                if (pageItem.provider.SaveTIF(fpTempTIF, Settings.Default.ConvDpi))
                                {
                                    if (Settings.Default.Mono && !pageItem.provider.IsMono)
                                    {
                                        FIBITMAP dib = FreeImage.LoadEx(fpTempTIF);
                                        try {
                                            FIBITMAP dib2 = FreeImage.Threshold(dib, 128);
                                            try {
                                                FreeImage.Save(FREE_IMAGE_FORMAT.FIF_TIFF, dib2, fpTempTIF, FREE_IMAGE_SAVE_FLAGS.TIFF_CCITTFAX4);
                                            }
                                            finally {
                                                FreeImage.UnloadEx(ref dib2);
                                            }
                                        }
                                        finally {
                                            FreeImage.UnloadEx(ref dib);
                                        }
                                    }
                                    if (Tiffcp.Run(fpsave, fpTempTIF, Settings.Default.Mono, x != 0))
                                    {
                                        nSuccess++;
                                    }
                                    else
                                    {
                                        errs += String.Format("{0:#,##0} ページ目の保存に失敗\n", 1 + pageItem.index);
                                    }
                                }
                                else
                                {
                                    errs += String.Format("{0:#,##0} ページ目の保存に失敗\n", 1 + pageItem.index);
                                }
                            }
                            break;
                        }
                    }
                }

            MessageBox.Show(this, (nTotal == nSuccess) ? "保存しました。" : "部分的に保存が成功しました。\n\n---\n" + errs, Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            return(true);
        }