一、
二、
三つ、
第四に、差し込み印刷(フィールドに入力)
4.1. テキストフィールドに記入する
サンプルコード
string tempFile = Application.streamingAssetsPath +"\\Templates\\template.doc";
string[] fieldNames = {
"ID" }; //域名
string[] values = {
"5" }; /值
Document doc = new Document(tempFile);
doc.MailMerge.Execute(fieldNames, values);
doc.Save(Application.persistentDataPath + "\\Export\\out.doc");
4.2. 画像フィールドへの入力
5. プリンター
5.1. デフォルトのプリンターを使用して印刷する
サンプルコード
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello world!");
// 1 - 使用默认打印机打印:
doc.Print();
5.2. 指定したプリンターで印刷する
サンプルコード
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello world!");
// 2 - 按名称指定我们希望打印文档的打印机:
string myPrinter = PrinterSettings.InstalledPrinters[4];
doc.Print(myPrinter);
5.3. プリンター一覧を取得する
サンプルコード
foreach (string printer in PrinterSettings.InstalledPrinters)
{
Debug.Log(index +":"+printer);
index++;
}
5.4. Unity が遭遇するエラー
- エラーの説明:
パラメータを指定した Print メソッドまたは Print メソッドを呼び出すことができません。 - エラーメッセージ:
OutOfMemoryException: Not enough memory to complete operation [GDI+ status: OutOfMemory] System.Drawing.GDIPlus.CheckStatus (System.Drawing.Status status) (at <7026bacc22c446e78b11ff130428baf7>:0) System.Drawing.Graphics.FromHdc (System.IntPtr hdc) (at <7026bacc22c446e78b11ff130428baf7>:0) System.Drawing.Printing.PrintDocument.Print () (at <7026bacc22c446e78b11ff130428baf7>:0) (wrapper remoting-invoke-with-check) System.Drawing.Printing.PrintDocument.Print() Aspose.Words.Document.Print (System.Drawing.Printing.PrinterSettings printerSettings, System.String documentName) (at <4d44192afd6745cb0e8eaf873e4443ac>:0) Aspose.Words.Document.Print (System.Drawing.Printing.PrinterSettings printerSettings) (at <4d44192afd6745cb0e8eaf873e4443ac>:0) Aspose.Words.Document.Print () (at <4d44192afd6745cb0e8eaf873e4443ac>:0)
- 原因:
System.Drawing.dll が見つからない - 解決策:現在の Unity バージョンのエディター
で System.Drawing.dll を Asserts にインポートします。
6.ユニティリリース
6.4 Unity で発生するエラー
- エラーの説明:
unity Editor では正常に実行されますが、公開後にエラーが表示されます。 - エラーメッセージ:
NullReferenceException: Object reference not set to an instance of an object
Rethrow as FileCorruptedException: The document appears to be corrupted and cannot be loaded.
- エラーの原因:
依存関係がありません。 - 解決:
- 最初に ProjectSetting -> Player -> Other Settings -> Api Compatibility Level を決定します。
- エディターのインストール パスで対応するライブラリ (
I18N.*
、Aspose.word.dll
、 ) を見つけます: .NET Standard 2.0: .NET 4.x:System.Drawing.dll
\Editor\Data\MonoBleedingEdge\lib\mono\2.0-api
\Editor\Data\MonoBleedingEdge\lib\mono\4.5
- その中で、.NET Standard2.0 の System.Drawing.dll は使用時に多少制限があり、サポートもあまり良くありません。
- 参考記事:https://blog.csdn.net/qq_37484084/article/details/126000485