Example #1
0
 /// <summary>
 /// publicly exposed class for saving a book to web
 /// </summary>
 /// <param name="bv">the current bookviewer</param>
 /// <param name="folderloc">the folder where the page is being saved</param>
 public static void PublishBook(BookViewer bv, string folderloc, MainWindow h)
 {
     h.SetBackGroundInvisible();
     CopyPreSetFiles(folderloc);
     RenderPages(bv, folderloc);
     h.SetBackGroundVisible();
 }
Example #2
0
        /// <summary>
        /// Generates an image of each page in the year book
        /// and saves it to the src folder
        /// </summary>
        /// <param name="bv"></param>
        /// <param name="folderloc"></param>
        private static void RenderPages(BookViewer bv, string folderloc)
        {
            int currentpage = bv.ViewIndex;
            //loops though each page
            foreach (Page p in bv.CurrentBook.Pages)
            {
                bv.ViewIndex = p.PageNumber;
                //forces the canvas to re-render
                BookViewer.DesignerCanvas.UpdateLayout();
                //takes a picture of the canvas
                RenderTargetBitmap rtb = new RenderTargetBitmap(PaperSize.Pixel.PaperWidth, PaperSize.Pixel.PaperHeight, 96, 96, PixelFormats.Default);
                rtb.Render(BookViewer.DesignerCanvas);
                //getting the bleed margin
                Int32Rect bleedmargin = new Int32Rect((PaperSize.Pixel.PaperWidth - PaperSize.Pixel.BleedWidth) / 2, (PaperSize.Pixel.PaperHeight - PaperSize.Pixel.BleedHeight) / 2, PaperSize.Pixel.BleedWidth, PaperSize.Pixel.BleedHeight);
                //cropping the image
                CroppedBitmap cb = new CroppedBitmap(rtb, bleedmargin);
                //encodes the image in png format
                PngBitmapEncoder pbe = new PngBitmapEncoder();
                pbe.Frames.Add(BitmapFrame.Create(cb));
                //saves the resulting image
                FileStream fs = File.Open(folderloc + "\\src\\" + (p.PageNumber+1) + ".png", FileMode.Create);
                pbe.Save(fs);
                fs.Flush();
                fs.Close();

            }
            bv.ViewIndex = currentpage;
        }
Example #3
0
 /// <summary>
 /// After the actual form has initilized run this event, mainly here for debuging purposes as the main form
 /// constructor wont show exceptions in visual studio
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Window_Initialized_1(object sender, EventArgs e)
 {
     //initilizes the book viewer for a new book and sets up the page navigation
     Book b = new Book();
     b.SetAsStarterBook();
     current = new BookViewer(DesignerCanvas, this, b);
     lblTotalPages.Content = "/ " + current.CurrentBook.Pages.Count.ToString();
     tbxPageIndex.Text = (current.ViewIndex + 1).ToString();
 }