Exemplo n.º 1
0
        protected override void Render(Microsoft.ReportingServices.OnDemandReportRendering.Report report, NameValueCollection deviceInfo, Hashtable renderProperties, CreateAndRegisterStream createAndRegisterStream)
        {
            PaginationSettings paginationSettings = new PaginationSettings(report, deviceInfo);

            paginationSettings.UseEmSquare       = true;
            paginationSettings.MeasureTextDpi    = 1000;
            paginationSettings.UseGenericDefault = false;
            if (paginationSettings.DynamicImageDpiX == 96)
            {
                paginationSettings.DynamicImageDpiX = 300;
            }
            if (paginationSettings.DynamicImageDpiY == 96)
            {
                paginationSettings.DynamicImageDpiY = 300;
            }
            BufferedStream bufferedStream;

            using (Microsoft.ReportingServices.Rendering.HPBProcessing.HPBProcessing hPBProcessing = new Microsoft.ReportingServices.Rendering.HPBProcessing.HPBProcessing(report, paginationSettings, createAndRegisterStream, ref renderProperties))
            {
                hPBProcessing.SetContext(hPBProcessing.PaginationSettings.StartPage, hPBProcessing.PaginationSettings.EndPage);
                using (Renderer renderer = new Renderer(physicalPagination: true))
                {
                    bufferedStream = new BufferedStream(createAndRegisterStream(report.Name, "pdf", null, "application/pdf", willSeek: false, StreamOper.CreateAndRegister));
                    using (PDFWriter pDFWriter = new PDFWriter(renderer, bufferedStream, disposeRenderer: false, createAndRegisterStream, hPBProcessing.PaginationSettings.DpiX, hPBProcessing.PaginationSettings.DpiY))
                    {
                        pDFWriter.HumanReadablePDF = m_humanReadablePDF;
                        pDFWriter.PrintOnOpen      = m_printOnOpen;
                        pDFWriter.Test             = m_test;
                        pDFWriter.EmbedFonts       = m_embedFonts;
                        if (report.HasDocumentMap)
                        {
                            DocumentMap documentMap = null;
                            try
                            {
                                documentMap = report.DocumentMap;
                                if (documentMap != null)
                                {
                                    if (documentMap.MoveNext())
                                    {
                                        DocumentMapNode current = documentMap.Current;
                                        HandleDocumentMap(documentMap, pDFWriter.DocumentMapRootLabel = new PDFLabel(current.Id, current.Label), 1);
                                    }
                                    if (pDFWriter.DocumentMapRootLabel.Children == null || pDFWriter.DocumentMapRootLabel.Children.Count == 0)
                                    {
                                        pDFWriter.DocumentMapRootLabel = null;
                                    }
                                    else
                                    {
                                        pDFWriter.DocumentMapLabelPoints = new Dictionary <string, PDFPagePoint>();
                                    }
                                }
                            }
                            finally
                            {
                                documentMap?.Dispose();
                            }
                        }
                        int num = hPBProcessing.PaginationSettings.StartPage;
                        pDFWriter.BeginReport(hPBProcessing.PaginationSettings.MeasureTextDpi, hPBProcessing.PaginationSettings.MeasureTextDpi);
                        while (true)
                        {
                            hPBProcessing.GetNextPage(out RPLReport rplReport);
                            if (rplReport == null)
                            {
                                break;
                            }
                            renderer.ProcessPage(rplReport, num, hPBProcessing.SharedFontCache, hPBProcessing.GlyphCache);
                            rplReport.Release();
                            rplReport = null;
                            num++;
                        }
                        pDFWriter.EndReport();
                    }
                }
            }
            bufferedStream.Flush();
        }