diff --git a/PROMS/Volian.Print.Library/Rtf2Pdf.cs b/PROMS/Volian.Print.Library/Rtf2Pdf.cs index 1f802f16..87a4ba1a 100644 --- a/PROMS/Volian.Print.Library/Rtf2Pdf.cs +++ b/PROMS/Volian.Print.Library/Rtf2Pdf.cs @@ -52,7 +52,6 @@ namespace Volian.Print.Library // Close the document document.Close(); } - private static void SampleParagraphs(Paragraph para, PdfContentByte cb, float yTop, float width, float x) { while (yTop > 0) @@ -79,66 +78,59 @@ namespace Volian.Print.Library { VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper; PdfLayer textLayer = _MyPageHelper == null ? null : _MyPageHelper.TextLayer; - if (textLayer != null) cb.BeginLayer(textLayer); float left = x + Offset.X; float top = y + Offset.Y; float right = left + width; float bottom = top - height; ColumnText myColumnText = new ColumnText(cb); - //myColumnText.SetSimpleColumn(left, top, left + width, top - height); - myColumnText.SetSimpleColumn(left, top, left + width, 36); // Bottom margin - //myColumnText.YLine -= 10; - //float yOff = pp.Font.BaseFont.GetAscentPoint("Almg", pp.Font.Size); - //myColumnText.YLine = -yOff; + myColumnText.SetSimpleColumn(left, top, left + width,36); // Bottom margin myColumnText.AddElement(iParagraph); - float pos = myColumnText.YLine; - //myColumnText.UseAscender = true;// Adjusts to the top of the text box. - // go processing it and if it fits, nothing to be processed is in mycolumntext. + float pos = myColumnText.YLine; // Save the position to be used if the paragraph fits int status = myColumnText.Go(true); // Check to see if it will fit on the page. if (ColumnText.HasMoreText(status)) - return 0;// Won't fit return 0; - myColumnText.YLine = pos; // location on page + return 0;// Paragraph won't fit. Return 0; + myColumnText.YLine = pos; // restore the location on the page myColumnText.AddElement(iParagraph); // add in paragraph - myColumnText.Go(false); - //float textHeight = pp.Leading * myColumnText.LinesWritten; - //Console.WriteLine("Calculated Bottom {0}, YLine {1}", top - textHeight, myColumnText.YLine); - //BoxText(cb, System.Drawing.Color.BurlyWood, left, top, left + width, top - height); - //BoxText(canvas, System.Drawing.Color.CadetBlue, left, top, left + width, top - textHeight); + if (textLayer != null) cb.BeginLayer(textLayer); + myColumnText.Go(false); // Draw the paragraph if (textLayer != null) cb.EndLayer(); - + // Approximate Descent by using Leading divided by 5. + float yDescent = iParagraph.Leading / 5; + // If the BaseFont is available, calculate yAdj on the basis of the Descent + if (iParagraph.Font.BaseFont != null) + yDescent = -iParagraph.Font.BaseFont.GetDescentPoint("Almg", iParagraph.Font.Size); if (PdfDebug) - DrawPdfDebug(cb, System.Drawing.Color.CadetBlue, left, top, left + width, myColumnText.YLine, debugText); - //Console.WriteLine("Lines = {0}", myColumnText.LinesWritten); + DrawPdfDebug(cb, System.Drawing.Color.CadetBlue, left, top, left + width, myColumnText.YLine, debugText,yDescent); return myColumnText.YLine; - } - private static void DrawPdfDebug(PdfContentByte cb, System.Drawing.Color sysColor, float left, float top, float right, float bottom, string debugText) + private static void DrawPdfDebug(PdfContentByte cb, System.Drawing.Color sysColor, float left, float top, float right, float bottom, string debugText, float yDescent) { - float yAdj = 3; + // yAdj is dependent on the size of the font and the spacing between lines. cb.SaveState(); VlnSvgPageHelper _MyPageHelper = cb.PdfWriter.PageEvent as VlnSvgPageHelper; PdfLayer debugLayer = _MyPageHelper == null ? null : _MyPageHelper.DebugLayer; if (debugLayer != null) cb.BeginLayer(debugLayer); cb.SetColorStroke(new Color(sysColor)); cb.SetLineWidth(.1F); - cb.MoveTo(left, top - yAdj); - cb.LineTo(right, top - yAdj); - cb.LineTo(right, bottom - yAdj); - cb.LineTo(left, bottom - yAdj); - cb.LineTo(left, top - yAdj); + cb.MoveTo(left, top - yDescent); + cb.LineTo(right, top - yDescent); + cb.LineTo(right, bottom - yDescent); + cb.LineTo(left, bottom - yDescent); + cb.LineTo(left, top - yDescent); cb.Stroke(); - ColumnText ct = new ColumnText(cb); - ct.SetSimpleColumn(left, 4 + top - yAdj, right, top - yAdj - 50); - iTextSharp.text.Font font = FontFactory.GetFont("Arial", 2); - Chunk chk = new Chunk(debugText, font); - Phrase ph = new Phrase(chk); - ct.AddElement(ph); - cb.SetColorFill(new Color(sysColor)); - ct.Go(); + if (debugText != "") + { + ColumnText ct = new ColumnText(cb); + ct.SetSimpleColumn(left, 4 + top - yDescent, right, top - yDescent - 50); + iTextSharp.text.Font font = FontFactory.GetFont("Arial", 2); + Chunk chk = new Chunk(debugText, font); + Phrase ph = new Phrase(chk); + ct.AddElement(ph); + cb.SetColorFill(new Color(sysColor)); + ct.Go(); + } if (debugLayer != null) cb.EndLayer(); cb.RestoreState(); } - - } }