2017-03-09 1 views
1

오류 : 호출 된 부재

PdfFontFactory.CreateFont(FontConstants.HELVETICA); 

또는 웹 애플리케이션 내부

PdfFontFactory.CreateFont(); 

를 호출 할 때 C# 1 웹 애플리케이션에 동적 어셈블리에서 지원되지 않고, 타겟 프레임 워크 4.0, 나는 다음과 같은 오류가 발생합니다.
[NotSupportedException: The invoked member is not supported in a dynamic assembly.] 
    System.Reflection.Emit.InternalAssemblyBuilder.get_Location() +52 
    iText.IO.Util.ResourceUtil.<LoadITextResourceAssemblies>b__3(Assembly a) +30 
    System.Linq.WhereSelectListIterator`2.MoveNext() +115 
    System.Linq.Buffer`1..ctor(IEnumerable`1 source) +239 
    System.Linq.Enumerable.ToArray(IEnumerable`1 source) +77 
    iText.IO.Util.ResourceUtil.LoadITextResourceAssemblies() +172 
    iText.IO.Util.ResourceUtil..cctor() +125 

[TypeInitializationException: The type initializer for 'iText.IO.Util.ResourceUtil' threw an exception.] 
    iText.IO.Font.Type1Parser.GetMetricsFile() +127 
    iText.IO.Font.Type1Font.Process() +53 
    iText.IO.Font.Type1Font..ctor(String metricsPath, String binaryPath, Byte[] afm, Byte[] pfb) +131 
    iText.IO.Font.FontProgramFactory.CreateFont(String name, Byte[] fontProgram, Boolean cached) +381 
    iText.Kernel.Font.PdfFontFactory.CreateFont(String fontProgram, String encoding) +29 
    iText.Kernel.Font.PdfFontFactory.CreateFont(String fontProgram) +31 
    PdfCreator.x(String pdf_file_name) in x.cs:165 
    ASP.x_cshtml.Execute() in x.cshtml:40 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +196 
    System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +68 
    System.Web.WebPages.WebPage.ExecutePageHierarchy() +151 
    System.Web.WebPages.StartPage.RunPage() +19 
    System.Web.WebPages.StartPage.ExecutePageHierarchy() +62 
    System.Web.WebPages.StartPage.RunPage() +19 
    System.Web.WebPages.StartPage.ExecutePageHierarchy() +62 
    System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76 
    System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +114 

나는 나는 단지

PdfFontFactory.Register(windows_fonts + "ARIAL.TTF", "Arial"); 
PdfFont Arial = PdfFontFactory.CreateRegisteredFont("Arial"); 

를 사용하여 문제를 해결 할 수 있지만, 그래도 만 오류없이 빈 PDF가 발생합니다 생각했다.

C# 콘솔 앱에서 동일한 코드를 실행하면 모든 글꼴이 포함 된 유효한 PDF가 표시됩니다. 또한 C# 콘솔 응용 프로그램 .net 4를 대상으로하므로 대상 프레임 워크와 관련이 없다는 점이 매우 긍정적입니다. 의견을 보내 주셔서 감사합니다. iTextSharp를 들어

+0

C# 버전의 라이브러리에 버그가 있습니다. 로컬에서 문제를 해결하는 방법에 대한 자세한 내용은이 풀 요청을 참조하거나 iText 팀의 수정을 기다리십시오. https://github.com/itext/itext7-dotnet/pull/2 –

+0

감사합니다. 이제 문제를 이해합니다. –

답변

1

iText 팀 설명 된 문제에 대한 수정 프로그램이 적용된 .NET 버전 7.0.2.2을 릴리스했습니다. 이 버전은 기본적으로 핫픽스로 7.0.2 버전입니다. 경우에 따라 .NET에만 문제가 발생했기 때문에 Java 용으로 7.0.2.2이 표시되지 않습니다.

또는 iText Artifactory에서 새 7.0.2.2 버전을 다운로드 할 수 있습니다.

0

: 문서에 요소를 추가 할 때

string path = Path.Combine(AppDataPath, "helvetica.ttf"); 
BaseFont baseFont = BaseFont.CreateFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); 
Font font = new Font(baseFont, fontSize, Font.NORMAL); 
  • 사용이 객체 :

    1. 파일에서 폰트 객체를 생성 TTF 파일 *로 당신의 마음에 드는 글꼴을 다운로드

      var p = new Paragraph("hello there!", font); 
      doc.Add(p); 
      

    iText7의 경우이 모양은 example입니다. 형식은 매우 유사하지만, 글꼴 만들 다른 클래스를 사용

    PdfFont f1 = PdfFontFactory.createFont(ttf_file_path, "Cp1250", true); 
        Paragraph p1 = new Paragraph("Testing of letters").setFont(f1); 
        doc.add(p1); 
    
  • +0

    iText5 구문으로 게시 한 이래로 빠른 답장을 보내 주셔서 감사합니다. C# 웹 페이지를 사용할 때 iText7보다는 iText5를 고수해야한다는 의미입니까? –

    +0

    iTextSharp (https://github.com/itext/itextsharp)를 사용합니다. iText는 동일한 회사의 다른 라이브러리입니다 (https://github.com/itext/itext7-dotnet). 나는 iText에 대한 경험이 없다. –

    +0

    다른 라이브러리에 대한 대답 업데이트 –

    1

    라이브러리의 C# 버전에서 버그가 있습니다. 로컬로 문제를 해결하는 방법에 대한 자세한 내용은이 풀 요청을 참조하거나 iText 팀의 수정 사항을 기다리십시오 : github.com/itext/itext7-dotnet/pull/2 - Alexey Subach Mar 9 at 18:20