Example #1
0
        internal override void Format(Area area, FormatInfo previousFormatInfo)
        {
            HtmlFormFormatInfo formatInfo = (HtmlFormFormatInfo)_renderInfo.FormatInfo;

            formatInfo.Width  = XUnit.FromMillimeter(_form.Width.Millimeter);
            formatInfo.Height = XUnit.FromMillimeter(_form.Height.Millimeter);

            base.Format(area, previousFormatInfo);
        }
Example #2
0
        internal override void Render()
        {
            RenderFilling();

            HtmlFormFormatInfo formatInfo = (HtmlFormFormatInfo)_renderInfo.FormatInfo;
            Area  contentArea             = _renderInfo.LayoutInfo.ContentArea;
            XRect destRect = new XRect(contentArea.X, contentArea.Y, formatInfo.Width, formatInfo.Height);

            if (formatInfo.Failure == HtmlFormFailure.None)
            {
                XImage xImage = null;
                try
                {
                    // TODO: Falhar com _form.Content vazio
                    // TODO: Add CropX, CropY, etc...

                    XRect srcRect = new XRect(0, 0, formatInfo.Width, formatInfo.Height);
                    var   config  = new PdfGenerateConfig
                    {
                        ManualPageSize = new XSize(formatInfo.Width, formatInfo.Height),
                        MarginBottom   = 0,
                        MarginTop      = 0,
                        MarginLeft     = 0,
                        MarginRight    = 0
                    };

                    using (var htmlPdfDoc = PdfGenerator.GeneratePdf(_form.Content, config))
                    {
                        using (var pdfStream = new MemoryStream())
                        {
                            htmlPdfDoc.Save(pdfStream);
                            xImage = XPdfForm.FromStream(pdfStream);

                            _gfx.DrawImage(xImage, destRect, srcRect, XGraphicsUnit.Point);
                        }
                    }
                }
                catch (Exception)
                {
                    RenderFailureImage(destRect);
                }
                finally
                {
                    if (xImage != null)
                    {
                        xImage.Dispose();
                    }
                }
            }
            else
            {
                RenderFailureImage(destRect);
            }

            RenderLine();
        }
Example #3
0
        void RenderFailureImage(XRect destRect)
        {
            _gfx.DrawRectangle(XBrushes.LightGray, destRect);
            string             failureString;
            HtmlFormFormatInfo formatInfo = (HtmlFormFormatInfo)RenderInfo.FormatInfo;

            switch (formatInfo.Failure)
            {
            case HtmlFormFailure.RenderError:
            default:
                failureString = Messages2.DisplayHtmlFormRenderError;
                break;
            }

            // Create stub font
            XFont font = new XFont("Courier New", 8);

            _gfx.DrawString(failureString, font, XBrushes.Red, destRect, XStringFormats.Center);
        }