Example #1
0
        private async void btnRender_Click(object sender, RoutedEventArgs e)
        {
            await Task.Delay(TimeSpan.FromMilliseconds(100));

            pdf.Clear();
            progressRing.IsActive = true;
            panel.Arrange(pdf.PageRectangle);

            //1. Export UI as an image and then draw this image in pdf document.
            var renderTargetBitmap = new RenderTargetBitmap();
            await renderTargetBitmap.RenderAsync(panel);

            var wb = new WriteableBitmap(renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight);

            (await renderTargetBitmap.GetPixelsAsync()).CopyTo(wb.PixelBuffer);
            var rect = new Rect(0, 0, renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight);

            pdf.DrawImage(wb, rect);

            //2. Draw every UI elements inside the panel in pdf document.
            //await pdf.DrawElement(panel, pdf.PageRectangle);
            PdfUtils.SetDocumentInfo(pdf, Strings.RenderUIDocumentTitle);
            await pdfDocSource.LoadFromStreamAsync(PdfUtils.SaveToStream(pdf).AsRandomAccessStream());

            progressRing.IsActive = false;
        }
Example #2
0
        async void TOCPage_Loaded(object sender, RoutedEventArgs e)
        {
            progressRing.IsActive = true;
            CreateDocumentTOC(pdf);
            PdfUtils.SetDocumentInfo(pdf, Strings.TableOfContentsDocumentTitle);
            await pdfDocSource.LoadFromStreamAsync(PdfUtils.SaveToStream(pdf).AsRandomAccessStream());

            progressRing.IsActive = false;
        }
        async void BasicText_Loaded(object sender, RoutedEventArgs e)
        {
            progressRing.IsActive = true;
            CreateDocumentText(pdf);

            await pdfDocSource.LoadFromStreamAsync(PdfUtils.SaveToStream(pdf).AsRandomAccessStream());

            progressRing.IsActive = false;
        }