2

ASP.NET + iTextSharp で PDF レポートを生成しました。
いくつかのタイプのフォントを使用しました。各フォントは、アート上の理由から 1 つまたは 2 つの単語に適用されます。
そのため、ファイルが大きいです。

実際に使用したフォントだけを埋め込むにはどうすればよいですか? MS Office Options で行っていることと同じです。

MS Office Word 2007 は次のようなものです:
「ファイルにフォントを埋め込む:
ドキュメントで使用されている文字のみを埋め込みます (ファイル サイズを縮小するのに最適です)
一般的なシステム フォントを埋め込まないでください」

または、別の種類のソリューションも受け入れることができます。
ページ全体を高解像度の画像にフラット化します。
プログラミングが便利な場合、私は実際にこのソリューションを好みます。

ありがとう。

4

1 に答える 1

2

埋め込みを有効にしてインスタンスを作成するBaseFont場合は、を呼び出す必要がありますmyBaseFont.setSubset(true)。エンコーディング「Identity-H」(別名BaseFont.IDENTITY_H)では、これは自動的に行われることに注意してください。

// find all fonts in the usual places across multiple OSs.
// This can be pretty slow if you have a large number fonts, or the fonts
// themselves are Really Big (ArialUnicodeMS: 23mb).
FontFactory.registerDirectories();

// here's one way to do it, using identity-h forces subsetting
Font myFontSubset1 = FontFactory.getFont(fontName1, BaseFont.IDENTITY_H);

// here's another, explicitly enable subsetting for the underlying BaseFont.
Font myFontSubset2 = FontFactory.getFont(fontName2, FontFactory.defaultEncoding, true);
myFontSubset2.getBaseFont().setSubset(true);

//or you can create the BaseFont yourself, with automagic subsetting
BaseFont myFontSubset3 = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H);

// or create it with some other encoding, and enable subsetting.
BaseFont myFontSubset4 = BaseFont.createFont(fontPath, BaseFont.WINANSI, true);
myFontSubset4.setSubset(true);

これはすべてJavaであることに注意してください。C#では、関数名の最初の文字が大文字になりsetX(newX)getX()プロパティになります。

于 2011-04-14T22:54:05.610 に答える