예제 #1
0
        public void Save()
        {
            try
            {
                // Give a slight preference to USB keys, though if they used a different directory last time, we favor that.

                if (string.IsNullOrEmpty(_lastDirectory) || !Directory.Exists(_lastDirectory))
                {
                    var drives = Palaso.UsbDrive.UsbDriveInfo.GetDrives();
                    if (drives != null && drives.Count > 0)
                    {
                        _lastDirectory = drives[0].RootDirectory.FullName;
                    }
                }

                using (var dlg = new SaveFileDialog())
                {
                    if (!string.IsNullOrEmpty(_lastDirectory) && Directory.Exists(_lastDirectory))
                    {
                        dlg.InitialDirectory = _lastDirectory;
                    }
                    var portion = "";
                    switch (BookletPortion)
                    {
                    case BookletPortions.AllPagesNoBooklet:
                        portion = "Pages";
                        break;

                    case BookletPortions.BookletCover:
                        portion = "Cover";
                        break;

                    case BookletPortions.BookletPages:
                        portion = "Inside";
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    string suggestedName = string.Format("{0}-{1}-{2}.pdf", Path.GetFileName(_currentlyLoadedBook.FolderPath),
                                                         _collectionSettings.GetLanguage1Name("en"), portion);
                    dlg.FileName = suggestedName;
                    dlg.Filter   = "PDF|*.pdf";
                    if (DialogResult.OK == dlg.ShowDialog())
                    {
                        _lastDirectory = Path.GetDirectoryName(dlg.FileName);
                        File.Copy(PdfFilePath, dlg.FileName, true);
                        Analytics.Track("Save PDF", new Dictionary <string, string>()
                        {
                            { "Portion", Enum.GetName(typeof(BookletPortions), BookletPortion) },
                            { "Layout", PageLayout.ToString() }
                        });
                    }
                }
            }
            catch (Exception err)
            {
                Palaso.Reporting.ErrorReport.NotifyUserOfProblem("Bloom was not able to save the PDF.  {0}", err.Message);
            }
        }
예제 #2
0
        public void Save()
        {
            try
            {
                // Give a slight preference to USB keys, though if they used a different directory last time, we favor that.

                if (string.IsNullOrEmpty(_lastDirectory) || !Directory.Exists(_lastDirectory))
                {
                    var drives = SIL.UsbDrive.UsbDriveInfo.GetDrives();
                    if (drives != null && drives.Count > 0)
                    {
                        _lastDirectory = drives[0].RootDirectory.FullName;
                    }
                }

                var portion = "";
                switch (BookletPortion)
                {
                case BookletPortions.None:
                    Debug.Fail("Save should not be enabled");
                    return;

                case BookletPortions.AllPagesNoBooklet:
                    portion = "Pages";
                    break;

                case BookletPortions.BookletCover:
                    portion = "Cover";
                    break;

                case BookletPortions.BookletPages:
                    portion = "Inside";
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                string forPrintShop =
                    _currentlyLoadedBook.UserPrefs.CmykPdf || _currentlyLoadedBook.UserPrefs.FullBleed
                                                ? "-printshop"
                                                : "";
                string suggestedName = string.Format($"{Path.GetFileName(_currentlyLoadedBook.FolderPath)}-{_currentlyLoadedBook.GetFilesafeLanguage1Name("en")}-{portion}{forPrintShop}.pdf");
                var    pdfFileLabel  = L10NSharp.LocalizationManager.GetString(@"PublishTab.PdfMaker.PdfFile",
                                                                               "PDF File",
                                                                               @"displayed as file type for Save File dialog.");

                pdfFileLabel = pdfFileLabel.Replace("|", "");
                var pdfFilter = String.Format("{0}|*.pdf", pdfFileLabel);

                var startingFolder = (!string.IsNullOrEmpty(_lastDirectory) && Directory.Exists(_lastDirectory)) ?
                                     _lastDirectory :
                                     Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var initialPath = Path.Combine(startingFolder, suggestedName);

                var destFileName = Utils.MiscUtils.GetOutputFilePathOutsideCollectionFolder(initialPath, pdfFilter);
                if (String.IsNullOrEmpty(destFileName))
                {
                    return;
                }

                _lastDirectory = Path.GetDirectoryName(destFileName);
                if (_currentlyLoadedBook.UserPrefs.CmykPdf)
                {
                    // PDF for Printshop (CMYK US Web Coated V2)
                    ProcessPdfFurtherAndSave(ProcessPdfWithGhostscript.OutputType.Printshop, destFileName);
                }
                else
                {
                    // we want the simple PDF we already made.
                    RobustFile.Copy(PdfFilePath, destFileName, true);
                }
                Analytics.Track("Save PDF", new Dictionary <string, string>()
                {
                    { "Portion", Enum.GetName(typeof(BookletPortions), BookletPortion) },
                    { "Layout", PageLayout.ToString() },
                    { "BookId", BookSelection.CurrentSelection.ID },
                    { "Country", _collectionSettings.Country }
                });
            }
            catch (Exception err)
            {
                SIL.Reporting.ErrorReport.NotifyUserOfProblem("Bloom was not able to save the PDF.  {0}", err.Message);
            }
        }
예제 #3
0
 public PdfCatalog(int objectNumber, PdfPages pdfPages, PageLayout pageLayout = PageLayout.SinglePage) : base(objectNumber, "Catalog")
 {
     Dictionary.Add("Pages", pdfPages.PdfReference());
     Dictionary.Add("PageLayout", $"/{pageLayout.ToString()}");
 }
예제 #4
0
        public void Save()
        {
            if (EpubMode)
            {
                try
                {
                    SaveAsEpub();
                }
                catch (Exception err)
                {
                    SIL.Reporting.ErrorReport.NotifyUserOfProblem("Bloom was not able to save the ePUB.  {0}", err.Message);
                }
                return;
            }
            try
            {
                // Give a slight preference to USB keys, though if they used a different directory last time, we favor that.

                if (string.IsNullOrEmpty(_lastDirectory) || !Directory.Exists(_lastDirectory))
                {
                    var drives = SIL.UsbDrive.UsbDriveInfo.GetDrives();
                    if (drives != null && drives.Count > 0)
                    {
                        _lastDirectory = drives[0].RootDirectory.FullName;
                    }
                }

                using (var dlg = new DialogAdapters.SaveFileDialogAdapter())
                {
                    if (!string.IsNullOrEmpty(_lastDirectory) && Directory.Exists(_lastDirectory))
                    {
                        dlg.InitialDirectory = _lastDirectory;
                    }
                    var portion = "";
                    switch (BookletPortion)
                    {
                    case BookletPortions.None:
                        Debug.Fail("Save should not be enabled");
                        return;

                    case BookletPortions.AllPagesNoBooklet:
                        portion = "Pages";
                        break;

                    case BookletPortions.BookletCover:
                        portion = "Cover";
                        break;

                    case BookletPortions.BookletPages:
                        portion = "Inside";
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    string suggestedName = string.Format("{0}-{1}-{2}.pdf", Path.GetFileName(_currentlyLoadedBook.FolderPath),
                                                         _collectionSettings.GetFilesafeLanguage1Name("en"), portion);
                    dlg.FileName = suggestedName;
                    var rgb = L10NSharp.LocalizationManager.GetString(@"PublishTab.PdfMaker.PdfWithRGB",
                                                                      "PDF with RGB color",
                                                                      @"displayed as file type for Save File dialog. 'RGB' may not be translatable, it is a standard.");
                    var swopv2 = L10NSharp.LocalizationManager.GetString(@"PublishTab.PdfMaker.PdfWithCmykSwopV2",
                                                                         "PDF with CMYK color (U.S. Web Coated (SWOP) v2)",
                                                                         @"displayed as file type for Save File dialog, the content in parentheses may not be translatable. 'CMYK' may not be translatable, it is a print shop standard.");

                    rgb        = rgb.Replace("|", "");
                    swopv2     = swopv2.Replace("|", "");
                    dlg.Filter = String.Format("{0}|*.pdf|{1}|*.pdf", rgb, swopv2);
                    if (DialogResult.OK == dlg.ShowDialog())
                    {
                        _lastDirectory = Path.GetDirectoryName(dlg.FileName);
                        switch (dlg.FilterIndex)
                        {
                        case 1:                         // PDF for Desktop Printing
                            RobustFile.Copy(PdfFilePath, dlg.FileName, true);
                            break;

                        case 2:                         // PDF for Printshop (CMYK US Web Coated V2)
                            ProcessPdfFurtherAndSave(ProcessPdfWithGhostscript.OutputType.Printshop, dlg.FileName);
                            break;
                        }
                        Analytics.Track("Save PDF", new Dictionary <string, string>()
                        {
                            { "Portion", Enum.GetName(typeof(BookletPortions), BookletPortion) },
                            { "Layout", PageLayout.ToString() },
                            { "BookId", BookSelection.CurrentSelection.ID },
                            { "Country", _collectionSettings.Country }
                        });
                    }
                }
            }
            catch (Exception err)
            {
                SIL.Reporting.ErrorReport.NotifyUserOfProblem("Bloom was not able to save the PDF.  {0}", err.Message);
            }
        }