Ejemplo n.º 1
0
        public static void Run(string outputfilename, PdfPageFormat pageFormat)
        {
            // Prepare document options:
            var options = new PdfDocumentOptions();

            options.Author     = "Arebis";
            options.Title      = "PDF Raster";
            options.Subject    = "Demonstrate Arebis.Pdf generation library.";
            options.TextFilter = new Arebis.Pdf.Common.PdfDeflateStreamFilter();
            //options.TextFilter = new Arebis.Pdf.Common.PdfASCIIHexDecodeFilter();

            // Content options:
            var graphicsOptions = new PdfGraphicsOptions(0.1, PdfColor.Black, null, PdfLineDashPattern.Small);
            var textOptions     = new PdfTextOptions(PdfPredefinedFont.Helvetica, 8, PdfColor.Black);

            // Make stream and writer objects:
            using (var stream = new FileStream(outputfilename, FileMode.Create, FileAccess.Write))
                using (var writer = new PdfDocumentWriter(stream, options))
                {
                    using (var page = writer.NewPage(pageFormat))
                    {
                        for (int x = 20; x < page.Width; x += 20)
                        {
                            page.DrawLine(x, 0, x, page.Height, graphicsOptions);
                            page.DrawText(x + 1, 101, x.ToString(), textOptions);
                        }

                        for (int y = 20; y < page.Height; y += 20)
                        {
                            page.DrawLine(0, y, page.Width, y, graphicsOptions);
                            page.DrawText(101, y - 8, y.ToString(), textOptions);
                        }
                    }
                }
        }
Ejemplo n.º 2
0
        protected void HandlePage(Page item, PdfDocumentWriter writer, Context context)
        {
            var format = PdfPageFormat.A4Portrait;

            if (!String.IsNullOrWhiteSpace(item.Format))
            {
                format = (PdfPageFormat)typeof(PdfPageFormat).GetField(item.Format).GetValue(null);
            }
            if (!String.IsNullOrWhiteSpace(item.Width) && !String.IsNullOrWhiteSpace(item.Height))
            {
                format = new PdfPageFormat(GetValue(item.Width, format.Width), GetValue(item.Height, format.Height));
            }

            var pageWriter = writer.NewPage(format);

            context                    = new Context(context);
            context.Coordinates        = GetCoordinates(pageWriter);
            context.GraphicsOptionsRef = item.GraphicsOptionsRef ?? context.GraphicsOptionsRef;
            context.TextOptionsRef     = item.TextOptionsRef ?? context.TextOptionsRef;

            if (item.CoordinateSpace != null)
            {
                context.Coordinates = new Coordinates(context.Coordinates.Physical, 0.0, 0.0, item.CoordinateSpace.Width, item.CoordinateSpace.Height);
            }

            try
            {
                // Call OnPageBegin callback:
                if (OnPageBegin != null)
                {
                    OnPageBegin(pageWriter, item);
                }

                // Dispatch page items:
                foreach (var pageItem in item.Items)
                {
                    this.Dispatch(pageItem, pageWriter, context);
                }

                // Call OnPageEnd callback:
                if (OnPageEnd != null)
                {
                    OnPageEnd(pageWriter, item);
                }
            }
            finally
            {
                pageWriter.Dispose();
            }
        }