2017-12-11 26 views
1

例外、チェックitext7 - System.TypeInitializationException: 'iText.IO.Util.ResourceUtil' のタイプ初期化子はXamarinは、アプリケーション(Androidの& IOS)を形成するために、私はiTextのPDFジェネレータでPOCを試してみました

シナリオを投げました: itext sharpバージョン:5.5.21 - PCLプロジェクトとネイティブプロジェクトの両方でうまくいきました。 itext7バージョン:7.1.0 - これは以前のバージョンで修正されていると言われていますフォーラムでエラー

System.TypeInitializationException: The type initializer for 
'iText.IO.Util.ResourceUtil' threw an exception. ---> 
System.TypeInitializationException: The type initializer for 
'Microsoft.Extensions.DependencyModel.DependencyContextLoader' threw an 
exception. ---> System.TypeInitializationException: The type initializer for 
'Microsoft.Extensions.DependencyModel.DependencyContextPaths' threw an 
exception. ---> System.NotImplementedException: The method or operation is not 
implemented. 

下になりました。ブレークポイントのヒットが、それは誤りの上上げるPdfFont間、私は以下before.Attachを初期化する必要がある任意のものは、

PdfDocument pdf = new PdfDocument(new PdfWriter(fs, new WriterProperties().AddXmpMetadata())); 
Document document = new Document(pdf); 

pdf.SetTagged(); 
pdf.GetCatalog().SetLang(new PdfString("en-US")); 
pdf.GetCatalog().SetViewerPreferences(new PdfViewerPreferences().SetDisplayDocTitle(true)); 
PdfDocumentInfo info = pdf.GetDocumentInfo(); 
info.SetTitle("iText7 PDF/UA example"); 

PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true); 
Paragraph p = new Paragraph(); 
p.SetFont(font); 
p.Add(new Text("The quick brown ")); 

document.Add(p); 
document.Close(); 

をコードを試してみました。

答えて

1

iText 5では動作しますが、iText 7では動作しないコードがあります。これは正常です。 iText 7は、iText 5の完全な書き直しです!APIには後方互換性がありませんので、iText 5コードを使用している場合は、そのコードをiText 7で動作させたい場合は、最初から書き直す必要があります。

これらのすべてのメソッド(およびこれらのクラスの多く)がiText 7に存在しなくなったため、これらの例外がすべて発生します。彼らは他のメソッド(およびクラス)に置き換えられました。私はnugetからitext7をインストールしたiText 7: Jump-start tutorial for .NET

+0

このチュートリアルでは、ジャンプスタートを与えるだろう。コンソールアプリケーションとして実行すると、同じコードがうまく動作しますが、XamarinフォームやPCLでは機能しませんでした。 – vijay

関連する問題