Exemple #1
0
        void RenderPreview(int i)
        {
            SPanel.Children.Clear();

            Canvas can = CanvasSaveLoad.LoadSpecificCanvas(data, i);

            CanvasSaveLoad.ToPresentationMode(can);
            CanvasSaveLoad.SimulateCanvas(can);

            can.UpdateLayout();
            Size size = new Size();

            can.Measure(size);
            can.Arrange(new Rect(size));

            ImageSource bs = ImageWorker.ByteDataToImage(CanvasWriter.SaveCanvasToImgSimulateFullPng(can));

            Border pageP = new Border();

            pageP.Background      = new ImageBrush(bs);
            pageP.BorderBrush     = new SolidColorBrush(Color.FromRgb(44, 62, 80));
            pageP.BorderThickness = new Thickness(3);
            pageP.Width           = data.CanvasW;
            pageP.Height          = data.CanvasH;
            pageP.Margin          = new Thickness(10, 10, 10, 15);

            SPanel.Children.Add(pageP);

            L_Page.Content = (i + 1) + "/" + data.pages.Count;
        }
Exemple #2
0
        private void PrintAddPage(int i, FixedDocument document, Size sizeContent, Size margins)
        {
            Canvas can = CanvasSaveLoad.LoadSpecificCanvas(data, i);

            CanvasSaveLoad.ToPresentationMode(can);
            CanvasSaveLoad.SimulateCanvas(can);


            can.UpdateLayout();
            Size size = new Size();

            can.Measure(size);
            can.Arrange(new Rect(size));

            ImageSource bs    = ImageWorker.ByteDataToImage(CanvasWriter.SaveCanvasToImgSimulateFullPng(can));
            Image       image = new Image();

            if (SB_Fit.IsChecked())
            {
                image.Width  = sizeContent.Width;
                image.Height = sizeContent.Height;
            }
            else
            {
                image.Width  = data.CanvasW;
                image.Height = data.CanvasH;
            }
            image.Stretch = Stretch.Uniform;
            image.Source  = bs;


            FixedPage page = new FixedPage();

            page.Width  = document.DocumentPaginator.PageSize.Width;
            page.Height = document.DocumentPaginator.PageSize.Width;

            if (SB_Fit.IsChecked())
            {
                page.Margin = new Thickness(margins.Width, margins.Height, 0, 0);
            }


            page.Children.Clear();
            page.Children.Add(image);

            PageContent pageContent = new PageContent();

            ((IAddChild)pageContent).AddChild(page);
            document.Pages.Add(pageContent);
        }
Exemple #3
0
        private void LoadCanvas()
        {
            Canvas can = CanvasSaveLoad.LoadSpecificCanvas(data, curloaded);

            CanvasSaveLoad.ToPresentationMode(can);
            CanvasSaveLoad.SimulateCanvas(can);

            can.UpdateLayout();
            Size size = new Size();

            can.Measure(size);
            can.Arrange(new Rect(size));

            ImageSource bs = ImageWorker.ByteDataToImage(CanvasWriter.SaveCanvasToImgSimulateFullPng(can));

            IMBorder.Background      = new ImageBrush(bs);
            IMBorder.BorderBrush     = new SolidColorBrush(Color.FromRgb(0, 0, 0));
            IMBorder.BorderThickness = new Thickness(1);
            IMBorder.Width           = data.CanvasW;
            IMBorder.Height          = data.CanvasH;

            TextBox_Page.Text = "" + (curloaded + 1);
            L_Pages.Content   = "/" + data.pages.Count;
        }
Exemple #4
0
        private void ExportCanvasToPDF()
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.FileName = Strings.ResStrings.File + ".pdf";
            saveFileDialog.Filter   = Strings.FormatStrings.PDF + "| *.pdf|" + Strings.ResStrings.AllFiles + "| *.*";

            if (saveFileDialog.ShowDialog() == true)
            {
                PdfDocument pdf = new PdfDocument();

                for (int i = 0; i < data.pages.Count; i++)
                {
                    Canvas can = CanvasSaveLoad.LoadSpecificCanvas(data, i);
                    CanvasSaveLoad.ToPresentationMode(can);
                    CanvasSaveLoad.SimulateCanvas(can);


                    can.UpdateLayout();
                    Size size = new Size();
                    can.Measure(size);
                    can.Arrange(new Rect(size));

                    BitmapSource bs;

                    if (RB_BQuality.IsChecked == true)
                    {
                        bs = (BitmapSource)ImageWorker.ByteDataToImage(CanvasWriter.SaveCanvasToImgSimulateFullPng(can));
                    }
                    else
                    {
                        int quality = 90;

                        int.TryParse(TB_Quality.Text, out quality);

                        bs = (BitmapSource)ImageWorker.ByteDataToImage(CanvasWriter.SaveCanvasToImgSimulateFullJpg(can, quality));
                    }

                    var ximg = XImage.FromBitmapSource(bs);
                    ximg.Interpolate = false;

                    PdfPage pdfPage = pdf.AddPage();
                    pdfPage.Width  = XUnit.FromPresentation(data.CanvasW);
                    pdfPage.Height = XUnit.FromPresentation(data.CanvasH);
                    XGraphics xgr = XGraphics.FromPdfPage(pdfPage);

                    xgr.DrawImage(
                        ximg,
                        0, 0, pdfPage.Width, pdfPage.Height);
                }

                pdf.Info.Creator      = Strings.ResStrings.AppName;
                pdf.Info.CreationDate = DateTime.Now;
                pdf.Info.Subject      = TB_Subject.Text;
                pdf.Info.Author       = TB_Author.Text;
                pdf.Info.Title        = TB_Title.Text;
                pdf.Info.Keywords     = TB_Keywords.Text;

                pdf.Save(saveFileDialog.FileName);

                IsExported = true;
                Close();
            }
        }
Exemple #5
0
        private void ExportOutputToPDF()
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.FileName = Strings.ResStrings.File + ".pdf";
            saveFileDialog.Filter   = Good_Teacher.Strings.FormatStrings.PDF + "| *.pdf|" + Good_Teacher.Strings.ResStrings.AllFiles + "| *.*";

            if (saveFileDialog.ShowDialog() == true)
            {
                PdfDocument pdf = new PdfDocument();

                for (int i = 0; i < output.Pages.Count; i++)
                {
                    InkCanvas canvas = new InkCanvas();
                    canvas.Width  = output.W;
                    canvas.Height = output.H;
                    canvas.Margin = new Thickness(0, 0, 0, 0);

                    if (output.Pages[i].strokeCollection != null)
                    {
                        using (Stream stream = new MemoryStream(output.Pages[i].strokeCollection))
                        {
                            StrokeCollection strokes = new StrokeCollection(stream);
                            canvas.Strokes.Add(strokes);
                        }
                    }

                    canvas.Background = new ImageBrush(GetImage(output.Pages[i].Image));

                    BitmapSource bs;

                    if (RB_BQuality.IsChecked == true)
                    {
                        bs = (BitmapSource)ImageWorker.ByteDataToImage(SaveInkCanvasToPng(canvas));
                    }
                    else
                    {
                        int quality = 90;

                        int.TryParse(TB_Quality.Text, out quality);

                        bs = (BitmapSource)ImageWorker.ByteDataToImage(SaveInkCanvasToJpg(canvas, quality));
                    }

                    var ximg = XImage.FromBitmapSource(bs);
                    ximg.Interpolate = false;

                    PdfPage pdfPage = pdf.AddPage();
                    pdfPage.Width  = XUnit.FromPresentation(output.W);
                    pdfPage.Height = XUnit.FromPresentation(output.H);
                    XGraphics xgr = XGraphics.FromPdfPage(pdfPage);


                    xgr.DrawImage(
                        ximg,
                        0, 0, pdfPage.Width, pdfPage.Height);

                    /*
                     * BitmapSource bs = (BitmapSource)GetImage(output.Pages[i].Image);
                     *
                     * var ximg = XImage.FromBitmapSource(bs);
                     * ximg.Interpolate = false;
                     *
                     * PdfPage pdfPage = pdf.AddPage();
                     * pdfPage.Width = XUnit.FromPresentation(output.W);
                     * pdfPage.Height = XUnit.FromPresentation(output.H);
                     * XGraphics xgr = XGraphics.FromPdfPage(pdfPage);
                     *
                     *
                     * xgr.DrawImage(
                     * ximg,
                     * 0, 0, pdfPage.Width, pdfPage.Height);
                     */
                }

                pdf.Info.Creator      = Strings.ResStrings.AppName;
                pdf.Info.CreationDate = DateTime.Now;
                pdf.Info.Subject      = TB_Subject.Text;
                pdf.Info.Author       = TB_Author.Text;
                pdf.Info.Title        = TB_Title.Text;
                pdf.Info.Keywords     = TB_Keywords.Text;

                pdf.Save(saveFileDialog.FileName);

                IsExported = true;
                Close();
            }
        }