Yanor.net/
Wiki
Blog
GitHub
Sandbox
開始行:
* HTMLからPDFファイルを作成 [#f9d79fe1]
- 日本語を使うにはフォントを指定する。
- フォントを指定するにはFontProviderを作る。
static void Main(string[] args)
{
Font fnt = new Font(BaseFont.CreateFont(@"c:\windows...
Dictionary< string, object > dicProvider = new Dicti...
dicProvider.Add(HTMLWorker.FONT_PROVIDER, new NewFon...
string html = "<html><body><h1>Test PDF</h1><ul><li>...
string outfilepath = @"c:\tmp\test-html.pdf";
FileStream fsoutput = new FileStream(outfilepath, Fi...
TextReader reader = new StringReader(html);
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 30, 30...
// step 2:
// we create a writer that listens to the document
// and directs a XML-stream to a file
PdfWriter writer = PdfWriter.GetInstance(document, f...
// step 3: we create a worker parse the document
HTMLWorker worker = new HTMLWorker(document);
worker.SetProviders(dicProvider);
// step 4: we open document and start the worker on ...
document.Open();
worker.StartDocument();
// step 5: parse the html into the document
worker.Parse(reader);
// step 6: close the document and the worker
worker.EndDocument();
worker.Close();
document.Close();
Console.ReadLine();
}
public class NewFontProvider : FontFactoryImp
{
public override Font GetFont(string fontname, string...
{
if (string.IsNullOrEmpty(fontname)) {
fontname = "c:\\windows\\fonts\\msmincho.ttc...
encoding = BaseFont.IDENTITY_H;
embedded = BaseFont.EMBEDDED;
}
return base.GetFont(fontname, encoding, embedded...
}
}
** 参考 [#ye888b31]
- http://codezine.jp/article/detail/462
- http://www.vector.co.jp/soft/winnt/writing/se462217.html
- http://catblogger.seesaa.net/article/217675010.html
- http://www.mosa-architect.com/wp/2011/08/itext-htmlwork...
- http://jehupc.exblog.jp/12731848/
終了行:
* HTMLからPDFファイルを作成 [#f9d79fe1]
- 日本語を使うにはフォントを指定する。
- フォントを指定するにはFontProviderを作る。
static void Main(string[] args)
{
Font fnt = new Font(BaseFont.CreateFont(@"c:\windows...
Dictionary< string, object > dicProvider = new Dicti...
dicProvider.Add(HTMLWorker.FONT_PROVIDER, new NewFon...
string html = "<html><body><h1>Test PDF</h1><ul><li>...
string outfilepath = @"c:\tmp\test-html.pdf";
FileStream fsoutput = new FileStream(outfilepath, Fi...
TextReader reader = new StringReader(html);
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 30, 30...
// step 2:
// we create a writer that listens to the document
// and directs a XML-stream to a file
PdfWriter writer = PdfWriter.GetInstance(document, f...
// step 3: we create a worker parse the document
HTMLWorker worker = new HTMLWorker(document);
worker.SetProviders(dicProvider);
// step 4: we open document and start the worker on ...
document.Open();
worker.StartDocument();
// step 5: parse the html into the document
worker.Parse(reader);
// step 6: close the document and the worker
worker.EndDocument();
worker.Close();
document.Close();
Console.ReadLine();
}
public class NewFontProvider : FontFactoryImp
{
public override Font GetFont(string fontname, string...
{
if (string.IsNullOrEmpty(fontname)) {
fontname = "c:\\windows\\fonts\\msmincho.ttc...
encoding = BaseFont.IDENTITY_H;
embedded = BaseFont.EMBEDDED;
}
return base.GetFont(fontname, encoding, embedded...
}
}
** 参考 [#ye888b31]
- http://codezine.jp/article/detail/462
- http://www.vector.co.jp/soft/winnt/writing/se462217.html
- http://catblogger.seesaa.net/article/217675010.html
- http://www.mosa-architect.com/wp/2011/08/itext-htmlwork...
- http://jehupc.exblog.jp/12731848/
ページ名: