Exemple #1
0
        public void PrintElement(BasicElement element, PdfDocument pdf, PdfStream pdfStream)
        {
            var type = element.GetType();

            var adapter = new PdfStreamAdapter(pdfStream, defaultFont);

            if (type == typeof (Text))
            {
                adapter.PrintText((Text) element);
            }
            else if (type == typeof (Expression))
            {
                adapter.PrintExpression((Expression) element);
            }
            else if (type == typeof (Image))
            {
                adapter.PrintImage((Image) element);
            }
            else if (type == typeof (Rectangle))
            {
                adapter.PrintRectangle((Rectangle) element);
            }
            else if (type == typeof (Bookmark))
            {
                PrintBookmark((Bookmark) element, pdf);
            }
        }
Exemple #2
0
        public PdfPage(int number, string resourcesRef, PdfStream content, int width, int height)
            : base(number)
        {
            this.resourcesRef = resourcesRef;
            this.width = width;
            this.height = height;

            Content = content;
        }
Exemple #3
0
        public override int Output(Stream stream)
        {
            var length = 0;

            var imgData = new PdfStream(0);
            imgData.AddData(Image.GetBitmaps());

            //apply filters if any
            if (Image.Filter != null) imgData.AddFilter(Image.Filter);

            var strFilters = imgData.ApplyFilters();

            var sb = new StringBuilder();

            sb.Append(Number);
            sb.Append(" ");
            sb.Append(Generation);
            sb.Append(" obj\n<< /Type /XObject\n/Subtype /Image\n/Name /Im");
            sb.Append(imgnumber);

            sb.Append("\n/Length ");
            sb.Append(imgData.Length);
            sb.Append("\n/Width ");
            sb.Append(Image.Width);
            sb.Append("\n/Height ");
            sb.Append(Image.Height);
            sb.Append("\n/BitsPerComponent ");
            sb.Append(Image.BitsPerPixel);
            sb.Append("\n/ColorSpace ");
            sb.Append(Image.ColorSpace.GetRepresentation());

            if (Image.IsAdobe && Image.ColorSpace.ColorDevice == ColorDevice.DeviceCMYK)
            {
                //photoShop CMYK values are inverted
                sb.Append("\n/Decode [ 1.0 0.0 1.0 0.0 1.0 0.0 1.1 0.0 ]\n");
            }

            sb.Append("\n");
            sb.Append(strFilters);
            sb.Append(">>\n");

            var encoder = new ASCIIEncoding();

            var bt = encoder.GetBytes(sb.ToString());
            stream.Write(bt, 0, bt.Length);
            stream.Flush();
            length += bt.Length;

            length += imgData.outputPDFStream(stream);
            bt = encoder.GetBytes("endobj\n");
            stream.Write(bt, 0, bt.Length);
            stream.Flush();
            length += bt.Length;
            return length;
        }
Exemple #4
0
        private PdfStream MakeStream()
        {
            var ps = new PdfStream(++objectcounter);
            trailer.Add(ps);

            return ps;
        }
 public PdfStreamAdapter(PdfStream pdfStream, string defaultFont)
 {
     this.pdfStream = pdfStream;
     this.defaultFont = defaultFont;
 }