コード例 #1
0
        public void Start()
        {
            // Create the anchor for all pdf objects
            CompressionConfig cc = RdlEngineConfig.GetCompression();

            anchor = new PdfAnchor(cc != null);

            //Create a PdfCatalog
            string lang;

            if (r.ReportDefinition.Language != null)
            {
                lang = r.ReportDefinition.Language.EvaluateString(this.r, null);
            }
            else
            {
                lang = null;
            }
            catalog = new PdfCatalog(anchor, lang);

            //Create a Page Tree Dictionary
            pageTree = new PdfPageTree(anchor);

            //Create a Font Dictionary
            fonts = new PdfFonts(anchor);

            //Create a Pattern Dictionary
            patterns = new PdfPattern(anchor);

            //Create an Image Dictionary
            images = new PdfImages(anchor);

            //Create an Outline Dictionary
            outline = new PdfOutline(anchor);

            //Create the info Dictionary
            info = new PdfInfo(anchor);

            //Set the info Dictionary.
            info.SetInfo(r.Name, r.Author, r.Description, "");  // title, author, subject, company

            //Create a utility object
            pdfUtility = new PdfUtility(anchor);

            //write out the header
            int size = 0;

            tw.Write(pdfUtility.GetHeader("1.5", out size), 0, size);
            //
            filesize = size;
        }
コード例 #2
0
        /// <summary>
        /// Content object
        /// </summary>
        /// <summary>
        /// Get the Content Dictionary
        /// </summary>
        internal byte[] GetContentDict(long filePos, out int size)
        {
            // When no compression
            if (!CanCompress)
            {
                content = string.Format("\r\n{0} 0 obj<</Length {1}>>stream\r{2}\rendstream\rendobj\r",
                                        this.objectNum, contentStream.Length, contentStream);

                return(GetUTF8Bytes(content, filePos, out size));
            }

            // Try to use compression; could still fail in which case fall back to uncompressed
            Stream       strm = null;
            MemoryStream cs   = null;

            try
            {
                CompressionConfig cc = RdlEngineConfig.GetCompression();
                cs = new MemoryStream();                        // this will contain the content stream
                if (cc != null)
                {
                    strm = cc.GetStream(cs);
                }

                if (strm == null)
                {                       // can't compress string
                    cs.Close();

                    content = string.Format("\r\n{0} 0 obj<</Length {1}>>stream\r{2}\rendstream\rendobj\r",
                                            this.objectNum, contentStream.Length, contentStream);

                    return(GetUTF8Bytes(content, filePos, out size));
                }

                // Compress the contents
                int    cssize;
                byte[] ca = PdfUtility.GetUTF8Bytes(contentStream, out cssize);
                strm.Write(ca, 0, cssize);
                strm.Flush();
                cc.CallStreamFinish(strm);

                // Now output the PDF command
                MemoryStream ms = new MemoryStream();
                int          s;
                byte[]       ba;

                // get the compressed data;  we need the lenght now
                byte[] cmpData = cc.GetArray(cs);

                // write the beginning portion of the PDF object
                string ws = string.Format("\r\n{0} 0 obj<< /Filter /FlateDecode /Length {1}>>stream\r",
                                          this.objectNum, cmpData.Length);

                ba = GetUTF8Bytes(ws, filePos, out s);                  // this will also register the object
                ms.Write(ba, 0, ba.Length);
                filePos += s;

                // write the Compressed data
                ms.Write(cmpData, 0, cmpData.Length);
                filePos += ba.Length;

                // write the end portion of the PDF object
                ba = PdfUtility.GetUTF8Bytes("\rendstream\rendobj\r", out s);
                ms.Write(ba, 0, ba.Length);
                filePos += s;

                // now the final output array
                ba   = ms.ToArray();
                size = ba.Length;
                return(ba);
            }
            finally
            {
                if (strm != null)
                {
                    strm.Close();
                }
            }
        }