Пример #1
0
        public Stream PrintSeries(string userName, string[] seriesInstanceUIDs, PrintOptions options, string annotationData)
        {
            DocumentWriter documentWriterInstance = null;

            try
            {
                List <SeriesImage> seriesImages = _Exporter.GetSeriesImages(seriesInstanceUIDs);
                Dictionary <string, List <AnnContainer> > annotations = AddInsUtils.GetAnnotations(annotationData);

                documentWriterInstance = OpenDocumentWriterInstance(options.PageWidth, options.PageHeight, 300);
                string fileName = Path.GetTempFileName();
                documentWriterInstance.BeginDocument(fileName, DocumentFormat.Pdf);

                foreach (SeriesImage si in seriesImages)
                {
                    ProcessInstance(si, userName, options, annotations);

                    {
                        var page = new Leadtools.Document.Writer.DocumentWriterRasterPage();
                        page.Image = si.Image;
                        documentWriterInstance.AddPage(page);
                    }
                }

                documentWriterInstance.EndDocument();
                MemoryStream ms = new MemoryStream(File.ReadAllBytes(fileName));
                File.Delete(fileName);
                ms.Position = 0;
                return(ms);
            }
            finally
            {
                if (null != documentWriterInstance)
                {
                    documentWriterInstance.EndDocument();
                }
            }
        }
Пример #2
0
        public Stream PrintLayout(string userName, string seriesInstanceUID, Layout layout, PrintOptions options, string annotationData)
        {
            DocumentWriter documentWriterInstance = null;

            //
            // Check to see if a width was provide.  If not we default to 1024;
            //
            if (options.LayoutImageWidth == 0)
            {
                options.LayoutImageWidth = 1024;
            }

            SeriesImage layoutImageWithInfo = null;

            using (RasterImage layoutImage = AddInsUtils.CreateLayoutImage(options.LayoutImageWidth, options.WhiteBackground))
            {
                try
                {
                    options.LayoutPatientInfo = true;
                    Dictionary <string, List <AnnContainer> > annotations = AddInsUtils.GetAnnotations(annotationData);

                    foreach (var box in layout.Boxes)
                    {
                        if (null == box.referencedSOPInstanceUID)
                        {
                            continue;
                        }
                        if (0 == box.referencedSOPInstanceUID.Count)
                        {
                            continue;
                        }

                        //only the first instance
                        List <SeriesImage> seriesImages = _Exporter.GetInstanceImages(new string[] { box.referencedSOPInstanceUID[0] });

                        if (null == seriesImages)
                        {
                            continue;
                        }
                        if (0 == seriesImages.Count)
                        {
                            continue;
                        }

                        // layout patient info check whether to print the patient information on each image or on the whole layout image.
                        if (!options.LayoutPatientInfo)
                        {
                            //only the first image
                            ProcessInstance(seriesImages[0], userName, options, annotations);
                        }
                        else
                        {
                            // take one of those series image to print them at the bottom of the final resultant image.
                            if (layoutImageWithInfo == null)
                            {
                                layoutImageWithInfo = seriesImages[0];
                            }
                        }

                        AddInsUtils.LayoutImage(layoutImage, seriesImages[0].Image, box);
                    }

                    documentWriterInstance = OpenDocumentWriterInstance(options.PageWidth, options.PageHeight, 300);
                    string fileName = Path.GetTempFileName();
                    documentWriterInstance.BeginDocument(fileName, DocumentFormat.Pdf);

                    {
                        var page       = new Leadtools.Document.Writer.DocumentWriterRasterPage();
                        var finalImage = layoutImage;
                        if (options.LayoutPatientInfo)
                        {
                            // add text to the bottom of the resultant image.
                            layoutImageWithInfo.Image = layoutImage;
                            ProcessInstance(layoutImageWithInfo, userName, options, null);
                            finalImage = layoutImageWithInfo.Image;
                        }

                        page.Image = finalImage;
                        documentWriterInstance.AddPage(page);
                    }

                    documentWriterInstance.EndDocument();
                    MemoryStream ms = new MemoryStream(File.ReadAllBytes(fileName));
                    File.Delete(fileName);
                    ms.Position = 0;
                    return(ms);
                }
                finally
                {
                    if (null != documentWriterInstance)
                    {
                        documentWriterInstance.EndDocument();
                    }
                }
            }

            return(null);
        }