{"id":1494,"date":"2015-04-11T21:15:55","date_gmt":"2015-04-12T01:15:55","guid":{"rendered":"http:\/\/andrewpallant.ca\/wordpress\/?p=1494"},"modified":"2015-04-11T21:20:06","modified_gmt":"2015-04-12T01:20:06","slug":"html-to-pdf","status":"publish","type":"post","link":"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/","title":{"rendered":"HTML to PDF"},"content":{"rendered":"<p>Have you ever wanted a function to convert HTML to PDF?  It is really easy.  A good use of this is when you have a resume  on your website and you want to create a download of it as a PDF.  Mind you; you will have to properly format your resume so it looks good in both cases.  Not the easiest job, but totally worth while to have a resume download created on demand.<!--more--><\/p>\n<p>I just created a genPDF.aspx file that takes a URL and makes it to a PDF.  Put a button on the page and have it call the genPDF.aspx page.  Your download will automatically be created and pushed through to the browser.<\/p>\n<p>Some things you will need first is a download of some zip files.  You can get them from my <a href=\"http:\/\/www.ldndeveloper.com\/Lib\/iTextSharp.zip\" title=\"iTextSharp\" target=\"_blank\">website<\/a> or you can seek them out on sourceforge ( <a href=\"http:\/\/sourceforge.net\/projects\/itextsharp\/\" title=\"iTextSharp\" target=\"_blank\">iTextSharp<\/a> \/ <a href=\"http:\/\/sourceforge.net\/projects\/itextsharp\/files\/xmlworker\/xmlworker-5.5.5\/\" title=\"iTextSharp - XML Worker\" target=\"_blank\">xmlworker<\/a> ).<\/p>\n<p>There is a lot of examples of how to do this; however, most examples do not support linked CSS files.  My example does support linked CSS files.  <\/p>\n<p>The code is very simple:<\/p>\n<pre  style=\"font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;padding:0px;color:#000000;text-align:left;line-height:20px;\"><code style=\"color:#000000;word-wrap:normal;\"> \r\n     Document document = new Document();  \r\n     try  \r\n     {  \r\n       var oStream = new MemoryStream();  \r\n       PdfWriter writer = PdfWriter.GetInstance(document, oStream);  \r\n       document.Open();  \r\n       document.AddHeader(\"Content-Disposition\", \"attachment; filename=resume.pdf\");  \r\n       WebClient wc = new WebClient();  \r\n       string htmlText = wc.DownloadString(\"http:\/\/ldndeveloper.com\/resume\/resume.aspx\");  \r\n       iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, new StringReader(htmlText));  \r\n       document.Close();  \r\n       Response.ClearContent();  \r\n       Response.ClearHeaders();  \r\n       Response.AppendHeader(\"Content-Type\", \"application\/pdf\");  \r\n       Response.AppendHeader(\"Content-Disposition\", \"attachment;filename=andrew_pallant_resume2015.pdf\");  \r\n       Response.OutputStream.Write(oStream.GetBuffer(), 0, oStream.GetBuffer().Length);  \r\n       Response.End();  \r\n     }  \r\n     catch(Exception ex)  \r\n     {  \r\n       Response.Write(ex.StackTrace);  \r\n     }  \r\n\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever wanted a function to convert HTML to PDF? It is really easy. A good use of this is when you have a resume on your website and you want to create a download of it as a PDF. Mind you; you will have to properly format your resume so it looks good &hellip; <a href=\"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">HTML to PDF<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,14,141,60,96],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>HTML to PDF - Software Developer In London<\/title>\r\n<meta name=\"description\" content=\"Have you ever wanted a function to convert HTML to PDF? A good use of this is when you have a resume on your website and you want to create a download of it as a PDF.\" \/>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"HTML to PDF - Software Developer In London\" \/>\r\n<meta property=\"og:description\" content=\"Have you ever wanted a function to convert HTML to PDF? A good use of this is when you have a resume on your website and you want to create a download of it as a PDF.\" \/>\r\n<meta property=\"og:url\" content=\"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/\" \/>\r\n<meta property=\"og:site_name\" content=\"LDNDeveloper\" \/>\r\n<meta property=\"article:published_time\" content=\"2015-04-12T01:15:55+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2015-04-12T01:20:06+00:00\" \/>\r\n<meta name=\"author\" content=\"ldnDeveloper\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<meta name=\"twitter:creator\" content=\"@LdnDeveloper\" \/>\r\n<meta name=\"twitter:site\" content=\"@LdnDeveloper\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ldnDeveloper\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/\"},\"author\":{\"name\":\"ldnDeveloper\",\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\"},\"headline\":\"HTML to PDF\",\"datePublished\":\"2015-04-12T01:15:55+00:00\",\"dateModified\":\"2015-04-12T01:20:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/\"},\"wordCount\":182,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\"},\"articleSection\":[\"C#\",\"C-Sharp\",\"Developement\",\"PDF\",\"Web\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/\",\"url\":\"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/\",\"name\":\"HTML to PDF - Software Developer In London\",\"isPartOf\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#website\"},\"datePublished\":\"2015-04-12T01:15:55+00:00\",\"dateModified\":\"2015-04-12T01:20:06+00:00\",\"description\":\"Have you ever wanted a function to convert HTML to PDF? A good use of this is when you have a resume on your website and you want to create a download of it as a PDF.\",\"breadcrumb\":{\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/andrewpallant.ca\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"HTML to PDF\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#website\",\"url\":\"https:\/\/andrewpallant.ca\/wordpress\/\",\"name\":\"LDNDeveloper\",\"description\":\"Learning, Growing and Sharing.\",\"publisher\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/andrewpallant.ca\/wordpress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84\",\"name\":\"ldnDeveloper\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg\",\"contentUrl\":\"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg\",\"width\":512,\"height\":512,\"caption\":\"ldnDeveloper\"},\"logo\":{\"@id\":\"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/\"},\"description\":\"Andrew Pallant (@LdnDeveloper) has been a web, database and desktop developer for over 16 years. Andrew has worked on projects that ranged from factory automation to writing business applications. Most recently he has been heavily involved in various forms for ecommerce projects. Over the years Andrew has worn many hats: Project Manager, IT Manager, Lead Developer, Supervisor of Developers and many more - See more at: http:\/\/www.unlatched.com\/#sthash.8DiTkpKy.dpuf\",\"sameAs\":[\"http:\/\/www.andrewpallant.ca\",\"https:\/\/x.com\/LdnDeveloper\"],\"url\":\"http:\/\/andrewpallant.ca\/wordpress\/author\/ldndeveloper\/\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"HTML to PDF - Software Developer In London","description":"Have you ever wanted a function to convert HTML to PDF? A good use of this is when you have a resume on your website and you want to create a download of it as a PDF.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/","og_locale":"en_US","og_type":"article","og_title":"HTML to PDF - Software Developer In London","og_description":"Have you ever wanted a function to convert HTML to PDF? A good use of this is when you have a resume on your website and you want to create a download of it as a PDF.","og_url":"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/","og_site_name":"LDNDeveloper","article_published_time":"2015-04-12T01:15:55+00:00","article_modified_time":"2015-04-12T01:20:06+00:00","author":"ldnDeveloper","twitter_card":"summary_large_image","twitter_creator":"@LdnDeveloper","twitter_site":"@LdnDeveloper","twitter_misc":{"Written by":"ldnDeveloper","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/#article","isPartOf":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/"},"author":{"name":"ldnDeveloper","@id":"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84"},"headline":"HTML to PDF","datePublished":"2015-04-12T01:15:55+00:00","dateModified":"2015-04-12T01:20:06+00:00","mainEntityOfPage":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/"},"wordCount":182,"commentCount":0,"publisher":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84"},"articleSection":["C#","C-Sharp","Developement","PDF","Web"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/#respond"]}]},{"@type":"WebPage","@id":"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/","url":"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/","name":"HTML to PDF - Software Developer In London","isPartOf":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/#website"},"datePublished":"2015-04-12T01:15:55+00:00","dateModified":"2015-04-12T01:20:06+00:00","description":"Have you ever wanted a function to convert HTML to PDF? A good use of this is when you have a resume on your website and you want to create a download of it as a PDF.","breadcrumb":{"@id":"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/andrewpallant.ca\/wordpress\/html-to-pdf\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/andrewpallant.ca\/wordpress\/"},{"@type":"ListItem","position":2,"name":"HTML to PDF"}]},{"@type":"WebSite","@id":"https:\/\/andrewpallant.ca\/wordpress\/#website","url":"https:\/\/andrewpallant.ca\/wordpress\/","name":"LDNDeveloper","description":"Learning, Growing and Sharing.","publisher":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/andrewpallant.ca\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/f6f5bb1ac3e0c5a54a8b5ce35fd67b84","name":"ldnDeveloper","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg","contentUrl":"https:\/\/andrewpallant.ca\/wordpress\/wp-content\/uploads\/2017\/05\/cropped-AAEAAQAAAAAAAAXQAAAAJDQxMGRlMzFjLWM4ODctNDk1NC05M2EyLWE1NDNhNTRiZjVlYw-2.jpg","width":512,"height":512,"caption":"ldnDeveloper"},"logo":{"@id":"https:\/\/andrewpallant.ca\/wordpress\/#\/schema\/person\/image\/"},"description":"Andrew Pallant (@LdnDeveloper) has been a web, database and desktop developer for over 16 years. Andrew has worked on projects that ranged from factory automation to writing business applications. Most recently he has been heavily involved in various forms for ecommerce projects. Over the years Andrew has worn many hats: Project Manager, IT Manager, Lead Developer, Supervisor of Developers and many more - See more at: http:\/\/www.unlatched.com\/#sthash.8DiTkpKy.dpuf","sameAs":["http:\/\/www.andrewpallant.ca","https:\/\/x.com\/LdnDeveloper"],"url":"http:\/\/andrewpallant.ca\/wordpress\/author\/ldndeveloper\/"}]}},"_links":{"self":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1494"}],"collection":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/comments?post=1494"}],"version-history":[{"count":5,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1494\/revisions"}],"predecessor-version":[{"id":1499,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/posts\/1494\/revisions\/1499"}],"wp:attachment":[{"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/media?parent=1494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/categories?post=1494"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/andrewpallant.ca\/wordpress\/wp-json\/wp\/v2\/tags?post=1494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}