﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Re-invent ASP.NET Hosting Community / Web Site Development / Design / ASP.NET 1.1 Hosting Discussion  / ABCpdf AddImageUrl method / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>Re-invent ASP.NET Hosting Community</description><link>http://community.re-invent.com/</link><webMaster>community@re-invent.com</webMaster><lastBuildDate>Tue, 06 Jan 2009 08:26:07 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: ABCpdf AddImageUrl method</title><link>http://community.re-invent.com/Topic266-2-1.aspx</link><description>&lt;P&gt;The HTML conversion program I made takes an HTML page with some additional attributes on the TD elements and converts it to a PDF using ABCpdf without using the AddImageUrl method and staying within the security settings of the server.&lt;/P&gt;&lt;P&gt;Basically it loads the file into an XmlDocument (after converting '&amp;amp;nbsp;' to string.Empty since XmlDocument does not understand that string) and iterates over the nodes.  The assumption is that the bulk of the page is a table that describes the pdf document layout.  Since the file is p****d top to bottom, the 'TopDown' attribute of ABCpdf must be set to true.  Then it looks for a table node (only one was needed for my solution) and iterates over the tr then td nodes.  I also needed the ability to set the background color (for the 'paper' of my pdf).  Important portions of the code are below.&lt;/P&gt;&lt;P&gt;P****Style extracts information from a 'style' property of the element.  The 'GetSafe...Attribute' methods encapsulate the handling of the attribute not existing and the last parameter is the default value to use in that case.  The 'Convert...' methods are used to translate the english words displayed by the user into hex values - this could be accomplished as the value of the select elements, but I needed some additional flexibilty fo the integration I was performing with another site (&lt;a target=_blank href="http://www.misterpaddy.com"&gt;www.misterpaddy.com&lt;/A&gt;).  I used the 'AddHtml' method to allow for editing of text by the user with font size and color information in HTML format (similar to the editor used for posting on this forum).&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;After the XmlDocument xmlDocument was loaded and the ABCpdf Doc doc was created:&lt;/P&gt;&lt;P&gt;doc.TopDown = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;true&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;/P&gt;&lt;P&gt;XmlNode tableNode = xmlDocument.SelectSingleNode("//table");&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;FONT size=2&gt; (tableNode != &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;cellpadding = GetSafeIntAttribute("cellpadding", tableNode, 0);&lt;/P&gt;&lt;P&gt;cellspacing = GetSafeIntAttribute("cellspacing", tableNode, 0);&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; pageWidth = GetSafeIntAttribute("width", tableNode, -1);&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;int&lt;/FONT&gt;&lt;FONT size=2&gt; pageHeight = GetSafeIntAttribute("height", tableNode, -1);&lt;/P&gt;&lt;P&gt;doc.MediaBox.Width = pageWidth;&lt;/P&gt;&lt;P&gt;doc.MediaBox.Height = pageHeight;&lt;/P&gt;&lt;P&gt;doc.Rect.String = doc.MediaBox.String;&lt;/P&gt;&lt;P&gt;doc.Color.String = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;FONT size=2&gt;.ConvertHexToByteString(ConvertNamedColorsToHex(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;FONT size=2&gt;.ddlPaperColor.SelectedItem.ToString()));&lt;/P&gt;&lt;P&gt;doc.FillRect(); //Sets the 'paper' color&lt;/P&gt;&lt;P&gt;style = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;FONT size=2&gt;.GetSafeStringAttribute("style", tableNode, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt;.Empty);&lt;/P&gt;&lt;P&gt;P****Style(style, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; backgroundImage, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; height, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; width, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; fontSize, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; bold, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; color, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; italic, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; fontFamily, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; backgroundColor, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; underline, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; strikeOut, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; overline, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; superScript, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; subScript, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; lineBottom);&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;foreach&lt;/FONT&gt;&lt;FONT size=2&gt;(XmlNode trNode &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;in&lt;/FONT&gt;&lt;FONT size=2&gt; tableNode.SelectNodes("tr"))&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;//Set defaults&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;currentX = 0; //Used to determine the current left side of the Rect&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt; vAlign = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;FONT size=2&gt;.GetSafeStringAttribute("valign", trNode, "top");&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;string&lt;/FONT&gt;&lt;FONT size=2&gt; backgroundColorTr = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;FONT size=2&gt;.GetSafeStringAttribute("bgcolor", trNode, backgroundColor);&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;double&lt;/FONT&gt;&lt;FONT size=2&gt; trHeight = 0;&lt;/P&gt;&lt;P&gt;doc.Rect.Top = currentY;&lt;/P&gt;&lt;P&gt;currentY += trHeight;&lt;/P&gt;&lt;P&gt;doc.Rect.Bottom = currentY;&lt;/P&gt;&lt;P&gt;doc.FontSize = fontSize;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;foreach&lt;/FONT&gt;&lt;FONT size=2&gt;(XmlNode tdNode &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;in&lt;/FONT&gt;&lt;FONT size=2&gt; trNode.SelectNodes("td"))&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;FONT size=2&gt; (vAlign == "top")&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;doc.VPos = 0.0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;else&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;if&lt;/FONT&gt;&lt;FONT size=2&gt; (vAlign == "middle")&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;doc.VPos = 0.5;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;else&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;doc.VPos = 1.0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;doc.AddHtml(textOut);&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;The rest of the method loads any images referenced by 'img' tags and converts them to one of two colors (I needed to allow two printing inks only).&lt;/P&gt;&lt;P&gt;If you have any questions I'd be happy to answer them in this forum.&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;</description><pubDate>Wed, 22 Mar 2006 16:11:00 GMT</pubDate><dc:creator>Rodney</dc:creator></item><item><title>RE: ABCpdf AddImageUrl method</title><link>http://community.re-invent.com/Topic266-2-1.aspx</link><description>&lt;P&gt;I was afraid you would say that.  When I complete the HTML p****r for translating HTML documents to PDF with ABCpdf without using the AddImageUrl method, I'll post some comments about how it works here.&lt;/P&gt;&lt;P&gt;Thanks for the quick reply!&lt;/P&gt;</description><pubDate>Mon, 13 Mar 2006 14:14:00 GMT</pubDate><dc:creator>Rodney</dc:creator></item><item><title>RE: ABCpdf AddImageUrl method</title><link>http://community.re-invent.com/Topic266-2-1.aspx</link><description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Unfortunately, at this time the security policy in place prevents the AddImageUrl method of ABCPdf. &lt;/P&gt;</description><pubDate>Mon, 13 Mar 2006 13:59:00 GMT</pubDate><dc:creator>Re-invent (Nick)</dc:creator></item><item><title>ABCpdf AddImageUrl method</title><link>http://community.re-invent.com/Topic266-2-1.aspx</link><description>&lt;P&gt;Before I get too far along in developing a solution, I need to know if the AddImageUrl method of ABCpdf is permitted on these servers?  The security settings have to be relaxed enough to allow it (that's all I know at this point).  &lt;/P&gt;&lt;P&gt;If not, I will have to complete the HTML rendering engine I'm working on, but this would save me hours of effort.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description><pubDate>Mon, 13 Mar 2006 13:45:00 GMT</pubDate><dc:creator>Rodney</dc:creator></item></channel></rss>