Пример #1
0
        /// <summary>
        /// Saves the PDF from the disk swap file
        /// </summary>
        /// <param name="b"></param>
        /// <param name="output"></param>
        public void SaveAsPDF(BitmapFile b, string output)
        {
            FileInfo fi = new FileInfo(output);

            // Following are the calls to the Gios PDF library
            PdfDocument   myPdfDocument  = new PdfDocument(PdfDocumentFormat.InCentimeters(m_PDF_Width, m_PDF_Height));
            int           horizontalStep = Convert.ToInt32(m_PDF_Width * m_PDF_DPI / 2.54);
            int           verticalStep   = Convert.ToInt32(m_PDF_Height * m_PDF_DPI / 2.54);
            int           origin         = 0;
            List <string> tmpFiles       = new List <string>();
            int           tmpFileCount   = 0;

            while (origin < b.Y)
            {
                Bitmap tmp       = b.GetBitmap(0, origin, horizontalStep, verticalStep);
                string temp_file = fi.DirectoryName + "\\_tempPDFComponent_" + tmpFileCount.ToString().PadLeft(5, '0') + ".jpg";
                tmp.Save(temp_file, ImageFormat.Jpeg);
                tmpFiles.Add(temp_file);
                PdfPage  newPdfPage = myPdfDocument.NewPage();
                PdfImage myImage    = myPdfDocument.NewImage(temp_file);
                newPdfPage.Add(myImage, 0.0, 0.0, m_PDF_DPI);
                newPdfPage.SaveToDocument();
                origin += verticalStep;
                tmpFileCount++;
                tmp.Dispose();
            }
            myPdfDocument.SaveToFile(output);
            foreach (string f in tmpFiles)
            {
                try { File.Delete(f); }
                catch (Exception) { }
            }
        }
Пример #2
0
        /// <summary>
        /// Generates a bitmap from the slide
        /// </summary>
        /// <param name="slide">Slide to generate</param>
        /// <param name="input">Inpit directory</param>
        public CompositeBitmap(Slide slide, string input)
        {
            m_Input = new DirectoryInfo(input);
            if (!m_Input.Exists)
            {
                throw new Exception(input + " not found");
            }
            m_PDF_Width  = slide.pageX;
            m_PDF_Height = slide.pageY;
            m_PDF_DPI    = slide.pageDPI;

            if (slide.OnMemory)
            {
                // make bitmap
                BaseBitmap = new Bitmap(slide.x, slide.y);
                Graphics g = Graphics.FromImage(BaseBitmap);
                g.Clear(slide.BkColor);

                //draw all components
                foreach (SlideComponent sc in slide.Components)
                {
                    sc.Draw(input, g, BaseBitmap);
                }
                g.Dispose();
            }
            else
            {
                BaseBitmapFile = new BitmapFile(input + "\\_Swap.tiff", slide.x, slide.y, slide.BkColor, slide.pageDPI);
                int count = -1; // increment counter for debug output
                foreach (SlideComponent sc in slide.Components)
                {
                    sc.Draw(input, BaseBitmapFile, count);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Virtial Draw, defined in children
        /// </summary>
        /// <param name="source"></param>
        public override void Draw(string source, BitmapFile bmp, int count)
        {
            Bitmap   b                = null;
            Graphics g                = null;
            int      originalX        = x; x = 0; // paste is done to the zero coordinates
            int      originalY        = y; y = 0;
            int      originalTextX    = Text_x; Text_x -= originalX;
            int      originalTextY    = Text_y; Text_y -= originalY;
            int      originalCalloutX = Callout_x; Callout_x -= originalX;
            int      originalCalloutY = Callout_y; Callout_y -= originalY;

            try
            {
                b = bmp.GetBitmap(originalX, originalY, dx + 1, dy + 1);
                g = Graphics.FromImage(b);
                Draw(source, g, b);
                if (count >= 0)
                {
                    b.Save("C:\\temp\\_debug_" + count.ToString("000") + ".jpg", ImageFormat.Jpeg);
                }
                bmp.SetBitmap(b, originalX, originalY);
            }
            catch (Exception ex)
            {
                throw new Exception("Error in Draw routine: " + ex.Message);
            }
            finally
            {
                x         = originalX;
                y         = originalY;
                Text_x    = originalTextX;
                Text_y    = originalTextY;
                Callout_x = originalCalloutX;
                Callout_y = originalCalloutY;
                if (g != null)
                {
                    g.Dispose();
                }
                if (b != null)
                {
                    b.Dispose();
                }
            }
        }