Exemple #1
0
        private XGraphics CreateGraphics(PdfPage pdfPage, PdfRendererOptions options)
        {
            var g = XGraphics.FromPdfPage(pdfPage, XGraphicsUnit.Point);

            g.SmoothingMode = XSmoothingMode.HighQuality;
            options.ConfigureGraphics?.Invoke(g);
            return(g);
        }
Exemple #2
0
        private static Size DetermineMaxSize(PdfPage pdfPage, PdfRendererOptions options, XGraphics g)
        {
            if (options.AdjustPageSize)
            {
                return(new Size(int.MaxValue, int.MaxValue));
            }

            var pageSize     = new Size(pdfPage.Width.ToLayout(), pdfPage.Height.ToLayout());
            var scaledSize   = GetTransformedSize(g, pageSize);
            var upscaledSize = new Size(
                (int)(pageSize.Width / scaledSize.Width * pageSize.Width),
                (int)(pageSize.Height / scaledSize.Height * pageSize.Height));

            return(upscaledSize);
        }
Exemple #3
0
        public void Render(Form form, PdfPage pdfPage, PdfRendererOptions options = null)
        {
            options = options ?? PdfRendererOptions.Default;

            using (var localBitmapCache = new PdfBitmapCache())
            {
                using (var g = CreateGraphics(pdfPage, options))
                {
                    var size = DetermineMaxSize(pdfPage, options, g);
                    form.LayOut(size, CreateContext(g, localBitmapCache));

                    if (options.AdjustPageSize)
                    {
                        AdjustPageSize(form, pdfPage, g);
                    }
                }

                using (var g = CreateGraphics(pdfPage, options))
                    Render(CreateContext(g, localBitmapCache), form.Content);
            }
        }