Last active
January 5, 2018 07:51
-
-
Save ugurhasar/566fe1fb52d581dfb81c2b40b07ec3b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C#'ta iTextSharp ile Html'i Pdf'e Dönüştürme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>Page Title</title> | |
</head> | |
<body> | |
<h1>This is a Heading</h1> | |
<p>This is a paragraph.</p> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public byte[] Write() | |
{ | |
byte[] bytes = null; | |
string htmlStr = File.ReadAllText("html dosya yolu", Encoding.UTF8); | |
string cssStr = File.ReadAllText("css dosya yolu", Encoding.UTF8); | |
using (var memoryStream = new MemoryStream()) | |
{ | |
using (Document document = new Document(PageSize.A4, 0, 0, 0, 0)) | |
{ | |
using (var pdfWriter = PdfWriter.GetInstance(document, memoryStream)) | |
{ | |
document.Open(); | |
using (var css = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(cssStr))) | |
{ | |
using (var html = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(htmlStr))) | |
{ | |
XMLWorkerHelper.GetInstance().ParseXHtml(pdfWriter, document, html, css); | |
} | |
} | |
document.Close(); | |
} | |
} | |
bytes = memoryStream.ToArray(); | |
} | |
return bytes; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
h1 { color: red; } | |
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.UI.HtmlControls; | |
using System.IO; | |
using iTextSharp.text; | |
using iTextSharp.text.pdf; | |
using iTextSharp.text.html.simpleparser; | |
using System.Text.RegularExpressions; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment