MakePdf() public method

public MakePdf ( string inputHtmlPath, string outputPdfPath, string paperSizeName, bool landscape, bool saveMemoryMode, bool layoutPagesForRightToLeft, PublishModel booketLayoutMethod, PublishModel bookletPortion, BackgroundWorker worker, DoWorkEventArgs doWorkEventArgs, Control owner ) : void
inputHtmlPath string
outputPdfPath string
paperSizeName string A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,B0,B1,B10,B2,B3,B4,B5,B6,B7,B8,B9,C5E,Comm10E,DLE,Executive,Folio,Ledger,Legal,Letter,Tabloid
landscape bool true if landscape orientation, false if portrait orientation
saveMemoryMode bool true if PDF file is to be produced using less memory (but more time)
layoutPagesForRightToLeft bool true if RTL, false if LTR layout
booketLayoutMethod PublishModel NoBooklet,SideFold,CutAndStack,Calendar
bookletPortion PublishModel None,AllPagesNoBooklet,BookletCover,BookletPages,InnerContent
worker System.ComponentModel.BackgroundWorker If not null, the Background worker which is running this task, and may be queried to determine whether a cancel is being attempted
doWorkEventArgs System.ComponentModel.DoWorkEventArgs The event passed to the worker when it was started. If a cancel is successful, it's Cancel property should be set true.
owner System.Windows.Forms.Control A control which can be used to invoke parts of the work which must be done on the ui thread.
return void
Beispiel #1
0
 public void MakePdf_BookStyleIsNone_OutputsPdf()
 {
     var maker = new PdfMaker();
     using (var input = TempFile.WithExtension("htm"))
     using (var output = new TempFile())
     {
         File.WriteAllText(input.Path,"<html><body>Hello</body></html>");
         File.Delete(output.Path);
         maker.MakePdf(input.Path, output.Path, "a5", false, PublishModel.BookletLayoutMethod.SideFold, PublishModel.BookletPortions.AllPagesNoBooklet, new DoWorkEventArgs(null));
         //we don't actually have a way of knowing it did a booklet
         Assert.IsTrue(File.Exists(output.Path));
     }
 }
Beispiel #2
0
        public void MakePdf_BookNameIsChinese_OutputsPdf()
        {
            var maker = new PdfMaker();
            using (var input = TempFile.WithFilename("北京.htm"))
            using (var output = TempFile.WithFilename("北京.pdf"))
            {
                File.WriteAllText(input.Path, "<html><body>北京</body></html>");
                File.Delete(output.Path);
                maker.MakePdf(input.Path, output.Path, "A5", false, PublishModel.BookletLayoutMethod.SideFold, PublishModel.BookletPortions.BookletPages, new DoWorkEventArgs(null));
                //we don't actually have a way of knowing it did a booklet
                Assert.IsTrue(File.Exists(output.Path));
            }

            using (var input = TempFile.WithFilename("എന്റെ ബുക്ക്.htm"))
            using (var output = TempFile.WithFilename("എന്റെ ബുക്ക്.pdf"))
            {
                File.WriteAllText(input.Path, "<html><body>എന്റെ ബുക്ക്</body></html>");
                File.Delete(output.Path);
                maker.MakePdf(input.Path, output.Path, "A5", false, PublishModel.BookletLayoutMethod.SideFold, PublishModel.BookletPortions.BookletPages, new DoWorkEventArgs(null));
                //we don't actually have a way of knowing it did a booklet
                Assert.IsTrue(File.Exists(output.Path));
            }
        }
Beispiel #3
0
        public void LoadBook(BackgroundWorker worker, DoWorkEventArgs doWorkEventArgs)
        {
            try
            {
                using (var tempHtml = MakeFinalHtmlForPdfMaker())
                {
                    if (doWorkEventArgs.Cancel)
                    {
                        return;
                    }

                    BookletLayoutMethod layoutMethod = GetBookletLayoutMethod();

                    // Check memory for the benefit of developers.  The user won't see anything.
                    Bloom.Utils.MemoryManagement.CheckMemory(true, "about to create PDF file", false);
                    _pdfMaker.MakePdf(new PdfMakingSpecs()
                    {
                        InputHtmlPath             = tempHtml.Key,
                        OutputPdfPath             = PdfFilePath,
                        PaperSizeName             = PageLayout.SizeAndOrientation.PageSizeName,
                        Landscape                 = PageLayout.SizeAndOrientation.IsLandScape,
                        SaveMemoryMode            = _currentlyLoadedBook.UserPrefs.ReducePdfMemoryUse,
                        LayoutPagesForRightToLeft = LayoutPagesForRightToLeft,
                        BooketLayoutMethod        = layoutMethod,
                        BookletPortion            = BookletPortion,
                        BookIsFullBleed           = _currentlyLoadedBook.FullBleed,
                        PrintWithFullBleed        = GetPrintingWithFullBleed(),
                        Cmyk = _currentlyLoadedBook.UserPrefs.CmykPdf
                    },
                                      worker, doWorkEventArgs, View);
                    // Warn the user if we're starting to use too much memory.
                    Bloom.Utils.MemoryManagement.CheckMemory(false, "finished creating PDF file", true);
                }
            }
            catch (Exception e)
            {
                //we can't safely do any ui-related work from this thread, like putting up a dialog
                doWorkEventArgs.Result = e;
                //                SIL.Reporting.ErrorReport.NotifyUserOfProblem(e, "There was a problem creating a PDF from this book.");
                //                SetDisplayMode(DisplayModes.WaitForUserToChooseSomething);
                //                return;
            }
        }
Beispiel #4
0
        public void LoadBook(BackgroundWorker worker, DoWorkEventArgs doWorkEventArgs)
        {
            try
            {
                LoadBookIfNeeded();

                using (var tempHtml = MakeFinalHtmlForPdfMaker())
                {
                    if (doWorkEventArgs.Cancel)
                    {
                        return;
                    }

                    BookletLayoutMethod layoutMethod;
                    if (this.BookletPortion == BookletPortions.AllPagesNoBooklet)
                    {
                        layoutMethod = BookletLayoutMethod.NoBooklet;
                    }
                    else
                    {
                        layoutMethod = BookSelection.CurrentSelection.GetBookletLayoutMethod(PageLayout);
                    }

                    // Check memory for the benefit of developers.  The user won't see anything.
                    SIL.Windows.Forms.Reporting.MemoryManagement.CheckMemory(true, "about to create PDF file", false);
                    _pdfMaker.MakePdf(tempHtml.Key, PdfFilePath, PageLayout.SizeAndOrientation.PageSizeName,
                                      PageLayout.SizeAndOrientation.IsLandScape, LoadBookIfNeeded().UserPrefs.ReducePdfMemoryUse,
                                      LayoutPagesForRightToLeft, layoutMethod, BookletPortion, worker, doWorkEventArgs, View);
                    // Warn the user if we're starting to use too much memory.
                    SIL.Windows.Forms.Reporting.MemoryManagement.CheckMemory(false, "finished creating PDF file", true);
                }
            }
            catch (Exception e)
            {
                //we can't safely do any ui-related work from this thread, like putting up a dialog
                doWorkEventArgs.Result = e;
                //                SIL.Reporting.ErrorReport.NotifyUserOfProblem(e, "There was a problem creating a PDF from this book.");
                //                SetDisplayMode(DisplayModes.WaitForUserToChooseSomething);
                //                return;
            }
        }
        public void LoadBook(BackgroundWorker worker, DoWorkEventArgs doWorkEventArgs)
        {
            _currentlyLoadedBook = BookSelection.CurrentSelection;

            try
            {
                using (var tempHtml = MakeFinalHtmlForPdfMaker())
                {
                    if (doWorkEventArgs.Cancel)
                    {
                        return;
                    }

                    BookletLayoutMethod layoutMethod;
                    if (this.BookletPortion == BookletPortions.AllPagesNoBooklet)
                    {
                        layoutMethod = BookletLayoutMethod.NoBooklet;
                    }
                    else
                    {
                        layoutMethod = BookSelection.CurrentSelection.GetDefaultBookletLayout();
                    }

                    _pdfMaker.MakePdf(tempHtml.Path, PdfFilePath, PageLayout.SizeAndOrientation.PageSizeName, PageLayout.SizeAndOrientation.IsLandScape,
                                      layoutMethod, BookletPortion, worker, doWorkEventArgs, View);
                }
            }
            catch (Exception e)
            {
                //we can't safely do any ui-related work from this thread, like putting up a dialog
                doWorkEventArgs.Result = e;
                //                Palaso.Reporting.ErrorReport.NotifyUserOfProblem(e, "There was a problem creating a PDF from this book.");
                //                SetDisplayMode(DisplayModes.WaitForUserToChooseSomething);
                //                return;
            }
        }
		/// <summary>
		/// Runs PdfMaker.MakePdf() with the desired arguments.  Note that the implementation (as of March 2015)
		/// uses an external program to generate the PDF from the HTML file, so it doesn't need to be run on
		/// a background thread.  The process includes a (possibly overgenerous) timeout, so we don't try to
		/// impose one here.
		/// </summary>
		/// <remarks>
		/// Running this on a background thread would be okay, except that on Linux, the interaction between
		/// Mono and NUnit and the Bloom method result in the BackgroundWorker.RunWorkerCompleted event
		/// never being fired if tests other than those in this file are run along with these tests.  This is
		/// almost certainly an obscure bug in Mono.  Running the method directly as we do here sidesteps that
		/// problem.  (See https://jira.sil.org/browse/BL-831.)
		/// </remarks>
		void RunMakePdf(PdfMaker maker, string input, string output, string paperSize, bool landscape, bool saveMemoryMode, bool rightToLeft,
			PublishModel.BookletLayoutMethod layout, PublishModel.BookletPortions portion)
		{
			// Passing in a DoWorkEventArgs object prevents a possible exception being thrown.  Which may not
			// really matter much in the test situation since NUnit would catch the exception.  But I'd rather
			// have a nice test failure message than an unexpected exception caught message.
			var eventArgs = new DoWorkEventArgs(null);
			maker.MakePdf(input, output, paperSize, landscape, saveMemoryMode, rightToLeft, layout, portion, null, eventArgs, null);
		}