1
시스템 글꼴 디렉토리에 글꼴이 설치되어 있으면 중국어 문자로 올바르게 PDF 파일이 생성됩니다. 실제로 이것을 Azure 웹 사이트에 배포 할 때 글꼴을 설치할 수 없습니다.iTextSharp는 글꼴이 설치되어 있지 않으면 사용하지 않습니다.
프로젝트에 글꼴을 추가했지만 배포가 진행 중일 때 응용 프로그램에서 경로를 찾았지만 iTextSharp는 PDF가 생성 될 때이를 사용하지 않습니다.
private void CreatePDF(IList<string> HTMLData, string fileName, bool rotate)
{
//Create PDF document
Document doc = new Document(PageSize.A4, 36, 36, 36, 36);
if (rotate)
{
doc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
}
HTMLWorker parser = new HTMLWorker(doc);
string fontpath = Server.MapPath("/Fonts/arialuni.ttf");
FontFactory.Register(fontpath);
StyleSheet styles = new StyleSheet();
styles.LoadTagStyle(HtmlTags.TABLE, HtmlTags.SIZE, "6pt");
styles.LoadTagStyle(HtmlTags.H3, HtmlTags.SIZE, "10pt");
styles.LoadTagStyle(HtmlTags.H5, HtmlTags.SIZE, "6pt");
styles.LoadTagStyle(HtmlTags.BODY, HtmlTags.FACE, "Arial Unicode MS");
styles.LoadTagStyle(HtmlTags.BODY, HtmlTags.ENCODING, BaseFont.IDENTITY_H);
parser.SetStyleSheet(styles);
PdfWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create));
doc.Open();
//Try/Catch removed
foreach (var s in HTMLData) {
StringReader reader = new StringReader(s);
parser.Parse(reader);
doc.NewPage();
}
doc.Close();
}
전체 루틴은 생산하지 않는다 : -
FontFactory.Register("c:/windows/fonts/ARIALUNI.TTF");
이 작동하지 않습니다하지만 경로가 좋다 -
string arialuniTffFont = System.IO.Path.Combine(Server.MapPath("~/bin/fonts/arialuni.ttf"));
FontFactory.Register(arialuniTffFont);
업데이트 작동
현재 코드 한자.
http://stackoverflow.com/questions/5114658/how-can-i-install-custom-fonts-on-windows-azure 그게 전혀 도움이 되나요? – BlakeH
의심의 여지가 없지만 경로가 맞는지 100 % 확실합니까? 'MapPath()'는 경로의 유효성을 검사하지 않고 절대적으로 보이는 부분 만 상대적인 것으로 변환합니다. 그래서 예외가 발생해서는 안된다. if (! File.Exists (arialuniTffFont)) {throw new FileNotFoundException(); }' –
@ChrisHaas, 나는이 일을하는 데 정말로 가깝다. 폰트는 실제로 등록되어 있습니다. 단지 한자를 표시하는 데 사용하지 않고 있습니다. 무엇을 바꾸어야합니까? – Craig