Exemplo n.º 1
0
        public override Stream Render(
            ReportLayout report,
            string documentId, string designId, string title,
            int version, DateTimeOffset timestamp,
            string photoUri, string resourceUri, bool drawRules, bool drawPageBoxes,
            Generator generator, ITrace tracer)
        {
            AssemblyName assName = Assembly.GetExecutingAssembly().GetName();
            string       creator = $"Demon report generator {assName.Name} version {assName.Version.Major}.{assName.Version.Minor}.{assName.Version.Revision}";

            _generator = generator;

            Dictionary <string, string> docInfo = new Dictionary <string, string>();

            docInfo.Add("Title", title);
            docInfo.Add("Creator", creator);
            docInfo.Add("Producer", creator);
            docInfo.Add("CreationDate", $"D:{timestamp:yyyyMMddHHmmssZ}");
            docInfo.Add("Version", $"{version}");
            docInfo.Add("DocumentId", documentId);
            docInfo.Add("ReportDesignId", designId);

            //	In case we're going to draw rules on at least one page, make
            //	sure that we've got a font prepared for that
            _rulesFont = _generator.GetFont("Helvetica", 400, false, false, false, false);
            string ruleChars = "0123456789";

            foreach (char c in ruleChars)
            {
                _rulesFont.MapCharacter(c);
            }

            //	Lay out the content and apply page breaks
            _generator.TraceLayoutActivity("Measure and cut content");
            List <PageLayout> pageLayouts = report.LayOut();

            //	Subset the fonts. First map characters actually used by the
            //	layouts into the fonts' glyph character maps, and then create
            //	the subsets using only those glyphs. Do this after laying out
            //	because header and footer content isn't loaded until the layout
            //	phase. See the note in TextLayout.LoadContent before the call
            //	to ExpandProperties.
            //TODO: find a better way to handle PageNumber and PageCount so that we
            //can include them in the page body, and so that we can lay out the
            //header and footer at the same time as the body.
            report.MapFontCharacters();
            _generator.FontCache.Subset();

            Demon.PDF.Document doc = new Demon.PDF.Document(docInfo, _generator.FontCache);

            //	Write the content to the PDF
            tracer.TraceLayoutActivity("Generate document");
            foreach (PageLayout pageLayout in pageLayouts)
            {
                RenderPageLayout(pageLayout, doc, drawRules);
            }

            Stream file = doc.Write();

            return(file);
        }