<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>Debenu Quick PDF Library - PDF SDK Community Forum : Drawing RichText (RTF)</title>
  <link>http://www.quickpdf.org/forum/</link>
  <description><![CDATA[This is an XML content feed of; Debenu Quick PDF Library - PDF SDK Community Forum : I need help - I can help : Drawing RichText (RTF)]]></description>
  <copyright>Copyright (c) 2006-2013 Web Wiz Forums - All Rights Reserved.</copyright>
  <pubDate>Sat, 06 Jun 2026 23:50:40 +0000</pubDate>
  <lastBuildDate>Thu, 01 Sep 2011 04:55:11 +0000</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 11.01</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.quickpdf.org/forum/RSS_post_feed.asp?TID=1940</WebWizForums:feedURL>
  <image>
   <title><![CDATA[Debenu Quick PDF Library - PDF SDK Community Forum]]></title>
   <url>http://www.quickpdf.org/forum/forum_images/QPDF_Forum_Title.png</url>
   <link>http://www.quickpdf.org/forum/</link>
  </image>
  <item>
   <title><![CDATA[Drawing RichText (RTF) : I have played with some code in...]]></title>
   <link>http://www.quickpdf.org/forum/drawing-richtext-rtf_topic1940_post8259.html#8259</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.quickpdf.org/forum/member_profile.asp?PF=1483">AndrewC</a><br /><strong>Subject:</strong> 1940<br /><strong>Posted:</strong> 01 Sep 11 at 4:55AM<br /><br />I have played with some code in C# and the results were reasonable but not perfect. &nbsp;I did also attempt to move the same code to Delphi but the results were far from perfect.<div><br></div><div>Here is the C# code which should help you get started. &nbsp;Some Googling will help also.</div><div><br></div><div><div>&nbsp; &nbsp; &nbsp; &nbsp; &#091;StructLayout(LayoutKind.Sequential)&#093;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; private struct RECT</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public int Left;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public int Top;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public int Right;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public int Bottom;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &#091;StructLayout(LayoutKind.Sequential)&#093;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; private struct CHARRANGE</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public int cpMin; &nbsp; &nbsp; &nbsp; &nbsp; //First character of range (0 for start of doc)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public int cpMax; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Last character of range (-1 for end of doc)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &#091;StructLayout(LayoutKind.Sequential)&#093;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; private struct FORMATRANGE</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public IntPtr hdc; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Actual DC to draw on</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public IntPtr hdcTarget; &nbsp; &nbsp; &nbsp; //Target DC for determining text formatting</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public RECT rc; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Region of the DC to draw to (in twips)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public RECT rcPage; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Region of the whole DC (page size) (in twips)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public CHARRANGE chrg; &nbsp; &nbsp; &nbsp; &nbsp; //Range of text to draw (see earlier declaration)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; private const int WM_USER = 0x0400;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; private const int EM_FORMATRANGE = WM_USER + 57;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &#091;DllImport("USER32.dll")&#093;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; // Size RichTextBox1 to A4 format</div><div>&nbsp; &nbsp; &nbsp; &nbsp; public void RenderRTFtoPDF(string rtfFilename)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntPtr dc;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int pageNumber = 1;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int lastChar = 0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int docId;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int mainDocId = 0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int ret;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Create a new RichTextBox to use for rendering.</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // RichTextBox richTextBox1 = new RichTextBox();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // richTextBox1.Visible = false;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; richTextBox1.Left = richTextBox1.Top = 0;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; richTextBox1.Width = (int)(8.268 * 96) - 50;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; richTextBox1.Height = (int)(11.693 * 96) - 600;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; richTextBox1.LoadFile(rtfFilename);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; do</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; QP.SetMeasurementUnits(1);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // get a virtual device context size at A4</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //dc = (IntPtr)QP.GetCanvasDC(richTextBox1.Width * 96, richTextBox1.Height * 96); &nbsp;// 1 point = 20 twips</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //dc = (IntPtr)QP.GetCanvasDC((int)(595 * 1.37), (int)(842 * 1.37)); &nbsp;// 1 point = 20 twips</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dc = (IntPtr)QP.GetCanvasDC((int)(8.27 * 96), (int)(11.70 * 96)); &nbsp;// 1 point = 20 twips</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // print the rtfbox</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lastChar = RenderRTF(dc, richTextBox1, lastChar);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //generate a new document</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret = QP.LoadFromCanvasDC(96, 3);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret = docId = QP.SelectedDocument();</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (pageNumber == 1)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainDocId = docId;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret = QP.SelectDocument(mainDocId);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ret = QP.MergeDocument(docId);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pageNumber++;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while (lastChar != 0 &amp;&amp; lastChar != -1);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; int RenderRTF(IntPtr dc, RichTextBox rtf, int FirstChar)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RECT &nbsp; &nbsp; &nbsp; &nbsp;RcDrawTo;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RECT &nbsp; &nbsp; &nbsp; &nbsp;RcPage;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FORMATRANGE fr;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int scale = 36;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int nextCharPosition;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RcPage.Left = 0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RcPage.Right = (rtf.Left + rtf.Width) * scale;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RcPage.Top = 0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RcPage.Bottom = (rtf.Top + rtf.Height) * scale;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //RcPage.Right /= 8;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //RcPage.Bottom /= 8;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RcDrawTo.Left = (rtf.Left) * scale;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RcDrawTo.Top = (rtf.Top) * scale;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RcDrawTo.Right = (rtf.Left + rtf.Width) * scale;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RcDrawTo.Bottom = (rtf.Top + rtf.Height) * scale;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fr.hdc = dc;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fr.hdcTarget = dc;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fr.rc = RcDrawTo;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fr.rcPage = RcPage;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fr.chrg.cpMin = FirstChar;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fr.chrg.cpMax = -1;</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntPtr res = IntPtr.Zero;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntPtr wparam = IntPtr.Zero;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wparam = new IntPtr(1);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Get the pointer to the FORMATRANGE structure in memory</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IntPtr lparam = IntPtr.Zero;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fr));</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Marshal.StructureToPtr(fr, lparam, false);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res = SendMessage(rtf.Handle, EM_FORMATRANGE, wparam, lparam);</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nextCharPosition = res.ToInt32();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (nextCharPosition &lt; rtf.TextLength)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return nextCharPosition;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; private void button23_Click(object sender, EventArgs e)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RenderRTFtoPDF("Overview.rtf");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; QP.SaveToFile("Overview.pdf");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div></div><div><br></div><div><br></div><div><br></div>]]>
   </description>
   <pubDate>Thu, 01 Sep 2011 04:55:11 +0000</pubDate>
   <guid isPermaLink="true">http://www.quickpdf.org/forum/drawing-richtext-rtf_topic1940_post8259.html#8259</guid>
  </item> 
  <item>
   <title><![CDATA[Drawing RichText (RTF) : Does anyone know of any code that...]]></title>
   <link>http://www.quickpdf.org/forum/drawing-richtext-rtf_topic1940_post8258.html#8258</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.quickpdf.org/forum/member_profile.asp?PF=872">waynefulcher</a><br /><strong>Subject:</strong> 1940<br /><strong>Posted:</strong> 30 Aug 11 at 3:37PM<br /><br />Does anyone know of any code that could parse richtext and convert that to drawing commands which could be used to call methods in the QuickPDF&nbsp;library to output the richtext to PDF?<DIV>I am using Delphi 7 but really if anyone has any code in pretty much any language I can convert it to delphi. What would really be nice is if QuickPDF had a method something like:</DIV><DIV>&nbsp;</DIV><DIV>PDF.DrawRichText(top, left, richtext) ;</DIV><DIV>&nbsp;</DIV><DIV>Any help or direction for me to look would be awesome. I just don't want to start from scratch by writing my own RTF parser if I don't have to.</DIV><DIV>&nbsp;</DIV><DIV>Thanks</DIV><DIV>Wayne</DIV>]]>
   </description>
   <pubDate>Tue, 30 Aug 2011 15:37:28 +0000</pubDate>
   <guid isPermaLink="true">http://www.quickpdf.org/forum/drawing-richtext-rtf_topic1940_post8258.html#8258</guid>
  </item> 
 </channel>
</rss>