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(); } }
/** * render inline area to PDF * * @param area inline area to render */ public void RenderWordArea(WordArea area) { FontState fontState = area.GetFontState(); String name = fontState.FontName; int size = fontState.FontSize; // This assumes that *all* CIDFonts use a /ToUnicode mapping Font font = (Font)fontState.FontInfo.GetFontByName(name); if ((!name.Equals(this.currentFontName)) || (size != this.currentFontSize)) { CloseText(); this.currentFontName = name; this.currentFontSize = size; currentStream.SetFont(name, size); } // Do letter spacing (must be outside of [...] TJ] float letterspacing = ((float)fontState.LetterSpacing) / 1000f; if (letterspacing != this.currentLetterSpacing) { this.currentLetterSpacing = letterspacing; CloseText(); //? currentStream.SetLetterSpacing(letterspacing); } //-------------------------------------------- PdfColor?a_color = this.currentFill; PdfColor areaObj_color = area.GetColor(); if (a_color == null || !areaObj_color.IsEq(a_color.Value)) { //change area color a_color = areaObj_color; CloseText(); //? this.currentFill = a_color; currentStream.SetFontColor(a_color.Value); } //-------------------------------------------- int rx = this.currentXPosition; int bl = this.currentYPosition; int areaContentW = area.getContentWidth(); if (area.getUnderlined()) { AddUnderLine(rx, bl, areaContentW, size, a_color.Value); } if (area.getOverlined()) { AddOverLine(rx, bl, areaContentW, size, fontState.Ascender, a_color.Value); } if (area.getLineThrough()) { AddLineThrough(rx, bl, areaContentW, size, fontState.Ascender, a_color.Value); } //-------------------------------------------- _textPrinter.Reset(fontState, options != null && options.Kerning); if (!textOpen || bl != prevWordY) { CloseText(); //set text matrix _textPrinter.SetTextPos(rx, bl); //pdf.Append("1 0 0 1 " + PdfNumber.doubleOut(rx / 1000f) + // " " + PdfNumber.doubleOut(bl / 1000f) + " Tm [" + startText); prevWordY = bl; textOpen = true; //*** } else { // express the space between words in thousandths of an em int space = prevWordX - rx + prevWordWidth; float emDiff = (float)space / (float)currentFontSize * 1000f; // this prevents a problem in Acrobat Reader where large // numbers cause text to disappear or default to a limit if (emDiff < -33000) { CloseText(); _textPrinter.SetTextPos(rx, bl); //pdf.Append("1 0 0 1 " + PdfNumber.doubleOut(rx / 1000f) + // " " + PdfNumber.doubleOut(bl / 1000f) + " Tm [" + startText); textOpen = true;//*** } else { _textPrinter.SetEmDiff(emDiff); //pdf.Append(PdfNumber.doubleOut(emDiff)); //pdf.Append(" "); //pdf.Append(startText); } } prevWordWidth = areaContentW; prevWordX = rx; string s = area.GetTextContent(); if (area is PageNumberInlineArea) { //need to resolve to page number s = idReferences.getPageNumber(s); } _textPrinter.WriteText(s); //------- _textPrinter.PrintContentTo(currentStream); //------- this.currentXPosition += area.getContentWidth(); }