1点質問させてください。
Delphi6 Personal + Windows 7 Proで、本田勝彦さんのTStringsPrinterを
使ってテキストファイルを印刷するプログラムを作成して使用していました。
http://homepage3.nifty.com/~katsuhiko/strprint.html
正常に処理が終わり、Printer.EndDocまで処理されていることを確認してい
るのですが、リコーのプリンターで印刷をすると、たまに複数ページのうち
1ページ目しか印刷されず、コンソール画面に以下のようなエラーメッセー
ジが表示されることがあります。
91:ジョブがキャンセルされました
また、Windows 7 に標準でインストールされているXPS Document Writerで
試しに印刷処理を行ってみましたが、やはりそちらでも正常に印刷がおわら
ないことがあり、作成されたファイルをダブルクリックして開こうとすると、
XPS ビューアーでは以下のようなメッセージが表示されます。
[Main Instruction]
XPS ビューアーでこのドキュメントを開くことができません
[Content]
このドキュメントは別のプログラムで開かれている可能性があります。他の
実行中のプログラムをすべて終了し、再試行してください。
同じ処理なのに、うまくいくときとうまくいかないときがあります。どなた
か、同じような症状に遭遇した方はいらっしゃいますでしょうか。確認させ
てください。
※同じ現象は、TeraPadという、TStringsPrinterを使ったソフトでも発生して
います。
※A4縦の用紙に1部だけ印刷しました。
※StringsPrinterのプロパティは次のとおりです。
object StringsPrinter1: TStringsPrinter
ColumnCount = 1
ColumnSpace = 4
FirstLineNumber = 1
FirstPageNumber = 1
Font.Charset = SHIFTJIS_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = MS ゴシック
Font.Size = 10
Font.Style = []
FooterAlign = haNone
HeaderAlign = haNone
LastLine = 0
LastPage = 999999
LineNumber = False
LineRangeOption = roWhole
MarginBottom = 25
MarginLeft = 20
MarginLine = 1
MarginRight = 20
MarginTop = 25
PageOption = poBoth
RangeOption = roWhole
StartLine = 1
StartPage = 1
WordBreak = True
end
※印刷しようとした文字列は、以下のとおりです。
↓ここから
procedure TMEMain.SetFindResult;
var
ARow, i, n, SI, EI, ATag, ALineNum, AStart, ExStart, ALen: Integer;
ATitle, ALineStr: string;
Editor: TMyEditor;
Options: TExSearchOptions;
begin
for n := 0 to TabsCount - 1 do begin
Editor := GetEditor(n);
for i := 0 to 6 do Editor.FindResult[i].Clear;
end;
ExitFindFlag := False;
Options := [];
if SearchSettings.MatchCase then Include(Options, soMatchCase);
if SearchSettings.WholeWord then Include(Options, soWholeWord);
if SearchSettings.RegExp then Include(Options, soRegexp);
if SearchSettings.AllFiles then begin
SI := 0;
EI := TabsCount - 1;
end else begin
SI := ActiveTabIndex;
EI := ActiveTabIndex;
end;
for n := SI to EI do begin
Editor := GetEditor(n);
Editor.ExSearchOptions := Options;
Editor.FindString := Edit1.Text;
ARow := 0;
while (ARow < Editor.ListCount) do begin
Application.ProcessMessages;
if ExitFindFlag then break;
if Editor.SetSearchInfoList(ARow, True) > 0 then begin
for i := 0 to Editor.FSearchInfoList.Count - 1 do begin
Application.ProcessMessages;
if ExitFindFlag then break;
ATag := Editor.Tag;
ATitle := Editor.Title;
ALineStr := Editor.LineString(ARow);
ALineNum := Editor.RowToLines(ARow) + 1;
AStart := PSearchInfo(Editor.FSearchInfoList.Items[i]).Start;
ExStart := Editor.ExpandTabLength(Copy(ALineStr, 1, AStart - 1)) + 1;
ALen := PSearchInfo(Editor.FSearchInfoList.Items[i]).Len;
Editor.FindResult[0].Add(IntToStr(ATag));
Editor.FindResult[1].Add(ATitle);
Editor.FindResult[2].Add(ALineStr);
Editor.FindResult[3].Add(IntToStr(ALineNum));
Editor.FindResult[4].Add(IntToStr(AStart));
Editor.FindResult[5].Add(IntToStr(ExStart));
Editor.FindResult[6].Add(IntToStr(ALen));
end;
end;
ARow := Editor.GetLineLastRow(ARow) + 1;
end;
end;
UpdateFindResult;
end;
↑ここまで
1点補足です。
最初の1回は、処理に成功するようなのですが、2回目で上記のようなエラーが
おこる頻度が高いような気がします。
念のため、TStringsPrinterの「StrPrint.pas」ファイル内のtry文をあえてはず
し、何かエラーが起きていないかチェックもしたのですが、統合開発環境では
何のエラーも検知しませんでした。
Delphi7+WinXP で作成した印刷プログラムがWin7では印刷されない
http://www.freeml.com/delphi-users/4499/latest
とは、違う現象でしょうか?
igy様、ご回答ありがとうございます。
Printer.Copies := 0
を付け足したことで、今までうまく動いていなかったのがうまく動くように
なった感じです。こんなに早くご回答いただけて、本当に助かりました。
昨日からずっと悩んでいたので、本当にうれしいです。
もう少しだけ様子を見て、結果良好であることを確認したうえで、皆様に
ご報告の意味でまた投稿させていただきます。本当にありがとうございました。
Copiesには1を入れた方が良いかもしれません。
0の場合、印刷しないプリンターがあったので。。。
デフォルトは1なので値的には変化しないはずなのですが
どうしてなんでしょう?
貴重な情報、誠にありがとうございます。
当方のプログラムでは、この値は特に使用しておりませんので、自由に変更できます。念には念をいれて、1を設定しておきたいと思います。
この件に関しての追加情報です。
Workaround for Printing from Delphi (or the Delphi IDE): three strikes and you get “Printer is not currently printing.” – yes I mentioned “Delphi 8!” « The Wiert Corner – irregular stream of stuff
https://wiert.me/2016/08/31/workaround-for-printing-from-delphi-or-the-delphi-ide-three-strikes-and-you-get-printer-is-not-currently-printing-yes-i-mentioned-delphi-8/
こちらでは回避策として(1)MS16-098(KB3177725)のアンインストール、または(2)Preinter.Copiesに値を代入、が挙げられています。
(Copiesに値を代入することで内部でPrinter.GetPrinterとPrinter.SetPrinterを発生させる、ということ)
一方マイクロソフトからはhotfixが出ています。
Print functionality is broken after any of the MS16-098 security updates are installed
https://support.microsoft.com/ja-jp/kb/3187022
hotfixの導入には前提条件("To apply this update, you must have April 2014 update rollup for Windows RT 8.1,
Windows 8.1, and Windows Server 2012 R2 (2919355) installed in Windows 8.1 or Windows Server 2012 R2.
Or, install Service Pack 1 for Windows 7 or Windows Server 2008 R2. Or, install Service Pack 2 for
Windows Vista and for Windows Server 2008. ")があります。またhotfixはMicrosoft Update Catalogからのみ
ダウンロード可能です(IEでアクセスする必要があります)。
あれからしばらく様子を見ていましたが、問題が再現しなくなりました。
皆様からの情報を拝見しても、これが解決法だと思われますので、解決とさせていただきます。
みなさま、本当にありがとうございました。
ツイート | ![]() |