Exemplo n.º 1
0
        /// <summary>
        /// Reads the WMF into a template.
        /// </summary>
        /// <param name="template">the template to read to</param>
        public void ReadWMF(PdfTemplate template)
        {
            TemplateData    = template;
            template.Width  = this.Width;
            template.Height = this.Height;
            Stream istr = null;

            try {
                if (rawData == null)
                {
                    WebRequest w = WebRequest.Create(url);
                    istr = w.GetResponse().GetResponseStream();
                }
                else
                {
                    istr = new MemoryStream(rawData);
                }
                MetaDo meta = new MetaDo(istr, template);
                meta.ReadAll();
            }
            finally {
                if (istr != null)
                {
                    istr.Close();
                }
            }
        }
        /// <summary>
        /// Reads the WMF into a template.
        /// </summary>
        /// <param name="template">the template to read to</param>
        public void ReadWmf(PdfTemplate template)
        {
            TemplateData    = template;
            template.Width  = Width;
            template.Height = Height;
            Stream istr = null;

            try
            {
                if (rawData == null)
                {
                    istr = url.GetResponseStream();
                }
                else
                {
                    istr = new MemoryStream(rawData);
                }
                var meta = new MetaDo(istr, template);
                meta.ReadAll();
            }
            finally
            {
                if (istr != null)
                {
                    istr.Dispose();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Extracts the image data from the Image.
        /// @throws DocumentException If an error occurs accessing the image content
        /// </summary>
        /// <param name="image">The image for which to extract the content</param>
        /// <returns>The raw image data, not formated</returns>
        private byte[][] getImageData(Image image)
        {
            int wmfPlaceableHeaderSize = 22;
            RtfByteArrayBuffer bab     = new RtfByteArrayBuffer();

            try
            {
                if (_imageType == Image.ORIGINAL_BMP)
                {
                    bab.Append(MetaDo.WrapBmp(image));
                }
                else
                {
                    byte[] iod = image.OriginalData;
                    if (iod == null)
                    {
                        Stream imageIn = image.Url.GetResponseStream();
                        if (_imageType == Image.ORIGINAL_WMF)
                        { //remove the placeable header first
                            for (int k = 0; k < wmfPlaceableHeaderSize; k++)
                            {
                                if (imageIn.ReadByte() < 0)
                                {
                                    throw (new IOException("while removing wmf placeable header"));
                                }
                            }
                        }
                        bab.Write(imageIn);
                        imageIn.Dispose();
                    }
                    else
                    {
                        if (_imageType == Image.ORIGINAL_WMF)
                        {
                            //remove the placeable header
                            bab.Write(iod, wmfPlaceableHeaderSize, iod.Length - wmfPlaceableHeaderSize);
                        }
                        else
                        {
                            bab.Append(iod);
                        }
                    }
                }
                return(bab.ToArrayArray());
            }
            catch (IOException ioe)
            {
                throw new DocumentException(ioe.Message);
            }
        }
Exemplo n.º 4
0
        /**
         * Extracts the image data from the Image.
         *
         * @param image The image for which to extract the content
         * @return The raw image data, not formated
         * @throws DocumentException If an error occurs accessing the image content
         */
        private byte[][] GetImageData(Image image)
        {
            int WMF_PLACEABLE_HEADER_SIZE = 22;
            RtfByteArrayBuffer bab        = new RtfByteArrayBuffer();

            try {
                if (imageType == Image.ORIGINAL_BMP)
                {
                    bab.Append(MetaDo.WrapBMP(image));
                }
                else
                {
                    byte[] iod = image.OriginalData;
                    if (iod == null)
                    {
                        Stream imageIn = WebRequest.Create(image.Url).GetResponse().GetResponseStream();
                        if (imageType == Image.ORIGINAL_WMF)   //remove the placeable header first
                        {
                            for (int k = 0; k < WMF_PLACEABLE_HEADER_SIZE; k++)
                            {
                                if (imageIn.ReadByte() < 0)
                                {
                                    throw (new IOException("while removing wmf placeable header"));
                                }
                            }
                        }
                        bab.Write(imageIn);
                        imageIn.Close();
                    }
                    else
                    {
                        if (imageType == Image.ORIGINAL_WMF)
                        {
                            //remove the placeable header
                            bab.Write(iod, WMF_PLACEABLE_HEADER_SIZE, iod.Length - WMF_PLACEABLE_HEADER_SIZE);
                        }
                        else
                        {
                            bab.Append(iod);
                        }
                    }
                }
                return(bab.ToArrayArray());
            } catch (IOException ioe) {
                throw new DocumentException(ioe.Message);
            }
        }
Exemplo n.º 5
0
        /**
         * Extracts the image data from the Image. The data is formated for direct inclusion
         * in a rtf document
         *
         * @param image The Image for which to extract the content
         * @return The image data formated for the rtf document
         * @throws DocumentException If an error occurs accessing the image content
         */
        private byte[] GetImage(Image image)
        {
            MemoryStream imageTemp = new MemoryStream();

            try {
                Stream imageIn;
                if (imageType == Image.ORIGINAL_BMP)
                {
                    imageIn = new MemoryStream(MetaDo.WrapBMP(image));
                }
                else
                {
                    if (image.OriginalData == null)
                    {
                        imageIn = WebRequest.Create(image.Url).GetResponse().GetResponseStream();
                    }
                    else
                    {
                        imageIn = new MemoryStream(image.OriginalData);
                    }
                    if (imageType == Image.ORIGINAL_WMF)   //remove the placeable header
                    {
                        Image.Skip(imageIn, 22);
                    }
                }
                int buffer = 0;
                int count  = 0;
                while ((buffer = imageIn.ReadByte()) != -1)
                {
                    String helperStr = buffer.ToString("X2");
                    byte[] t         = DocWriter.GetISOBytes(helperStr);
                    imageTemp.Write(t, 0, t.Length);
                    count++;
                    if (count == 64)
                    {
                        imageTemp.WriteByte((byte)'\n');
                        count = 0;
                    }
                }
            } catch (IOException ioe) {
                throw new DocumentException(ioe.ToString());
            }
            return(imageTemp.ToArray());
        }