コード例 #1
0
        private void PrepareSizes(PdfDictionary baseData)
        {
            // Set "Times-Roman" as default basefont sizes
            _widths = PdfStandar14FontMetrics.Times_Roman.Widths;
            _height = PdfStandar14FontMetrics.Times_Roman.ApproxHeight;

            if (baseData.Values.ContainsKey("ToUnicode"))
            {
                byte[]    toUnicodeStream = ((PdfStream)baseData.Values["ToUnicode"]).Data;
                PdfParser parser          = new PdfParser(toUnicodeStream);
                _toUnicode = parser.ParseToUnicode();
            }

            string baseFont = _baseData.GetParamAsString("BaseFont");

            if (string.IsNullOrEmpty(baseFont))
            {
                SetBaseFontSizes(baseFont);
            }

            if (_baseData.Values.ContainsKey("FirstChar") && _baseData.Values.ContainsKey("LastChar") && _baseData.Values.ContainsKey("Widths"))
            {
                ParseSizes();
            }
        }
コード例 #2
0
        public PdfDocumentPage(PdfDictionary baseData, PdfDictionary resources)
        {
            _baseData = baseData;
            string type = baseData.GetParamAsString("Type");

            if (type != "Page")
            {
                throw new Exception(string.Format("PdfDocumentPage: Expected dictionary of type:\"Page\". Found: {0}", type));
            }

            // Get content, resources and fonts
            _content = _baseData.GetParamAsStream("Contents");
            if (_baseData.Values.ContainsKey("Resources") == false)
            {
                _resources = resources;
            }
            else
            {
                _resources = _baseData.Values["Resources"] as PdfDictionary;
            }
            if (_resources != null && _resources.Values.ContainsKey("Font"))
            {
                PdfDictionary fonts = _resources.Values["Font"] as PdfDictionary;
                foreach (KeyValuePair <string, IPdfElement> pair in fonts.Values)
                {
                    var font = new PdfFont(pair.Value as PdfDictionary);
                    font.Name = pair.Key;
                    _fonts.Add(pair.Key, font);
                }
            }

            // Parse content
            if (_content != null)
            {
                PdfParser parser = new PdfParser(_content);
                _contentActions = parser.ParseContent();
            }
            else
            {
                _contentActions = new List <PdfContentAction>();
            }
        }