Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            string outputFilename = "bin\\output.pdf";

            using (FileStream outputStream = new FileStream(outputFilename, FileMode.Create, FileAccess.Write))
            {
                //----------------
                PdfCreator pdfCreator = new PdfCreator(outputStream);

                PdfResources     pdfRes        = pdfCreator.GetResources();
                PdfContentStream contentStream = pdfCreator.MakeContentStream();
                //----------------
                Fonet.Layout.FontInfo fontInfo = new Fonet.Layout.FontInfo();
                var fontSetup = new Fonet.Render.Pdf.FontSetup(
                    fontInfo, Fonet.Render.Pdf.FontType.Link);

                Fonet.Layout.FontState fontState = new Fonet.Layout.FontState(
                    fontInfo, "sans-serif", "normal",
                    "normal", 18000,
                    52);
                //----------------
                pdfCreator.OutputHeader();
                //----------------

                //simple page
                contentStream.BeginTextObject();
                contentStream.SetFont("F1", 18 * 1000);
                contentStream.SetFontColor(new Fonet.PdfColor(0, 0, 0));
                //----------------
                Fonet.Layout.TextPrinter textPrinter = new Fonet.Layout.TextPrinter();
                textPrinter.Reset(fontState, false);
                textPrinter.SetTextPos(100 * 1000, 100 * 1000);
                textPrinter.WriteText("Hello World!");
                textPrinter.PrintContentTo(contentStream);
                contentStream.CloseText();
                //----------------

                contentStream.DrawLine(0 * 1000, 0 * 1000, 70 * 1000, 50 * 1000,
                                       1 * 1000,
                                       new Fonet.PdfColor(255, 0, 0));


                contentStream.EndTextObject();
                //----------------
                int     w    = 800;
                int     h    = 600;
                PdfPage page = pdfCreator.MakePage(pdfRes, contentStream,
                                                   w,
                                                   h,
                                                   new string[0]);


                fontSetup.AddToResources(new PdfFontCreator(pdfCreator), pdfRes);
                pdfCreator.OutputTrailer();
                //----------------
                outputStream.Flush();
                outputStream.Close();
            }
        }
Exemplo n.º 2
0
        /**
         * render page into PDF
         *
         * @param page page to render
         */

        public void RenderPage(Page page)
        {
            BodyAreaContainer body;
            AreaContainer     before, after, start, end;

            currentStream = this.pdfCreator.MakeContentStream();
            body          = page.getBody();
            before        = page.getBefore();
            after         = page.getAfter();
            start         = page.getStart();
            end           = page.getEnd();

            this.currentFontName      = "";
            this.currentFontSize      = 0;
            this.currentLetterSpacing = Single.NaN;

            currentStream.BeginTextObject();

            RenderBodyAreaContainer(body);

            if (before != null)
            {
                RenderAreaContainer(before);
            }

            if (after != null)
            {
                RenderAreaContainer(after);
            }

            if (start != null)
            {
                RenderAreaContainer(start);
            }

            if (end != null)
            {
                RenderAreaContainer(end);
            }
            CloseText();

            // Bug fix for issue 1823
            this.currentLetterSpacing = Single.NaN;

            float w = page.getWidth();
            float h = page.GetHeight();

            currentStream.EndTextObject();

            var idList = new System.Collections.Generic.List <string>();

            foreach (string id in page.getIDList())
            {
                idList.Add(id);
            }

            currentPage = this.pdfCreator.MakePage(
                this.pdfResources, currentStream,
                Convert.ToInt32(Math.Round(w / 1000)),
                Convert.ToInt32(Math.Round(h / 1000)), idList.ToArray());

            if (page.hasLinks() || currentAnnotList != null)
            {
                if (currentAnnotList == null)
                {
                    currentAnnotList = this.pdfCreator.MakeAnnotList();
                }
                currentPage.SetAnnotList(currentAnnotList);

                ArrayList lsets = page.getLinkSets();
                foreach (LinkSet linkSet in lsets)
                {
                    linkSet.align();
                    String    dest     = linkSet.getDest();
                    LinkKind  linkType = linkSet.getLinkType();
                    ArrayList rsets    = linkSet.getRects();
                    foreach (LinkedRectangle lrect in rsets)
                    {
                        currentAnnotList.Add(
                            this.pdfCreator.MakeLink(lrect.getRectangle(),
                                                     dest, linkType).GetReference());
                    }
                }
                currentAnnotList = null;
            }
            else
            {
                // just to be on the safe side
                currentAnnotList = null;
            }

            // ensures that color is properly reset for blocks that carry over pages
            this.currentFill = null;
        }
Exemplo n.º 3
0
        /**
         * render a foreign object area
         */

        public void RenderForeignObjectArea(ForeignObjectArea area)
        {
            // if necessary need to scale and align the content
            this.currentXPosition = this.currentXPosition + area.getXOffset();
            // TODO: why was this here? this.currentYPosition = this.currentYPosition;
            switch (area.getAlign())
            {
            case TextAlign.START:
                break;

            case TextAlign.END:
                break;

            case TextAlign.CENTER:
            case TextAlign.JUSTIFY:
                break;
            }
            switch (area.getVerticalAlign())
            {
            case VerticalAlign.BASELINE:
                break;

            case VerticalAlign.MIDDLE:
                break;

            case VerticalAlign.SUB:
                break;

            case VerticalAlign.SUPER:
                break;

            case VerticalAlign.TEXT_TOP:
                break;

            case VerticalAlign.TEXT_BOTTOM:
                break;

            case VerticalAlign.TOP:
                break;

            case VerticalAlign.BOTTOM:
                break;
            }
            CloseText();

            // in general the content will not be text
            currentStream.EndTextObject();
            // align and scale
            currentStream.SaveGraphicsState();
            switch (area.scalingMethod())
            {
            case Scaling.UNIFORM:
                break;

            case Scaling.NON_UNIFORM:
                break;
            }
            // if the overflow is auto (default), scroll or visible
            // then the contents should not be clipped, since this
            // is considered a printing medium.
            switch (area.getOverflow())
            {
            case Overflow.VISIBLE:
            case Overflow.SCROLL:
            case Overflow.AUTO:
                break;

            case Overflow.HIDDEN:
                break;
            }

            area.getObject().render(this);
            currentStream.RestoreGraphicsState();
            currentStream.BeginTextObject();
            this.currentXPosition += area.getEffectiveWidth();
            // this.currentYPosition -= area.getEffectiveHeight();
        }