unit DKvCttSchMain; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Tocsg.Thread, Vcl.ExtCtrls, ThdCttSch, Vcl.StdCtrls, KvCttSchClient, Tocsg.Trace; type TDlgKvCttSchMain = class(TForm) tInit: TTimer; edSrc: TEdit; Label1: TLabel; Label2: TLabel; edDest: TEdit; btnExtrTxt: TButton; Button1: TButton; procedure tInitTimer(Sender: TObject); procedure btnExtrTxtClick(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } Trace_: TTgTrace; ThdTimer_: TThdTaskTimer; sMtx_: String; ThdCttSch_: TThdCttSch; Client_: TKvCttSchClient; procedure TimerCheckMutex(aSender: TObject); procedure ProcessPrint; public { Public declarations } Constructor Create(aOwner: TComponent); override; Destructor Destroy; override; procedure process_WM_COPYDATA(var msg: TMessage); Message WM_COPYDATA; end; var DlgKvCttSchMain: TDlgKvCttSchMain; implementation uses CttSchDefine, Tocsg.Win32, Tocsg.Exception, Tocsg.KvFilter, Tocsg.Safe, Tocsg.KvFilter.adinfo, superobject, Tocsg.Json, Tocsg.Watermark, Tocsg.Path, Tocsg.Files, ProcessDecompress, Tocsg.Encrypt, Vcl.Imaging.pngimage, Vcl.Printers, DWaitProcPrt, Condition, GlobalDefine, hyieutils, Tocsg.Convert, Tocsg.Graphic, Winapi.GDIPAPI, imageen, Vcl.Imaging.jpeg, Tocsg.Process, ManagerImgMskData, Tocsg.Strings, STLabGuardModule, Define, Tocsg.Kess, Tocsg.Registry, Tocsg.Shell, Tocsg.Valid, SynPdf, EM.PdfiumCore, System.Math, System.IniFiles, Tocsg.WinInfo, Tocsg.Network, ProcessPrintWater; {$R *.dfm} function SendData(h: HWND; dwCmd: DWORD; const sData: String): LONGLONG; var CopyData: TCopyDataStruct; begin CopyData.dwData := dwCmd; CopyData.cbData := (Length(sData) + 1) * 2; CopyData.lpData := PChar(sData); Result := SendMessage(h, WM_COPYDATA, 0, NativeInt(@CopyData)); Application.ProcessMessages; end; procedure TDlgKvCttSchMain.Button1Click(Sender: TObject); var i, pi: Integer; sDir, sPrtName, sImgPath: String; EmfList: TStringList; MF: TMetafile; nW, nH: Integer; begin sPrtName := 'Microsoft Print to PDF'; pi := -1; MF := nil; for i := 0 to Printer.Printers.Count - 1 do begin if Printer.Printers[i] = sPrtName then pi := i; end; if pi = -1 then begin TTgTrace.T('프린터 찾기 실패 .. Name=%s', [sPrtName]); exit; end; Printer.PrinterIndex := pi; Printer.Title := 'TEST *BSOne-'; sDir := 'C:\Users\kku\Desktop\TEST\_ColTest\'; Guard(EmfList, TStringList.Create); ExtrFilesFromDir(sDir, EmfList, false, 'em1'); if EmfList.Count = 0 then exit; EmfList.Sort; Printer.Orientation := poLandscape; Printer.BeginDoc; try for i := 0 to EmfList.Count - 1 do begin if not Printer.Printing or Printer.Aborted then break; try try if MF <> nil then FreeAndNil(MF); // i = 0은 위에서 미리 불러옴 MF := TMetafile.Create; sImgPath := sDir + EmfList[i]; MF.LoadFromFile(sImgPath); if (MF.MMWidth = 0) or (MF.MMHeight = 0) then continue; except {$IFDEF DEBUG} ASSERT(false); {$ENDIF} break; end; Printer.NewPage; // if MF.MMWidth > MF.MMHeight then // Printer.Orientation := poLandscape; nW := GetDeviceCaps(Printer.Canvas.Handle, HORZRES); nH := GetDeviceCaps(Printer.Canvas.Handle, VERTRES); Printer.Canvas.StretchDraw(Rect(0, 0, nW, nH), MF); except // on E: Exception do // ETgException.TraceException(Self, E, Format('Fail .. DoPrint .. Step=%d', [nStep])); end; end; finally Printer.EndDoc; end; end; Constructor TDlgKvCttSchMain.Create(aOwner: TComponent); var sImgExt: String; begin Inherited Create(aOwner); PDFiumDllDir := GetRunExePathDir; if GetUserDefaultLangID <> 1042 then Caption := APP_TITLE + ' $' else Caption := APP_TITLE; ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD); Trace_ := nil; {$IFDEF DEBUG} if gParam.TaskType <> csttExtrSimple then begin var sLogPath: String := 'C:\ProgramData\HE\' + CutFileExt(ExtractFileName(GetRunExePath)) + '.log'; DeleteFile(sLogPath); Trace_ := TTgTrace.Create(ExtractFilePath(sLogPath), ExtractFileName(sLogPath)); TTgTrace.T('Create()'); // Trace_ := TTgTrace.Create('C:\BSLog\', CutFileExt(ExtractFileName(GetRunExePath)) + '.log'); // TTgTrace.T('GOGO'); end; {$ENDIF} // TTgTrace.T('Create'); CUSTOMER_TYPE := gParam.CustomerType; if CUSTOMER_TYPE = CUSTOMER_KDNVN then begin var dwResult: DWORD := KCT_Init(GetRunExePathDir + DIR_CONF, 'kdnavien'); if dwResult <> RESULT_SUCCESS then TTgTrace.T('Fail .. Init KESS .. Code=%x', [dwResult]) else TTgTrace.T('Success .. Init KESS'); end; if UseFasooDecrypt and not IsCJ_Affiliates then // CJ에서는 DLL 로드하지 않도록 수정 25_0812 09:12:16 kku begin if not ExistsKey(HKEY_CLASSES_ROOT, 'TypeLib\{D3135A34-059E-4A47-AAD4-0D84F41DC165}\1.0\0\win64') then begin // 롯데마트는 기본 64DLL이 등록되지 않음 24_1104 11:22:41 kku // 다른 고객사는 확인필요... var sFsDll: String := 'C:\Program Files\Fasoo DRM\CW-Packager\WorkPackagerV3.dll'; if not FileExists(sFsDll) then sFsDll := GetRunExePathDir + DLL_FAS64; if not FileExists(sFsDll) then sFsDll := GetRunExePathDir + DIR_CONF + DLL_FAS64; if FileExists(sFsDll) then ExecutePath_hide('regsvr32.exe', Format('/s "%s"', [sFsDll])); end; end; ThdTimer_ := nil; ThdCttSch_ := nil; sImgExt := GetFileExt(gParam.PrtWaterEnt.sImgPath).ToUpper; if ((sImgExt = 'PDF') or (sImgExt = 'EM1')) and (gParam.RcvWnd <> 0) and gParam.UseWM then begin SetRegValueInteger(HKEY_CURRENT_USER, REG_HE, 'CT', gParam.CustomerType, true); SetRegValueString(HKEY_CURRENT_USER, REG_HE, 'UName', gParam.UName, true); SetRegValueString(HKEY_CURRENT_USER, REG_HE, 'EmpNo', gParam.EmpNo, true); SetRegValueString(HKEY_CURRENT_USER, REG_HE, 'DeptName', gParam.DeptName, true); var sIni: String := GetProgramFilesDir + DIR_TG + INI_FORCEHE; if FileExists(sIni) then begin var ini: TIniFile; Guard(ini, TIniFile.Create(sIni)); var f: Double := ini.ReadFloat('Force', 'WmTran', 0.0); if f <> 0.0 then SetRegValueString(HKEY_CURRENT_USER, REG_HE, 'WmTran', FloatToStr(f), true); end; var nResult: Integer := SendData(gParam.RcvWnd, KV_HOOK_PRINT, IntToStr(GetCurrentProcessId)); if nResult = 200 then TTgTrace.T('IsPrtSpl2Pdf - InjectModule() .. Success!, CT=%d', [gParam.CustomerType]) else TTgTrace.T('IsPrtSpl2Pdf - InjectModule() .. Fail! .. %d', [nResult]) // if InjectModule(GetCurrentProcessId, GetRunExePathDir + DIR_CONF + DLL_HOOK) > 0 then // begin // TTgTrace.T('IsPrtSpl2Pdf - InjectModule() Success.'); // end; end; tInit.Enabled := true; TTgTrace.T('Create() .. OK'); end; Destructor TDlgKvCttSchMain.Destroy; begin // TTgTrace.T('Destroy'); if Client_ <> nil then FreeAndNil(Client_); if ThdTimer_ <> nil then FreeAndNil(ThdTimer_); if ThdCttSch_ <> nil then FreeAndNil(ThdCttSch_); Inherited; if Trace_ <> nil then FreeAndNil(Trace_); end; procedure TDlgKvCttSchMain.btnExtrTxtClick(Sender: TObject); var KvFilter: TKvFilter; begin edSrc.Text := Trim(edSrc.Text); // if IsValidKoreanSSN(edSrc.Text) then // ShowMessage('검증 OK') // else // ShowMessage('검증 실패!'); //exit; edDest.Text := Trim(edDest.Text); if edSrc.Text = '' then begin MessageBox(Handle, PChar('문서파일 경로를 입력해 주십시오.'), PChar(Caption), MB_ICONWARNING or MB_OK); edSrc.SetFocus; exit; end; if not FileExists(edSrc.Text) then begin MessageBox(Handle, PChar('존재하지 않는 파일입니다.'), PChar(Caption), MB_ICONWARNING or MB_OK); edSrc.SetFocus; exit; end; if edDest.Text = '' then begin MessageBox(Handle, PChar('내보내기 경로를 입력해 주십시오.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; try // 압축해제 테스트 23_0602 12:22:26 kku // var sExt: String := GetFileExt(edSrc.Text).ToUpper; // if Pos(sExt, COMPRESS_EXTS) > 0 then // begin // var sZipExtrDir: String := GetRunExePathDir + 'Task\@etr\'; // if ForceDirectories(sZipExtrDir) then // begin // DecompressFile(edSrc.Text, sZipExtrDir, nil, nil); // end; //// DeleteDir(sZipExtrDir); // end; // exit; // var ThdProc: TThdProcFasooDRM;; // var sFsDir: String := 'C:\Program Files\Tocsg\eCrmHome\conf\fsdinit'; // SetDSD_CODE(DSD_CODE_CJ); // Guard(ThdProc, TThdProcFasooDRM.Create(sFsDir, edSrc.Text, edDest.Text, true)); // ThdProc.StartThread; // while ThdProc.WorkState <> tsCompleted do // begin // Sleep(200); // Application.ProcessMessages; // end; // if FileExists(edDest.Text) then // ShowMessage(Format('성공 (%d)', [ThdProc.ErrorCode])) // else // ShowMessage(Format('실패 (%d)', [ThdProc.ErrorCode])); // exit; Guard(KvFilter, TKvFilter.Create); with gParam.CttSimpleOpt do begin var nError := KvFilter.FilterFile(edSrc.Text, edDest.Text); if nError = 0 then MessageBox(Handle, PChar('내보내기를 완료했습니다.'), PChar(Caption), MB_ICONINFORMATION or MB_OK) else MessageBox(Handle, PChar(Format('내보내기 중 오류가 발생했습니다. (Error=%d)', [nError])), PChar(Caption), MB_ICONWARNING or MB_OK); end; except on E: Exception do ETgException.TraceException(Self, E, 'Fail .. ProcessExtrText()'); end; end; procedure TDlgKvCttSchMain.TimerCheckMutex(aSender: TObject); begin if (sMtx_ <> '') and not MutexExists(sMtx_) then TerminateProcess(GetCurrentProcess, 1); end; procedure TDlgKvCttSchMain.tInitTimer(Sender: TObject); procedure ProcessExtrText; var KvFilter: TKvFilter; ErrorCode: DWORD; begin try if not FileExists(gParam.CttSimpleOpt.sSrcPath) then exit; try Guard(KvFilter, TKvFilter.Create); with gParam.CttSimpleOpt do begin ErrorCode := KvFilter.FilterFile(sSrcPath, sDestPath); TTgTrace.T('[MGKIM] KvFilter.FilterFile ErrorCode : (%d)', [ErrorCode]); end; except on E: Exception do ETgException.TraceException(Self, E, 'Fail .. ProcessExtrText()'); end; finally Close; end; end; procedure ProcessDocInfo; var KvFilter: TKvFilter; DocInfo: TAdDocInfo; O: ISuperObject; Label LB_Retry; begin try if not FileExists(gParam.CttSimpleOpt.sSrcPath) then exit; try Guard(KvFilter, TKvFilter.Create); DocInfo := KvFilter.GetDocInfoFile(gParam.CttSimpleOpt.sSrcPath); O := SO; O.O['Info'] := TTgJson.ValueToJsonObject(DocInfo); SaveJsonObjToFile(O, gParam.CttSimpleOpt.sDestPath); except on E: Exception do ETgException.TraceException(Self, E, 'Fail .. ProcessExtrText()'); end; finally Close; end; end; procedure ProcessWatermark; var ImgEn: TImageEn; nRetryCnt: Integer; bLoadFail: Boolean; Font: TFont; sToday, sWaterTxt, sAppend: String; Label LB_Retry; begin try if not FileExists(gParam.CttSimpleOpt.sSrcPath) then exit; // DRM 파일은 무시하도록 보완 24_0109 15:57:54 kku if TTgEncrypt.CheckSign(gParam.CttSimpleOpt.sSrcPath, SIG_DRM) then exit; try ImgEn := TImageEn.Create(Self); Guard(Font, TFont.Create); Font.Size := 13; Font.Name := 'Arial'; Font.Style := Font.Style + [fsBold]; nRetryCnt := 0; LB_Retry : try bLoadFail := false; ImgEn.IO.LoadFromFile(gParam.CttSimpleOpt.sSrcPath); except bLoadFail := true; end; if bLoadFail then begin if nRetryCnt < 5 then begin Inc(nRetryCnt); Sleep(1000); goto LB_Retry; end else exit; end; AddWatermarkTextLayer(ImgEn, Font, gParam.CttSimpleOpt.sAssocInfo, 25, false); ImgEn.IO.SaveToFile(gParam.CttSimpleOpt.sDestPath); except on E: Exception do ETgException.TraceException(Self, E, 'Fail .. ProcessWatermark()'); end; finally Close; end; end; procedure ProcessSearchMulti; begin ThdCttSch_ := TThdCttSch.Create(gParam.Tasker, gParam.LangID, gParam.CttSchOpt, gParam.SchPatterns, gParam.ExtrTxtOnly); ThdCttSch_.StartThread; SendMessage(gParam.CttSchOpt.hRcvHwnd, WM_CTTSCH_INIT, Handle, gParam.Tasker); PostMessage(gParam.CttSchOpt.hRcvHwnd, WM_CTTSCH_REQUEST, KV_REQUEST_SEARCH_PATH, gParam.Tasker); // ThdCttSch_.PushSchEnt('*Start'); end; begin tInit.Enabled := false; TTgTrace.T('tInit() .. '); try {$IFDEF DEBUG} if (DebugHook <> 0) and gParam.ExistsParam('-testconn') then begin Client_ := TKvCttSchClient.Create; if Client_.ActiveW2W then Caption := IntToStr(Client_.GetSelfWnd); exit; end; {$ENDIF} if gParam.Mutex <> '' then begin sMtx_ := gParam.Mutex; ThdTimer_ := TThdTaskTimer.Create; ThdTimer_.AddTask(TimerCheckMutex, 1000, true); ThdTimer_.StartTimerThread; end; TTgTrace.T('tInit() .. 1, Type=%d', [Integer(gParam.TaskType)]); case gParam.TaskType of csttNone : Close; csttTest : ; csttExtrSimple : ProcessExtrText; csttExtrDocInfo : ProcessDocInfo; csttWaterMarkImg : ProcessWatermark; csttSchMulti : ProcessSearchMulti; csttSchConnect : begin Client_ := TKvCttSchClient.Create; if Client_.ActiveW2W then Client_.ConnectWnd(gParam.Tasker); end; csttPrint : ProcessPrint; end; except on E: Exception do ETgException.TraceException(Self, E, 'Fail .. tInitTimer()'); end; end; procedure TDlgKvCttSchMain.process_WM_COPYDATA(var msg: TMessage); var pCpData: PCopyDataStruct; sData: String; begin try pCpData := PCopyDataStruct(msg.LParam); if pCpData.cbData = 0 then exit; if ThdCttSch_ = nil then exit; case pCpData.dwData of KV_RESPONSE_SEARCH_PATH : begin sData := Copy(PChar(pCpData.lpData), 1, pCpData.cbData); ThdCttSch_.PushSchEnt(sData); end; end; except on E: Exception do ETgException.TraceException(Self, E, 'Fail .. process_WM_COPYDATA()'); end; end; procedure TDlgKvCttSchMain.ProcessPrint; procedure ExtrPrintImgFiles(sImgPath: String; aList: TStrings); var sFName: string; i: Integer; begin aList.Clear; sFName := StringReplace(CutFileExt(sImgPath), '_0001', '', [rfReplaceAll]); if not FileExists(sImgPath) and not FileExists(Format('%s_%.4d.png', [sFName, 1])) then exit; if FileExists(sImgPath) then aList.Add(sImgPath); i := 1; while True do begin sImgPath := Format('%s_%.4d.png', [sFName, i]); if FileExists(sImgPath) then begin if aList.IndexOf(sImgPath) = -1 then aList.Add(sImgPath); end else exit; Inc(i); end; end; { Returns grayscale version of a color. } function RgbToGray(C: TColor): TColor; begin C := Round(C and $FF * 0.3 + C and $00FF00 shr 8 * 0.59 + C shr 16 * 0.11); Result := RGB(C, C, C); end; { Converts whole PNG image to grayscale. } procedure ToGrayscale(PNG: TPNGObject); var X, Y: Integer; begin for X := 0 to PNG.Width - 1 do for Y := 0 to PNG.Height - 1 do PNG.Pixels[X, Y] := RgbToGray(PNG.Pixels[X, Y]); end; const WORD_GAP = ' '; type TProcType = (ptPng, ptPdf, ptEmf); var WInfo: TPrtWaterEnt; pi, i, nLeft, nTop, nW, nH: Integer; ImgList: TStringList; ProcType: TProcType; bIsWatchPtr: Boolean; png: TPngImage; mf: TMetaFile; sExt, sWImgPath, sImgDir, sImgPath, sTopText, sBottomText: String; bmpWaterP: TBitmap; arrDevice, arrDriver, arrPort: array [0..255] of Char; hDev: THandle; DevMode: PDeviceMode; OrgDevMode: TDeviceMode; // ImgEn: TImageEn; // F: TFont; dlg: TDlgWaitExtrProcPrt; // _bmpST, // _bmpWaterP: TBitmap; nStep: Integer; procedure DoMasking(pEnt: PMskEnt); var R: TRect; i: Integer; sText: String; x, y: Integer; begin R.Left := pEnt.x; R.Top := pEnt.y; R.Width := pEnt.w; R.Height := pEnt.h; png.Canvas.Pen.Color := clWhite; png.Canvas.Pen.Style := psSolid; png.Canvas.Brush.Color := clWhite; png.Canvas.Brush.Style := bsSolid;// bsBDiagonal; png.Canvas.FillRect(R); sText := 'Hidden by BSOne'; for i := 1 to 99 do begin png.Canvas.Font.Size := i; if (png.Canvas.TextHeight(sText) - 1) >= (R.Height - 2) then begin break; end; end; png.Canvas.TextRect(R, sText, [tfCenter, tfEndEllipsis, tfVerticalCenter]); png.Canvas.Pen.Color := clBlack; png.Canvas.Pen.Style := psDot; png.Canvas.MoveTo(R.Left, R.Top); png.Canvas.LineTo(R.Left + R.Width, R.Top); png.Canvas.LineTo(R.Left + R.Width, R.Top + R.Height); png.Canvas.LineTo(R.Left, R.Top + R.Height); png.Canvas.LineTo(R.Left, R.Top); end; // procedure ProcessSnaptag; // var // sStPng: String; // pngST: TPngImage; // nsX, nsY: Integer; // begin // if not gParam.UseSnaptag then // exit; // // try // if _bmpST = nil then // begin // sStPng := GetRunExePathDir + DIR_CONF + PNG_SNAPTAGDATA_PRT; // if FileExists(sStPng) then // begin // Guard(pngST, TPngImage.Create); // pngST.LoadFromFile(sStPng); // // _bmpST := TBitmap.Create; // _bmpST.PixelFormat := pf4bit; // _bmpST.SetSize(png.Width div 5, png.Height div 5); // // nsX := 0; // while nsX < (_bmpST.Width + pngST.Width) do // begin // nsY := 0; // while nsY < (_bmpST.Height + pngST.Height) do // begin // _bmpST.Canvas.Draw(nsX, nsY, pngST); // Inc(nsY, pngST.Height); // end; // Inc(nsX, pngST.Width); // end; // end; // end; // // if _bmpST <> nil then // begin //// _bmpST.SaveToFile('C:\Users\kku\Desktop\이전 바탕화면\출력 추출 데이터\test.bmp'); // // var cTrMatrix: TColorMatrix := MakeColorMatrix(0.2, 0.2, 0.2, gParam.ValSnaptag); // DrawBitmapWaterEx(png.Canvas.Handle, 0, 0, _bmpST, @cTrMatrix, png.Width, png.Height); // end; // except // on E: Exception do // ETgException.TraceException(Self, E, 'Fail .. ProcessSnaptag()'); // end; // end; // function GetDPI_Size(nSize: Integer): Integer; // begin // case gParam.PrtDPI of // 100 : Result := nSize - ((nSize div 6) * 5); // 200 : Result := nSize - ((nSize div 6) * 4); // 300 : Result := nSize - ((nSize div 6) * 3); // 400 : Result := nSize - ((nSize div 6) * 2); // 500 : Result := nSize - (nSize div 6); // else Result := nSize; // end; // end; // // function CalcSizeDIP(n300: Integer): Integer; // var // nSize: Integer; // begin // nSize := n300 * 2; // case gParam.PrtDPI of // 100 : Result := nSize - ((nSize div 6) * 5); // 200 : Result := nSize - ((nSize div 6) * 4); // 300 : Result := nSize - ((nSize div 6) * 3); // 400 : Result := nSize - ((nSize div 6) * 2); // 500 : Result := nSize - (nSize div 6); // else Result := nSize; // end; // end; // // procedure SetImgFontSize(nSize: Integer); // begin // png.Canvas.Font.Size := GetDPI_Size(nSize); // end; // // procedure DrawRotatedText(Canvas: TCanvas; X, Y, Angle: Integer; const Text: string); // var // LogFont: TLogFont; // OldFont, RotatedFont: HFONT; // begin // // 기존 폰트를 기반으로 로그폰트 가져오기 // GetObject(Canvas.Font.Handle, SizeOf(LogFont), @LogFont); // // // 회전 각도 설정 (0.1도 단위, 즉 450 = 45도) // LogFont.lfEscapement := Angle * 10; // LogFont.lfOrientation := Angle * 10; // // // 안티앨리어싱 등 품질 향상 옵션 // LogFont.lfQuality := ANTIALIASED_QUALITY; // // // 회전 폰트 생성 // RotatedFont := CreateFontIndirect(LogFont); // OldFont := SelectObject(Canvas.Handle, RotatedFont); // // // 텍스트 출력 // TextOut(Canvas.Handle, X, Y, PChar(Text), Length(Text)); // // // 자원 정리 // SelectObject(Canvas.Handle, OldFont); // DeleteObject(RotatedFont); // end; // function ProcessWatermark(aDest: HDC; sMaskImg: String = ''): Boolean; // var // bRotate: Boolean; // nTmp: Integer; // sWText: String; // begin // if png = nil then // Exit(false); // // Result := true; // // ProcessSnaptag; // // bRotate := false; // // 가로출력인데 세로로 되어 있으면 돌려준다. 24_0819 16:57:41 kku // if not WInfo.bPaperV and (png.Width < png.Height) then // begin // bRotate := true; //// if nW < nH then //// begin //// nTmp := nH; //// nH := nW; //// nW := nTmp; //// end; // RotatePng(png, 90); // end; // // if ProcType <> ptPng then // begin // Result := false; // exit; // end; // // if not gParam.UseWM then // begin // Result := false; // exit; // end; // // try // if gParam.MaskStr <> '' then // begin // // 마스킹 처리... 24_0529 16:16:06 kku // if (sMaskImg <> '') and FileExists(sMaskImg) then // begin // var sOcrPath: String := GetRunExePathDir + DIR_CONF + EXE_OCR; // var sTmpPath: String := 'C:\ProgramData\HE\Task\'; // if FileExists(sOcrPath) and ForceDirectories(sTmpPath) then // begin // sTmpPath := sTmpPath + '$TmpOcr.dat'; // ExecuteAppWaitUntilTerminate(sOcrPath, // Format('-r "%s" "%s"', [sMaskImg, sTmpPath]), SW_HIDE, 10000); // // if FileExists(sTmpPath) then // begin // var MgMsk: TManagerImgMskData; // Guard(MgMsk, TManagerImgMskData.Create(sTmpPath)); // DeleteFile(PChar(sTmpPath)); // // var StrList: TStringList; // Guard(StrList, TStringList.Create); // SplitString(gParam.MaskStr, ',', StrList, false, true); // // var MskLst: TMskEntList; // Guard(MskLst, TMskEntList.Create); // var cc, nn: Integer; // for cc := 0 to StrList.Count - 1 do // begin // if MgMsk.MatchToList(StrList[cc], MskLst) > 0 then // begin // for nn := 0 to MskLst.Count - 1 do // DoMasking(MskLst[nn]); // end; // end; // end; // end; // end; // end; // // if gParam.PrtWaterCfg.bActive then // begin // SetBkMode(png.Canvas.Handle, TRANSPARENT); // png.Canvas.Font.Color := clSilver; // // var PWC: TPrtWaterCfg := gParam.PrtWaterCfg; // var sText: String := ''; // nLeft := 0; // nTop := 0; // // if (PWC.sTopText <> '') and (PWC.nTopSize > 0) then // begin // SetImgFontSize(Round(Double(42) * (Double(PWC.nTopSize) / 10))); // sText := StrsReplace(PWC.sTopText, ['{IpAddr}', '{HostName}', '{MacAddr}', '{EmpNo}', '{Dept}', '{UserName}', '{DateTime}'], // [gParam.IP, GetComName, GetMACAddr, gParam.EmpNo, gParam.DeptName, gParam.UName, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now)]); // // case PWC.nTopPos of // 1 : nLeft := 0; // 왼쪽 // 2 : nLeft := (png.Width div 2) - (png.Canvas.TextWidth(sText) div 2); // 가운데 // 3 : nLeft := png.Width - png.Canvas.TextWidth(sText); // 오른쪽 // end; // png.Canvas.TextOut(nLeft, nTop, sText); // end; // // if (PWC.sBotText <> '') and (PWC.nBotSize > 0) then // begin // SetImgFontSize(Round(Double(42) * (Double(PWC.nBotSize) / 10))); // sText := StrsReplace(PWC.sBotText, ['{IpAddr}', '{HostName}', '{MacAddr}', '{EmpNo}', '{Dept}', '{UserName}', '{DateTime}'], // [gParam.IP, GetComName, GetMACAddr, gParam.EmpNo, gParam.DeptName, gParam.UName, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now)]); // // case PWC.nBotPos of // 1 : nLeft := 0; // 왼쪽 // 2 : nLeft := (png.Width div 2) - (png.Canvas.TextWidth(sText) div 2); // 가운데 // 3 : nLeft := png.Width - png.Canvas.TextWidth(sText); // 오른쪽 // end; // nTop := png.Height - png.Canvas.TextHeight(sText); // png.Canvas.TextOut(nLeft, nTop, sText); // end; // end else // if not IgrPrintWaterDefText then // begin // SetBkMode(png.Canvas.Handle, TRANSPARENT); // SetImgFontSize(42); // png.Canvas.Font.Color := clSilver; // // if sTopText <> '' then // begin // nLeft := 0; // nTop := 0; // // if cbTopTextPos.ItemIndex <> 0 then // // nLeft := bmp.Width - bmp.Canvas.TextWidth(sTopText); // // // bmp.Canvas.TextOut(nLeft, nTop, sTopText); // png.Canvas.TextOut(nLeft, nTop, sTopText); // end; // // if sBottomText <> '' then // begin // // bmp.Canvas.Font.Size := 10 * 7; // // nLeft := 0; // // nTop := bmp.Height - bmp.Canvas.TextHeight(sBottomText); // //// if cbBottomTextPos.ItemIndex <> 0 then // // nLeft := bmp.Width - bmp.Canvas.TextWidth(sBottomText); // // // bmp.Canvas.TextOut(nLeft, nTop, sBottomText); // // // if CUSTOMER_TYPE = CUSTOMER_SOLIDEO then // begin //// SetImgFontSize(50); // 42에서 50으로 변경 25_0520 09:06:51 kku // sBottomText := '(주)솔리데오'; // if gParam.DeptName <> '' then // begin // var sDept: String := gParam.DeptName; // var nPos: Integer := Pos(';', sDept); // if nPos > 0 then // Delete(sDept, nPos, sDept.Length - nPos + 1); // SumString(sBottomText, sDept, ' / '); // end; // if gParam.UName <> '' then // SumString(sBottomText, gParam.UName, ' / ') // else // SumString(sBottomText, gParam.EmpNo, ' / '); // SumString(sBottomText, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now), ' / '); // end; // // if (png.Height > nH) and (WInfo.sPdfPath = '') then // 이거 왜 이렇게 했는지... 까먹음.. 24_0626 14:18:50 kku // nTop := (png.Height - ((png.Height - nH) div 2)) - png.Canvas.TextHeight(sBottomText) // else // nTop := png.Height - png.Canvas.TextHeight(sBottomText); // // if (png.Width > nW) and (WInfo.sPdfPath = '') then // nLeft := (png.Width - ((png.Width - nW) div 2)) - png.Canvas.TextWidth(sBottomText) // else // nLeft := png.Width - png.Canvas.TextWidth(sBottomText); // // case CUSTOMER_TYPE of // CUSTOMER_DEMO : // begin // // for 포스코 // if (png.Width > nW) and (WInfo.sPdfPath = '') then // png.Canvas.TextOut((png.Width - nW) div 2, nTop, sBottomText) // else // png.Canvas.TextOut(0, nTop, sBottomText); // // var sTemp: String; // := '포스코 허락없이 출력정보 훼손 또는 무단유통시 법적책임이 있습니다.'; // // if (png.Width > nW) and (WInfo.sPdfPath = '') then // // nLeft := (png.Width - ((png.Width - nW) div 2)) - png.Canvas.TextWidth(sTemp) // // else // // nLeft := png.Width - png.Canvas.TextWidth(sTemp); // // png.Canvas.TextOut(nLeft, nTop, sTemp); // // // if WInfo.LogJson <> '' then // begin // // 파일 이름으로 보안등급 출력 // try // // var OLog: ISuperObject := SO(WInfo.LogJson); // // if OLog <> nil then // begin // // var sFName: String := OLog.S['COMPONENT_FILENAME']; // var sFName: String := WInfo.sDocName; // // // 엑셀에 [ 가 ( 로 변경되서 급한대로 아래처럼 처리 24_1023 10:07:45 kku // sFName := StringReplace(sFName, '(', '[', [rfReplaceAll]); // sFName := StringReplace(sFName, ')', ']', [rfReplaceAll]); // // // if (sFName <> '') and (sFName[1] = '[') then // if sFName.Contains('[') then // begin // SetImgFontSize(png.Canvas.Font.Size * 2); // sTemp := GetCapsuleStr('[', ']', sFName); // if (png.Width > nW) and (WInfo.sPdfPath = '') then // nLeft := (png.Width - ((png.Width - nW) div 2)) - png.Canvas.TextWidth(sTemp) // else // nLeft := png.Width - png.Canvas.TextWidth(sTemp); // // png.Canvas.TextOut(nLeft, 0, sBottomText); // // 왜인지.. 위가 잘림 24_1022 09:20:15 kku // png.Canvas.TextOut(nLeft, png.Canvas.TextHeight(sTemp) div 2, sTemp); // end; // end; // except // // ... // end; // end; // end; // // CUSTOMER_KORENTAL : // begin // png.Canvas.Font.Color := clBlack; // SetImgFontSize(45); // // // 좌측 상단 // png.Canvas.TextOut(0, 0, sBottomText); // // if (png.Height > nH) and (WInfo.sPdfPath = '') then // 이거 왜 이렇게 했는지... 까먹음.. 24_0626 14:18:50 kku // nTop := (png.Height - ((png.Height - nH) div 2)) - png.Canvas.TextHeight(sBottomText) // else // nTop := png.Height - png.Canvas.TextHeight(sBottomText); // // // 가운데 하단 // sWText := '본 문서는 한국렌탈의 정보 자산이며 무단 반출 시 당사 사규와 관련 법규에 의해 제재를 받을 수 있습니다.'; // if (png.Width > nW) and (WInfo.sPdfPath = '') then // nLeft := ((png.Width - ((png.Width - nW) div 2)) div 2) - (png.Canvas.TextWidth(sWText) div 2) // else // nLeft := (png.Width div 2) - (png.Canvas.TextWidth(sWText) div 2); // png.Canvas.TextOut(nLeft, nTop, sWText); // end; // // CUSTOMER_WELFND, // CUSTOMER_WELFNI : // begin // png.Canvas.Font.Color := clSilver; // SetImgFontSize(46); // if (png.Height > nH) and (WInfo.sPdfPath = '') then // 이거 왜 이렇게 했는지... 까먹음.. 24_0626 14:18:50 kku // nTop := (png.Height - ((png.Height - nH) div 2)) - png.Canvas.TextHeight(sBottomText) // else // nTop := png.Height - png.Canvas.TextHeight(sBottomText); // // var nTW: Integer := png.Canvas.TextWidth(sBottomText); // // // 좌측 상단 // png.Canvas.TextOut(0, 0, sBottomText); // // // 우측 상단 // if (png.Width > nW) and (WInfo.sPdfPath = '') then // nLeft := (png.Width - ((png.Width - nW) div 2)) - png.Canvas.TextWidth(sBottomText) // else // nLeft := png.Width - png.Canvas.TextWidth(sBottomText); // png.Canvas.TextOut(nLeft, 0, sBottomText); // // // 좌측 하단 // png.Canvas.TextOut(0, nTop, sBottomText); // // // 우측 하단 // sWText := '본 문서에 대한 소유권은 회사에 있으며, 무단으로 반출 시 법적 책임을 받게 됩니다.'; // if (png.Width > nW) and (WInfo.sPdfPath = '') then // nLeft := (png.Width - ((png.Width - nW) div 2)) - png.Canvas.TextWidth(sWText) // else // nLeft := png.Width - png.Canvas.TextWidth(sWText); // png.Canvas.TextOut(nLeft, nTop, sWText); // //// sBottomText := sEmpNo_ + '/' + sPrtDocId; // if png.Width > png.Height then // begin // nLeft := CalcSizeDIP(936); //(png.Width div 2) - nTW - Round(nTW / 2); // nTop := CalcSizeDIP(292); //Round(png.Height / 8.5); // DrawRotatedText(png.Canvas, nLeft, nTop, -45, sBottomText); //// _Trace('**************** 1번째 대각선 : L=%d, T=%d', [nLeft, nTop]); // nLeft := CalcSizeDIP(2298); // (png.Width div 2) + png.Canvas.TextWidth(sBottomText); // nTop := CalcSizeDIP(1652); // png.Height - (png.Height div 3); // DrawRotatedText(png.Canvas, nLeft, nTop, -45, sBottomText); //// _Trace('**************** 2번째 대각선 : L=%d, T=%d', [nLeft, nTop]); // end else begin // nLeft := CalcSizeDIP(347);//(png.Width div 4) - png.Canvas.TextWidth(sBottomText) div 2; // nTop := CalcSizeDIP(779); // Round(png.Height / 4.5); // DrawRotatedText(png.Canvas, nLeft, nTop, -45, sBottomText); //// _Trace('**************** 1번째 대각선 : L=%d, T=%d', [nLeft, nTop]); // // nLeft := CalcSizeDIP(1784); //(png.Width div 2) + png.Canvas.TextWidth(sBottomText); // nTop := CalcSizeDIP(2338); //png.Height - (png.Height div 3); // DrawRotatedText(png.Canvas, nLeft, nTop, -45, sBottomText); //// _Trace('**************** 2번째 대각선 : L=%d, T=%d', [nLeft, nTop]); // end; // end; // CUSTOMER_SOLMIX : // begin // png.Canvas.Font.Color := clSilver; // SetImgFontSize(50); // if (png.Height > nH) and (WInfo.sPdfPath = '') then // 이거 왜 이렇게 했는지... 까먹음.. 24_0626 14:18:50 kku // nTop := (png.Height - ((png.Height - nH) div 2)) - png.Canvas.TextHeight(sBottomText) // else // nTop := png.Height - png.Canvas.TextHeight(sBottomText); // //// var nTW: Integer := png.Canvas.TextWidth(sBottomText); // // sWText := sBottomText + WInfo.sDocName; // // // 좌측 상단 // png.Canvas.TextOut(0, 0, sWText); // // 좌측 하단 // sWText := sBottomText + '보안 문서로서 무단 복사 및 외부 유출을 금합니다.'; // png.Canvas.TextOut(0, nTop, sWText); // // // 가운데 사선 // if png.Width < png.Height then // SetImgFontSize(png.Width div 9) // else // SetImgFontSize(png.Height div 9); // sWText := gParam.EmpNo; // var bmpW: TBitmap; // Guard(bmpW, TBitmap.Create); // bmpW.SetSize(png.Canvas.TextWidth(sWText), png.Canvas.TextHeight(sWText)); // bmpW.Canvas.Font := png.Canvas.Font; // bmpW.Canvas.Font.Color := clSilver; // bmpW.Canvas.TextOut(0, 0, sWText); // bmpW.TransparentColor := clWhite; // bmpW.Transparent := true; // RotateBitmap_PlgBlt(bmpW, -0.8, true, clWhite); // // var cTrMatrix: TColorMatrix; // ZeroMemory(@cTrMatrix, SizeOf(cTrMatrix)); // // 회색 // cTrMatrix[0][0] := 0.299; // cTrMatrix[0][1] := 0.299; // cTrMatrix[0][2] := 0.299; // cTrMatrix[1][0] := 0.587; // cTrMatrix[1][1] := 0.587; // cTrMatrix[1][2] := 0.587; // cTrMatrix[2][0] := 0.114; // cTrMatrix[2][1] := 0.114; // cTrMatrix[2][2] := 0.114; // cTrMatrix[3][3] := 0.22; // 투명도 1.0 ~ 2.22 // cTrMatrix[4][4] := 1.0; // // var nX: Integer := png.Width - (png.Width div 2) - (bmpW.Width div 2); // var nY: Integer := png.Height - (png.Height div 2) - (bmpW.Height div 2); // DrawBitmapWaterEx(png.Canvas.Handle, nX, nY, bmpW, @cTrMatrix); // end; // // CUSTOMER_GIORDANO, // CUSTOMER_CJONS : // begin // // 우측 하단 //// if (png.Width > nW) and (WInfo.sPdfPath = '') then  //// nLeft := (png.Width - ((png.Width - nW) div 2)) - png.Canvas.TextWidth(sBottomText) //// else //// nLeft := png.Width - png.Canvas.TextWidth(sBottomText); //// png.Canvas.TextOut(nLeft, nTop + png.Canvas.TextHeight(sBottomText), sBottomText); // //// sBottomText := Format('W=%d, H=%d, T=%d, TW=%d, TH=%d > ', [png.Width, png.Height, nTop, png.Canvas.TextWidth(sBottomText), png.Canvas.TextHeight(sBottomText)]) + sBottomText; // //// png.Canvas.TextOut(0, 0, sBottomText); //// png.Canvas.TextOut(0, (nTop div 2) + png.Canvas.TextHeight(sBottomText), sBottomText); // // // 수정 25_0520 15:45:27 kku // nLeft := png.Width - png.Canvas.TextWidth(sBottomText); // nTop := png.Height - png.Canvas.TextHeight(sBottomText); // png.Canvas.TextOut(nLeft, nTop, sBottomText); // end; // CUSTOMER_SHSC : // begin // png.Canvas.Font.Color := clGray; // // // 좌측 하단 // sWText := '고객정보 무단 반출시 법적 제재를 받을 수 있으며, 모든 출력물은 모니터링 됩니다.'; // if (png.Width > nW) and (WInfo.sPdfPath = '') then // png.Canvas.TextOut((png.Width - nW) div 2, nTop + png.Canvas.TextHeight(sWText), sWText) // 위로 밀리는 현상 있어서 조정 // else // png.Canvas.TextOut(0, nTop, sWText); // // // 우측 하단 //// if (png.Width > nW) and (WInfo.sPdfPath = '') then  //// nLeft := (png.Width - ((png.Width - nW) div 2)) - png.Canvas.TextWidth(sBottomText) //// else //// nLeft := png.Width - png.Canvas.TextWidth(sBottomText); // nLeft := png.Width - png.Canvas.TextWidth(sBottomText); // png.Canvas.TextOut(nLeft, nTop, sBottomText); // end; // // CUSTOMER_SHCI : // begin // png.Canvas.Font.Color := $969696; // // nTop := png.Height - png.Canvas.TextHeight(sBottomText); // // 우측 상단 // sWText := '고객정보 무단 반출시 법적 제재를 받을 수 있으며, 모든 출력물은 모니터링 됩니다.'; //// if (png.Width > nW) and (WInfo.sPdfPath = '') then //// nLeft := (png.Width - ((png.Width - nW) div 2)) - png.Canvas.TextWidth(sWText) //// else // nLeft := png.Width - png.Canvas.TextWidth(sWText); // // 왜인지.. 위가 잘림 24_1022 09:20:15 kku //// png.Canvas.TextOut(nLeft, png.Canvas.TextHeight(sWText), sWText); // png.Canvas.TextOut(nLeft, 0, sWText); // // // 좌측 하단 //// if (png.Width > nW) and (WInfo.sPdfPath = '') then //// png.Canvas.TextOut((png.Width - nW) div 2, nTop, sBottomText) //// else // png.Canvas.TextOut(0, nTop, sBottomText); // end; // // CUSTOMER_WINSTN : // begin // png.Canvas.Font.Color := $969696; // // if (png.Width > nW) and (WInfo.sPdfPath = '') then // nLeft := (png.Width - nW) div 2 // else // nLeft := 0; // // // 좌측 하단 // sWText := Format('%s / %s', [WInfo.sDocName, i + 1, ImgList.Count, sBottomText]); // png.Canvas.TextOut(nLeft, nTop, sWText); // // var nTextH: Integer := png.Canvas.TextHeight(sWText); // Dec(nTop, nTextH + (nTextH div 3)); // sWText := 'This document is property of the WINSTECHNET And may not be modlfied, copled or distributed without prior consent of the WINSTECHNET'; // png.Canvas.TextOut(nLeft, nTop, sWText); // // Dec(nTop, nTextH + (nTextH div 3)); // sWText := '이 문서는 ㈜윈스테크넷의 자산입니다.'; // png.Canvas.TextOut(nLeft, nTop, sWText); // end; // // CUSTOMER_SANKYO : // begin // png.Canvas.Font.Color := clGray; // // // 좌측 상단 // sWText := sBottomText; // if (png.Width > nW) and (WInfo.sPdfPath = '') then // png.Canvas.TextOut((png.Width - nW) div 2, 0, sWText) // else // png.Canvas.TextOut(0, 0, sWText); // // // 가운데 하단 // sWText := '본 문서는 한국다이이찌산쿄의 정보자산이며, 본 문서의 무단 유출/복사/도용 시 당사 사규와 관련 법규에 의해 제재 받을 수 있습니다.'; // if (png.Width > nW) and (WInfo.sPdfPath = '') then // nLeft := ((png.Width - ((png.Width - nW) div 2)) div 2) - (png.Canvas.TextWidth(sWText) div 2) // else // nLeft := (png.Width div 2) - (png.Canvas.TextWidth(sWText) div 2); // png.Canvas.TextOut(nLeft, nTop, sWText); // end; // else begin // png.Canvas.TextOut(nLeft, nTop, sBottomText); // // if CUSTOMER_TYPE <> CUSTOMER_SOLIDEO then // begin // // 프린터 문서 이름 추가 23_0826 15:51:34 kku // if (png.Width > nW) and (WInfo.sPdfPath = '') then // png.Canvas.TextOut((png.Width - nW) div 2, nTop, Format('%s', [WInfo.sDocName, i + 1, ImgList.Count])) // else // png.Canvas.TextOut(0, nTop, Format('%s', [WInfo.sDocName, i + 1, ImgList.Count])); // end; // end; // end; // end; // end; // // if not gParam.PrtWaterCfg.bActive then // 워터마크 설정을 사용하면 아래 무시 25_0728 14:38:41 kku // case CUSTOMER_TYPE of //// CUSTOMER_DEV, // CUSTOMER_ALADIN : // begin // if png.Width < png.Height then // SetImgFontSize(png.Width div 40) // else // SetImgFontSize(png.Height div 40); // // png.Canvas.Font.Name := '돋음'; // 폰트 지정하면 출력 안되는 현상이 있다? 24_0509 13:17:25 kku // png.Canvas.Font.Style := png.Canvas.Font.Style + [fsBold]; // // var sText: String := gParam.EmpNo + '/' + gParam.IP + '/' + FormatDateTime('yyyy-mm-dd', Now); // if png.Width < png.Height then // sText := sText + WORD_GAP + sText + WORD_GAP + sText // else // sText := sText + WORD_GAP + sText + WORD_GAP + sText + WORD_GAP + sText; // // var bmpT: TBitmap; // Guard(bmpT, TBitmap.Create); // bmpT.PixelFormat := pf4bit; // bmpT.SetSize(png.Canvas.TextWidth(sText), png.Canvas.TextHeight(sText)); // bmpT.Canvas.Font := png.Canvas.Font; // bmpT.Canvas.Font.Color := clSilver; // bmpT.Canvas.TextOut(0, 0, sText); // bmpT.TransparentColor := clWhite; // bmpT.Transparent := true; // // bmpT.SaveToFile('c:\1.bmp'); // RotateBitmap_PlgBlt(bmpT, -0.45, true, clWhite); // // var cTrMatrix: TColorMatrix; // ZeroMemory(@cTrMatrix, SizeOf(cTrMatrix)); // // 회색 // cTrMatrix[0][0] := 0.299; // cTrMatrix[0][1] := 0.299; // cTrMatrix[0][2] := 0.299; // cTrMatrix[1][0] := 0.587; // cTrMatrix[1][1] := 0.587; // cTrMatrix[1][2] := 0.587; // cTrMatrix[2][0] := 0.114; // cTrMatrix[2][1] := 0.114; // cTrMatrix[2][2] := 0.114; // cTrMatrix[3][3] := 0.242; // 투명도 1.0 ~ 2.22 // cTrMatrix[4][4] := 1.0; // // var nHH := png.Height div 2; // var nGapH: Integer := bmpT.Height; // var c: Integer := (nGapH div 2) * -1; // while c < nHH + nGapH do // begin // DrawBitmapWaterEx(png.Canvas.Handle, 0, c, bmpT, @cTrMatrix); // Inc(c, Round(nGapH / 1.5)); // end; // end; // CUSTOMER_KBIZ : // begin // SetBkMode(png.Canvas.Handle, TRANSPARENT); // SetImgFontSize(54); // png.Canvas.Font.Color := clSilver; // if (png.Height > nH) and (WInfo.sPdfPath = '') then // 이거 왜 이렇게 했는지... 까먹음.. 24_0626 14:18:50 kku // nTop := (png.Height - ((png.Height - nH) div 2)) - png.Canvas.TextHeight(sBottomText) // else // nTop := png.Height - png.Canvas.TextHeight(sBottomText); // // sBottomText := Format('%s %s', [gParam.EmpNo, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now)]); // if (png.Width > nW) and (WInfo.sPdfPath = '') then // png.Canvas.TextOut((png.Width - nW) div 2, nTop, sBottomText) // else // png.Canvas.TextOut(0, nTop, sBottomText); // // if png.Width < png.Height then // SetImgFontSize(png.Width div 18) // else // SetImgFontSize(png.Height div 18); // png.Canvas.Font.Style := png.Canvas.Font.Style + [fsBold]; // // var sText: String := 'KBIZ'; // var bmpW: TBitmap; // Guard(bmpW, TBitmap.Create); // bmpW.SetSize(png.Canvas.TextWidth(sText), png.Canvas.TextHeight(sText)); // bmpW.Canvas.Font.Assign(png.Canvas.Font); // bmpW.Canvas.Font.Color := clSilver; // bmpW.Canvas.TextOut(0, 0, sText); // bmpW.TransparentColor := clWhite; // bmpW.Transparent := true; // RotateBitmap_PlgBlt(bmpW, -0.8, true, clWhite); // // var cTrMatrix: TColorMatrix; // ZeroMemory(@cTrMatrix, SizeOf(cTrMatrix)); // // 회색 // cTrMatrix := MakeColorMatrix(0.2, 0.2, 0.2, 0.05); // // // 가운데 //// var nX: Integer := png.Width - (png.Width div 2) - (bmpW.Width div 2); //// var nY: Integer := png.Height - (png.Height div 2) - (bmpW.Height div 2); //// DrawBitmapWaterEx(png.Canvas.Handle, nX, nY, bmpW, @cTrMatrix); // // // 왼쪽위 // DrawBitmapWaterEx(png.Canvas.Handle, 0, 0, bmpW, @cTrMatrix); // // // 오른쪽아래 // var nX: Integer := png.Width - bmpW.Width; // var nY: Integer := png.Height - bmpW.Height; // DrawBitmapWaterEx(png.Canvas.Handle, nX, nY, bmpW, @cTrMatrix); // end; // CUSTOMER_JUVIS : // begin // if png.Width < png.Height then // SetImgFontSize(png.Width div 9) // else // SetImgFontSize(png.Height div 9); // // png.Canvas.Font.Name := '돋음'; // 폰트 지정하면 출력 안되는 현상이 있다? 24_0509 13:17:25 kku // png.Canvas.Font.Style := png.Canvas.Font.Style + [fsBold]; // // // var sText: String := '쥬비스 다이어트'; // var sText: String := 'JUVIS DIET'; // var bmpW: TBitmap; // Guard(bmpW, TBitmap.Create); // bmpW.SetSize(png.Canvas.TextWidth(sText), png.Canvas.TextHeight(sText)); // bmpW.Canvas.Font := png.Canvas.Font; // bmpW.Canvas.Font.Color := clSilver; // bmpW.Canvas.TextOut(0, 0, sText); // bmpW.TransparentColor := clWhite; // bmpW.Transparent := true; // RotateBitmap_PlgBlt(bmpW, -0.8, true, clWhite); // // var cTrMatrix: TColorMatrix; // ZeroMemory(@cTrMatrix, SizeOf(cTrMatrix)); // // 회색 // cTrMatrix[0][0] := 0.299; // cTrMatrix[0][1] := 0.299; // cTrMatrix[0][2] := 0.299; // cTrMatrix[1][0] := 0.587; // cTrMatrix[1][1] := 0.587; // cTrMatrix[1][2] := 0.587; // cTrMatrix[2][0] := 0.114; // cTrMatrix[2][1] := 0.114; // cTrMatrix[2][2] := 0.114; // cTrMatrix[3][3] := 0.22; // 투명도 1.0 ~ 2.22 // cTrMatrix[4][4] := 1.0; // // var nX: Integer := png.Width - (png.Width div 2) - (bmpW.Width div 2); // var nY: Integer := png.Height - (png.Height div 2) - (bmpW.Height div 2); // DrawBitmapWaterEx(png.Canvas.Handle, nX, nY, bmpW, @cTrMatrix); // end; // // CUSTOMER_WELFND, // CUSTOMER_WELFNI, // CUSTOMER_SHSC, // CUSTOMER_SHCI, // CUSTOMER_WINSTN, // CUSTOMER_SANKYO, // CUSTOMER_KORENTAL, // CUSTOMER_DEMO : // begin //// var sImgPath: String := GetRunExePathDir + DIR_CONF + 'CI.bmp'; // var sImgPath: String := 'C:\ProgramData\HE\CI.bmp'; // if FileExists(sImgPath) then // begin // try // var bmpW: TBitmap; // Guard(bmpW, TBitmap.Create); // bmpW.LoadFromFile(sImgPath); // // bmpW.PixelFormat := pf4bit; // // bmpW.TransparentColor := clWhite; // bmpW.Transparent := true; // // ScalePercentBmp(bmpW, GetDPI_Size(300)); // // var cTrMatrix: TColorMatrix := MakeColorMatrix(0.2, 0.2, 0.2, 0.05); // // var nX: Integer := png.Width - (png.Width div 2) - (bmpW.Width div 2); // var nY: Integer := png.Height - (png.Height div 2) - (bmpW.Height div 2); // DrawBitmapWaterEx(png.Canvas.Handle, nX, nY, bmpW, @cTrMatrix); // except // // .. // end; // end else // Result := false; // end; // // CUSTOMER_GEC : // begin // if _bmpWaterP = nil then // begin // var sImgPath: String := GetRunExePathDir + DIR_CONF + 'HWMJ.dat'; // if FileExists(sImgPath) then // begin // var sText: String := ''; // if gParam.DeptName <> '' then // sText := gParam.DeptName + '/' + gParam.EmpNo + '/' + gParam.IP + '/' + FormatDateTime('yyyy-mm-dd', Now) // else // sText := gParam.EmpNo + '/' + gParam.IP + '/' + FormatDateTime('yyyy-mm-dd', Now); // var nFontSize: Integer := png.Canvas.Font.Size; // while True do // begin // if nFontSize > 200 then // break; // // if png.Canvas.TextHeight(sText) > 180 then // 부서명이 들어간 후 2000에서 변경 // begin // Dec(nFontSize); // break; // end; // Inc(nFontSize); // png.Canvas.Font.Size := (nFontSize); // end; // // var jpg: TJPEGImage; // jpg := TJPEGImage.Create; // jpg.LoadFromFile(sImgPath); // // var bmpImg: TBitmap; // bmpImg := TBitmap.Create; // bmpImg.Assign(jpg); // jpg.Free; // Free // bmpImg.Canvas.Font.Assign(png.Canvas.Font); // bmpImg.Canvas.Font.Color := clSilver; // bmpImg.Canvas.Font.Size := nFontSize - (nFontSize div 2); // bmpImg.Canvas.Font.Style := bmpImg.Canvas.Font.Style + [fsBold]; // // //--- // // sOut := '정보보호부문/2323308/10.177.15.123/2023-12-31'; // // HEC 새로운 요구사항 반영 23_1121 10:22:09 kku // // bmpImg.Canvas.Font.Size := bmpImg.Canvas.Font.Size + 14; // // ScalePercentBmp(bmpImg, 120); // //--- // // var nWW := bmpImg.Canvas.TextWidth(sText); // if bmpImg.Width > nWW then // nWW := bmpImg.Width; // var nHH := bmpImg.Height + bmpImg.Canvas.TextHeight(sText); // _bmpWaterP := TBitmap.Create; // _bmpWaterP.Canvas.Font.Assign(bmpImg.Canvas.Font); // _bmpWaterP.PixelFormat := pf4bit; // _bmpWaterP.SetSize(nWW, nHH); // _bmpWaterP.Canvas.Brush.Color := clWhite; // _bmpWaterP.Canvas.Brush.Style := bsSolid; // _bmpWaterP.Canvas.FillRect(Rect(0, 0, _bmpWaterP.Width, _bmpWaterP.Height)); // _bmpWaterP.Canvas.Draw((nWW div 2) - (bmpImg.Width div 2), 0, bmpImg); // _bmpWaterP.Canvas.TextOut(0, bmpImg.Height, sText); // bmpImg.Free; // Free // // RotateBitmap_PlgBlt(_bmpWaterP, -0.7, true, clWhite); // // var ii: Integer; // var jj: Integer; // for ii := 0 to _bmpWaterP.Width - 1 do // for jj := 0 to _bmpWaterP.Height - 1 do // if _bmpWaterP.Canvas.Pixels[ii, jj] <> clWhite then // _bmpWaterP.Canvas.Pixels[ii, jj] := clGray; // // // ScalePercentBmp(_bmpWaterP, 60); //// ScalePercentBmp(_bmpWaterP, 130); // 늘리는거 쓰면 이미지가 빈값이 되는 문제가 있음 24_0514 08:30:40 kku // _bmpWaterP.TransparentColor := clWhite; // _bmpWaterP.Transparent := true; // end; // end; // // if _bmpWaterP <> nil then // begin // // 추가 24_0626 17:31:52 kku // var cTrMatrix: TColorMatrix; // ZeroMemory(@cTrMatrix, SizeOf(cTrMatrix)); // // 회색 // cTrMatrix[0][0] := 0.299; // cTrMatrix[0][1] := 0.299; // cTrMatrix[0][2] := 0.299; // cTrMatrix[1][0] := 0.587; // cTrMatrix[1][1] := 0.587; // cTrMatrix[1][2] := 0.587; // cTrMatrix[2][0] := 0.114; // cTrMatrix[2][1] := 0.114; // cTrMatrix[2][2] := 0.114; // cTrMatrix[3][3] := 0.22; // 투명도 1.0 ~ 2.22 // cTrMatrix[4][4] := 1.0; // // var nIW: Integer := png.Width; // var nIH: Integer := png.Height; // var nX := (nIW div 2) - (_bmpWaterP.Width div 2); // var nY := (nIH div 2) - (nIH div 3); // DrawBitmapWaterEx(png.Canvas.Handle, nX, nY, _bmpWaterP, @cTrMatrix); // // nY := (nIH div 2) + (nIH div 10); // DrawBitmapWaterEx(png.Canvas.Handle, nX, nY, _bmpWaterP, @cTrMatrix); // //// _bmpWaterP.SaveToFile('c:\0.bmp'); //// png.SaveToFile('c:\1.png'); // // SetBkMode(png.Canvas.Handle, TRANSPARENT); // png.Canvas.Font.Color := clGray; // SetImgFontSize(Round(_bmpWaterP.Canvas.Font.Size * 1.3)); // sBottomText := gParam.LabelName; // '대외비(Restricted)'; // if sBottomText <> '' then // begin // nLeft := png.Width - png.Canvas.TextWidth(sBottomText); // nTop := 0; // png.Canvas.TextOut(nLeft, nTop, sBottomText); // end; // // sBottomText := 'Security Starts with Small Habits'; // nLeft := png.Width - png.Canvas.TextWidth(sBottomText); // nTop := png.Height - png.Canvas.TextHeight(sBottomText); // png.Canvas.TextOut(nLeft, nTop, sBottomText); // // SetImgFontSize(_bmpWaterP.Canvas.Font.Size div 2); // sBottomText := 'This document or drawing is the property of Hyundai Engineering. Any reproduction or distribution of the materials without permission of Hyundai engineering is strictly prohibited.'; // nLeft := 0; // nTop := png.Height - png.Canvas.TextHeight(sBottomText); // png.Canvas.TextOut(0, nTop, sBottomText); // //// png.SaveToFile('c:\2.png'); // end; // end; // // else Result := false; // end; // // // 용지를 출력 옵션대로 변경하기 때문에 다시 원래대로 안돌려도 된다 25_0904 10:09:55 kku //// if bRotate then //// begin //// nTmp := nW; //// nW := nH; //// nH := nTmp; //// RotatePng(png, -90); //// end; // // if Result then // begin // if aDest <> 0 then // begin // StretchBlt(aDest, 0, 0, nW, nH, // png.Canvas.Handle, 0, 0, png.Width, png.Height, SRCCOPY); // end; // end; // except // on E: Exception do // begin // Result := false; // ETgException.TraceException(Self, E, 'Fail .. ProcessWatermark()'); // end; // end; // end; Label LB_CollatePdf, LB_CollatePng, LB_CollateEmf, LB_Collate1; begin TTgTrace.T('ProcessPrint() ... 1'); nStep := 0; // _bmpST := nil; bmpWaterP := nil; dlg := nil; try // if FindWindow('TDlgWaitExtrProcPrt', nil) <> 0 then // exit; if Printer.Printing then exit; WInfo := gParam.PrtWaterEnt; // WInfo.sImgPath := 'C:\Users\kku\Desktop\이전 바탕화면\spl2pdf_cmd\_test\스풀데이터_20250903164023.pdf'; sExt := GetFileExt(WInfo.sImgPath).ToUpper; if sExt = 'PDF' then ProcType := ptPdf else if sExt = 'EM1' then ProcType := ptEmf else ProcType := ptPng; OrgDevMode := TTgRtti.StrToSetType(WInfo.DevMode); if gParam.IsAdvancePrtProg then begin // SendData(gParam.RcvWnd, KV_PRTWM_PROGRESS, 'next'); PostMessage(gParam.RcvWnd, WM_POPUP_PRTW_PROGRESS, 2, 0); end; dlg := TDlgWaitExtrProcPrt.Create(Self, WInfo.dwTotalPage); if gParam.IsAdvancePrtProg then begin // 드러나는 폼이 있어야 PDF 출력 시 BeginDoc()에서 파일 선택 창이 나온다... // 그래서 아래처럼 폼을 숨겨서 보여주는 식으로 사용 함 25_0626 22:40:32 kku dlg.FormStyle := fsNormal; dlg.Position := poDesigned; dlg.Top := Screen.DesktopTop - (dlg.Height * 2); dlg.Show; end else if not IsHidePrtProgPopup and not gParam.NoPrtPopup then dlg.Show; Application.ProcessMessages; png := nil; mf := nil; try Guard(ImgList, TStringList.Create); case ProcType of ptPdf : ; ptPng : begin ExtrPrintImgFiles(WInfo.sImgPath, ImgList); if ImgList.Count = 0 then exit; png := TPngImage.Create; sImgPath := ImgList[0]; png.LoadFromFile(sImgPath); end; ptEmf : begin sImgDir := ExtractFilePath(WInfo.sImgPath); ExtrFilesFromDir(sImgDir, ImgList, false, 'em1'); if ImgList.Count = 0 then exit; mf := TMetafile.Create; sImgPath := sImgDir + ImgList[0]; mf.LoadFromFile(sImgPath); end; end; TTgTrace.T('ProcessPrint() ... 2'); sTopText := ''; //Trim(edTopText.Text); // sBottomText := Format('%s/%s', [gParam.EmpNo, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now)]); // Trim(edBottomText.Text); sBottomText := gParam.DefPrtWaterTxt; // try // case CUSTOMER_TYPE of // CUSTOMER_WELFND, // CUSTOMER_WELFNI : // begin // var sTemp: String := gParam.PrtDocId; // if sTemp.Length > 20 then // SetLength(sTemp, 20); // // sBottomText := gParam.EmpNo + '/' + sTemp; // end; // CUSTOMER_KORENTAL : // begin // if gParam.UName <> '' then // sBottomText := Format('%s/%s/%s/%s/%s', [gParam.EmpNo, gParam.DeptName, gParam.UName, gParam.IP, FormatDateTime('yyyy-mm-dd hh:nn', Now)]) // else if gParam.DeptName <> '' then // sBottomText := Format('%s/%s/%s/%s', [gParam.EmpNo, gParam.DeptName, gParam.IP, FormatDateTime('yyyy-mm-dd hh:nn', Now)]) // else // sBottomText := Format('%s/%s/%s', [gParam.EmpNo, gParam.IP, FormatDateTime('yyyy-mm-dd hh:nn', Now)]) // end; // CUSTOMER_CJONS : // begin // var sDept: String := ExtrLastDelimiterStr(gParam.DeptName, ';'); // var sUName: String := gParam.UName; // if sUName = '' then // sUname := gParam.EmpNo; // if sDept <> '' then // sBottomText := Format('%s/%s/%s', [sUName, sDept, FormatDateTime('yyyy-mm-dd hh:nn', Now)]) // else // sBottomText := Format('%s/%s', [sUName, FormatDateTime('yyyy-mm-dd hh:nn', Now)]); // end; // CUSTOMER_SHSC : // begin // var sEmpNo: String := gParam.EmpNo; // if sEmpNo.Length > 2 then // sEmpNo[3] := '*'; // if sEmpNo.Length > 3 then // sEmpNo[4] := '*'; // // if gParam.UName <> '' then // begin // var sUName: String := gParam.UName; // if sUName.Length > 1 then // sUName[2] := '*'; // sBottomText := Format('%s / %s / %s', [sUName, sEmpNo, FormatDateTime('yyyy-mm-dd hh:nn', Now)]) // end else // sBottomText := Format('%s / %s', [sEmpNo, FormatDateTime('yyyy-mm-dd hh:nn', Now)]); // end; // CUSTOMER_SHCI : // begin // if gParam.UName <> '' then // begin // var sUName: String := gParam.UName; // if sUName.Length > 1 then // sUName[2] := '*'; // sBottomText := Format('%s / %s / %s / %s', [gParam.EmpNo, sUName, gParam.DeptName, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now)]); // end else // if gParam.DeptName <> '' then // sBottomText := Format('%s / %s / %s', [gParam.EmpNo, gParam.DeptName, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now)]) // else // sBottomText := Format('%s / %s', [gParam.EmpNo, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now)]); // end; // CUSTOMER_GIORDANO : // begin // sBottomText := Format('%s / %s', [gParam.EmpNo, DateTimeToStr(Now)]); // end; // CUSTOMER_MOTRAS : // begin // if gParam.UName <> '' then // sBottomText := Format('%s / %s / %s / %s / %s', [gParam.UName, gParam.DeptName, gParam.EmpNo, gParam.IP, FormatDateTime('yyyy-mm-dd hh:nn', Now)]) // else if gParam.DeptName <> '' then // sBottomText := Format('%s / %s / %s / %s', [gParam.DeptName, gParam.EmpNo, gParam.IP, FormatDateTime('yyyy-mm-dd hh:nn', Now)]) // else // sBottomText := Format('%s / %s / %s', [gParam.EmpNo, gParam.IP, FormatDateTime('yyyy-mm-dd hh:nn', Now)]); // end; // CUSTOMER_SOLMIX : // begin // sBottomText := Format('%s / %s / ', [gParam.EmpNo, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now)]); // end; // CUSTOMER_SANKYO : // begin // if gParam.UName <> '' then // sBottomText := Format('%s / %s / %s', [gParam.UName, gParam.EmpNo, FormatDateTime('yyyy-mm-dd hh:nn', Now)]) // else // sBottomText := Format('%s / %s', [gParam.EmpNo, FormatDateTime('yyyy-mm-dd hh:nn', Now)]); // end; // else begin // if gParam.UName <> '' then // sBottomText := Format('%s / %s / %s / %s', [gParam.UName, gParam.DeptName, gParam.EmpNo, FormatDateTime('yyyy-mm-dd hh:nn', Now)]) // else if gParam.DeptName <> '' then // sBottomText := Format('%s / %s / %s', [gParam.DeptName, gParam.EmpNo, FormatDateTime('yyyy-mm-dd hh:nn', Now)]) // else // sBottomText := Format('%s / %s', [gParam.EmpNo, FormatDateTime('yyyy-mm-dd hh:nn', Now)]); // end; // end; // except // sBottomText := 'Error'; // end; TTgTrace.T('ProcessPrint() ... 3'); // Guard(ImgEn, TImageEn.Create(nil)); // Guard(F, TFont.Create); // F.Size := 200; // 400 // if png.Width > png.Height then // F.Orientation := 50 // 가로 // else // F.Orientation := 300; // 세로 // F.Color := clSilver; // $F1F1F1; // clSilver; // clGray; // F.Style := png.Canvas.Font.Style + [fsBold]; pi := -1; // WInfo.sPtrName := 'Canon Generic Plus UFR II'; for i := 0 to Printer.Printers.Count - 1 do begin if Printer.Printers[i] = WInfo.sPtrName then pi := i; end; if pi = -1 then begin TTgTrace.T('프린터 찾기 실패 .. Name=%s', [WInfo.sPtrName]); exit; end; Printer.PrinterIndex := pi; if not WInfo.bUseWM then Printer.Title := WInfo.sDocName + ' *BSOne-' else Printer.Title := WInfo.sDocName + ' *BSOne'; TTgTrace.T('ProcessPrint() ... 4'); hDev := 0; Printer.GetPrinter(arrDevice, arrDriver, arrPort, hDev); if hDev = 0 then exit; var nCopies: Integer := OrgDevMode.dmCopies; var nCopies0: Integer; var dmCollate: DWORD := OrgDevMode.dmCollate; DevMode := GlobalLock(hDev); try // 항상 1부로 나오도록 조정, 설정된 출력은 별도 처리 25_0604 13:01:05 kku OrgDevMode.dmCopies := 1; if ProcType <> ptPdf then begin if WInfo.bPaperV then OrgDevMode.dmOrientation := DMORIENT_PORTRAIT else OrgDevMode.dmOrientation := DMORIENT_LANDSCAPE; end; // DevMode.dmPaperSize := WInfo.dwPageSizeT; DevMode^ := OrgDevMode; // DevMode.dmColor := DMCOLOR_COLOR; // DMCOLOR_MONOCHROME // DevMode.dmColor := DMCOLOR_MONOCHROME; // DMCOLOR_MONOCHROME Printer.SetPrinter(arrDevice, arrDriver, arrPort, hDev); finally GlobalUnlock(hDev); end; TTgTrace.T('ProcessPrint() ... 4 1'); // 용지 가로, 세로 돌릴려면 Printer.BeginDoc 전에 해야한다.. // 일부 프로그램에서 오류남 23_0623 08:45:27 kku // try // if not bIsOutPdf then // begin // if WInfo.bPaperV then // Printer.Orientation := poPortrait // else // Printer.Orientation := poLandscape; // end; // TTgTrace.T('ProcessPrint() ... 4 2'); // except // on E: Exception do // ETgException.TraceException(Self, E, 'Fail .. Set Printer.Orientation'); // end; TTgTrace.T('ProcessPrint() ... 4 3, ImgCnt=%d', [ImgList.Count]); // 신도 프린터에서는 부수 세팅을 1로 하고 스플에 여러부수(Copies) 출력 정보를 넣어준다... 25_0604 19:27:20 kku // 아래처럼 보완 처리, dmCollate는 항상 0으로 표시됨... // TTgTrace.T('ProcessPrint() .. 1, dmCollate=%d, TotalP=%d, Copies=%d, ImgCnt=%d', [dmCollate, WInfo.dwTotalPage, nCopies, ImgList.Count]); if (WInfo.dwTotalPage > 0) and (WInfo.dwTotalPage < ImgList.Count) then begin TTgTrace.T('ProcessPrint() ... 4 4'); nCopies := ImgList.Count div WInfo.dwTotalPage; dmCollate := 1; // 한 부씩 인쇄로 고정... // TTgTrace.T('ProcessPrint() .. 2, SetCopies..%d', [nCopies]); // 총 출력 부스만큼 이미지가 추출된 경우 처리... 25_0604 19:15:34 kku for i := ImgList.Count - 1 downto 0 do begin if (i mod nCopies) > 0 then ImgList.Delete(i); end; TTgTrace.T('ProcessPrint() ... 4 5'); end; // TTgTrace.T('ProcessPrint() .. 3, ImgCnt=%d', [ImgList.Count]); nW := 0; nH := 0; TTgTrace.T('ProcessPrint() ... 4 6'); {$IF false} TTgTrace.T('ProcessPrint() ... 4-1'); // Printer.BeginDoc; try for i := 0 to ImgList.Count - 1 do begin // if not Printer.Printing or Printer.Aborted then // break; if nW = 0 then begin // nW := GetDeviceCaps(Printer.Canvas.Handle, HORZRES); // nH := GetDeviceCaps(Printer.Canvas.Handle, VERTRES); end; try if i <> 0 then begin try if png <> nil then FreeAndNil(png); // i = 0은 위에서 미리 불러옴 png := TPngImage.Create; sImgPath := ImgList[i]; png.LoadFromFile(sImgPath); except {$IFDEF DEBUG} ASSERT(false); {$ENDIF} break; end; // Printer.NewPage; end; if gParam.IsPrtSpl2Pdf then // SendData(gParam.RcvWnd, KV_PRTWM_PROGRESS, IntToStr(i + 1)); PostMessage(gParam.RcvWnd, WM_POPUP_PRTW_PROGRESS, 0, i + 1); dlg.SetPagePos(i + 1); if not ProcessWatermark(0, sImgPath) then begin // pngRect.Right := nW; // pngRect.Bottom := nH; // // if png.Width > nW then // begin // pngRect.Left := (png.Width - nW) div 2; // pngRect.Width := nW; // end; // if png.Height > nH then // begin // pngRect.Top := (png.Height - nH) div 2; // pngRect.Height := nH; // end; png.SaveToFile(Format('c:\test-%d.png', [i + 1])); // StretchBlt(Printer.Canvas.Handle, 0, 0, nW, nH, // png.Canvas.Handle, 0, 0, png.Width, png.Height, SRCCOPY); end; except on E: Exception do ETgException.TraceException(Self, E, Format('Fail .. DoPrint .. Step=%d', [nStep])); end; end; finally // if Printer.Printing then // Printer.EndDoc; end; {$ELSE} TTgTrace.T('ProcessPrint() ... 5'); if gParam.ForcePdfPath <> '' then begin TTgTrace.T('ProcessPrint() ... 6, Pdf=%s', [gParam.ForcePdfPath]); var pdf: TPdfDocumentGDI; Guard(pdf, TPdfDocumentGDI.Create); // pdf.UseUniscribe := true; // pdf.StandardFontsReplace := true; // pdf.UseFontFallBack := false; // pdf.FontFallBackName := 'Tahoma'; pdf.ScreenLogPixels := 300; // 600; case OrgDevMode.dmPaperSize of DMPAPER_LETTERSMALL : begin pdf.DefaultPaperSize := psUserDefined; pdf.DefaultPageWidth := 216 * 72; pdf.DefaultPageHeight := 280 * 72; end; DMPAPER_LETTER : pdf.DefaultPaperSize := psLetter; DMPAPER_LEGAL : pdf.DefaultPaperSize := psLegal; DMPAPER_A3 : pdf.DefaultPaperSize := psA3; DMPAPER_A4 : pdf.DefaultPaperSize := psA4; DMPAPER_A4SMALL : begin pdf.DefaultPaperSize := psUserDefined; pdf.DefaultPageWidth := 210 * 72; pdf.DefaultPageHeight := 297 * 72; end; DMPAPER_A5 : pdf.DefaultPaperSize := psA5; DMPAPER_B4 : begin pdf.DefaultPaperSize := psUserDefined; pdf.DefaultPageWidth := 250 * 72; pdf.DefaultPageHeight := 354 * 72; end; DMPAPER_B5 : begin pdf.DefaultPaperSize := psUserDefined; pdf.DefaultPageWidth := 182 * 72; pdf.DefaultPageHeight := 257 * 72; end; end; if ProcType <> ptPdf then begin TTgTrace.T('ProcessPrint() ... 7'); if png.Width > png.Height then begin var nSizeTemp: Integer := pdf.DefaultPageHeight; pdf.DefaultPageHeight := pdf.DefaultPageWidth; pdf.DefaultPageWidth := nSizeTemp; end; end; var pdfPage: SynPdf.TPdfPage := pdf.AddPage; pdf.VCLCanvas.Brush.Style := bsClear; pdf.VCLCanvas.Font.Name := 'Tahoma'; nW := pdf.VCLCanvasSize.Width; nH := pdf.VCLCanvasSize.Height; case ProcType of ptPdf : ; ptPng : begin TTgTrace.T('ProcessPrint() ... 8, ImgCnt=%d', [ImgList.Count]); for i := 0 to ImgList.Count - 1 do begin try if i <> 0 then begin try if png <> nil then FreeAndNil(png); // i = 0은 위에서 미리 불러옴 png := TPngImage.Create; sImgPath := ImgList[i]; png.LoadFromFile(sImgPath); except break; end; pdfPage := pdf.AddPage; end; if gParam.IsAdvancePrtProg then PostMessage(gParam.RcvWnd, WM_POPUP_PRTW_PROGRESS, 0, i + 1); dlg.SetPagePos(i + 1); // if not ProcessWatermark(Printer.Canvas.Handle, sImgPath) then if (ProcType <> ptPng) or not ProcessWatermarkToImage(png, Printer.Canvas.Handle, nW, nH, WInfo, gParam.ValSnaptag, sTopText, sBottomText, bmpWaterP, sImgPath) then begin // pdf.VCLCanvas.StretchDraw() - 이게 어느날 갑자기 안되기 시작했다;;; 24_0930 15:30:53 kku StretchBlt(pdf.VCLCanvas.Handle, 0, 0, nW, nH, png.Canvas.Handle, 0, 0, png.Width, png.Height, SRCCOPY); end; except on E: Exception do ETgException.TraceException(Self, E, 'Fail .. PrintPDF .. 1'); end; end; end; ptEmf : begin begin TTgTrace.T('ProcessPrint() ... 8, ImgCnt=%d', [ImgList.Count]); for i := 0 to ImgList.Count - 1 do begin try if i <> 0 then begin try if mf <> nil then FreeAndNil(mf); // i = 0은 위에서 미리 불러옴 mf := TMetafile.Create; sImgPath := sImgDir + ImgList[i]; mf.LoadFromFile(sImgPath); if (mf.MMWidth = 0) or (mf.MMHeight = 0) then continue; except break; end; pdfPage := pdf.AddPage; end; if gParam.IsAdvancePrtProg then PostMessage(gParam.RcvWnd, WM_POPUP_PRTW_PROGRESS, 0, i + 1); dlg.SetPagePos(i + 1); pdf.VCLCanvas.StretchDraw(Rect(0, 0, nW, nH), mf); except on E: Exception do ETgException.TraceException(Self, E, 'Fail .. PrintPDF .. 2'); end; end; end; end; end; try pdf.SaveToFile(gParam.ForcePdfPath); except on E: Exception do ETgException.TraceException(Self, E, 'Fail .. PrintPDF .. 2'); end; end else begin TTgTrace.T('ProcessPrint() ... 6.'); Printer.BeginDoc; try TTgTrace.T('ProcessPrint() ... 6.1.'); if not Printer.Printing or Printer.Aborted then exit; TTgTrace.T('ProcessPrint() ... 6.2'); LB_Collate1 : case ProcType of ptPdf : begin TTgTrace.T('ProcessPrint() ... 7'); var doc: EM.PdfiumCore.TPdfDocument; Guard(doc, EM.PdfiumCore.TPdfDocument.Create); doc.LoadFromFile(WInfo.sImgPath); nW := GetDeviceCaps(Printer.Canvas.Handle, HORZRES); nH := GetDeviceCaps(Printer.Canvas.Handle, VERTRES); var page: EM.PdfiumCore.TPdfPage; var bIsPageLoad, bPagePortraitOrientation: Boolean; var nPageW, nPageH: Integer; bPagePortraitOrientation := nW > nH; TTgTrace.T('ProcessPrint() ... 8'); // FPU 예외 마스킹 (부동소수점 예외를 무시하게 함) >> PDFium 버그... 25_0612 16:12:04 kku // 현재 FPU 컨트롤 워드 저장 var SavedCW: WORD := Get8087CW; try // 모든 FPU 예외 마스크 SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]); // var bmp: TBitmap := nil; // Guard(bmp, TBitmap.Create); // bmp.PixelFormat := pf32bit; // bmp.Canvas.Brush.Color := clWhite; // bmp.SetSize(nW, nH); for i := 0 to doc.PageCount - 1 do begin if not Printer.Printing or Printer.Aborted then break; nPageW := nW; nPageH := nH; if i <> 0 then Printer.NewPage; // bIsPageLoad := doc.IsPageLoaded(i); try page := doc.Pages[i]; // if bPagePortraitOrientation <> (Trunc(page.Width) > Trunc(page.Height)) then // begin // var nTmp: Integer := nPageW; // nPageW := nPageH; // nPageH := nTmp; // end; TTgTrace.T('ProcessPrint() ... 9 - %d', [i]); nCopies0 := nCopies; if gParam.IsAdvancePrtProg then PostMessage(gParam.RcvWnd, WM_POPUP_PRTW_PROGRESS, 0, i + 1); dlg.SetPagePos(i + 1); LB_CollatePdf : // page.Draw(Printer.Handle, 0, 0, nPageW, nPageH, prNormal, [proPrinting, proNoNativeText, proNoCatch]); if bPagePortraitOrientation <> (Trunc(page.Width) > Trunc(page.Height)) then page.Draw(Printer.Handle, 0, 0, nPageW, nPageH, pr90Clockwise, [proPrinting, proNoCatch]) else page.Draw(Printer.Handle, 0, 0, nPageW, nPageH, prNormal, [proPrinting, proNoCatch]); // if bmp <> nil then // begin // if bPagePortraitOrientation <> (Trunc(page.Width) > Trunc(page.Height)) then // page.Draw(bmp.Canvas.Handle, 0, 0, nPageW, nPageH, pr90Clockwise, [proPrinting, proNoCatch]) // else // page.Draw(bmp.Canvas.Handle, 0, 0, nPageW, nPageH, prNormal, [proPrinting, proNoCatch]); // bmp.SaveToFile(Format('C:\test\%d.bmp', [i])); // bmp.Canvas.FillRect(Rect(0, 0, bmp.Width, bmp.Height)); // end; Dec(nCopies0); if (dmCollate = 0) and (nCopies0 > 0) then begin Printer.NewPage; goto LB_CollatePdf end; finally // if not bIsPageLoad and (page <> nil) then // page.Close; end; end; finally // 원래 상태 복원 Set8087CW(SavedCW); end; Dec(nCopies); if (dmCollate <> 0) and (nCopies > 0) then begin Printer.NewPage; goto LB_Collate1; end; TTgTrace.T('ProcessPrint() ... 10'); end; ptPng : begin for i := 0 to ImgList.Count - 1 do begin if not Printer.Printing or Printer.Aborted then break; try if i <> 0 then begin try if png <> nil then FreeAndNil(png); // i = 0은 위에서 미리 불러옴 png := TPngImage.Create; sImgPath := ImgList[i]; png.LoadFromFile(sImgPath); except {$IFDEF DEBUG} ASSERT(false); {$ENDIF} break; end; Printer.NewPage; end; nW := GetDeviceCaps(Printer.Canvas.Handle, HORZRES); nH := GetDeviceCaps(Printer.Canvas.Handle, VERTRES); nCopies0 := nCopies; if gParam.IsAdvancePrtProg then PostMessage(gParam.RcvWnd, WM_POPUP_PRTW_PROGRESS, 0, i + 1); dlg.SetPagePos(i + 1); LB_CollatePng : // if not ProcessWatermark(Printer.Canvas.Handle, sImgPath) then if (ProcType <> ptPng) or not ProcessWatermarkToImage(png, Printer.Canvas.Handle, nW, nH, WInfo, gParam.ValSnaptag, sTopText, sBottomText, bmpWaterP, sImgPath) then begin // png.SaveToFile(Format('c:\test\test-%d.png', [i + 1])); StretchBlt(Printer.Canvas.Handle, 0, 0, nW, nH, png.Canvas.Handle, 0, 0, png.Width, png.Height, SRCCOPY); end; Dec(nCopies0); if (dmCollate = 0) and (nCopies0 > 0) then begin Printer.NewPage; goto LB_CollatePng; end; except on E: Exception do ETgException.TraceException(Self, E, Format('Fail .. DoPrint .. Step=%d', [nStep])); end; end; Dec(nCopies); if (dmCollate <> 0) and (nCopies > 0) then begin if png <> nil then FreeAndNil(png); png := TPngImage.Create; sImgPath := ImgList[0]; png.LoadFromFile(sImgPath); Printer.NewPage; goto LB_Collate1; end; end; ptEmf : begin for i := 0 to ImgList.Count - 1 do begin if not Printer.Printing or Printer.Aborted then break; try if i <> 0 then begin try if mf <> nil then FreeAndNil(mf); // i = 0은 위에서 미리 불러옴 mf := TMetafile.Create; sImgPath := sImgDir + ImgList[i]; mf.LoadFromFile(sImgPath); if (mf.MMWidth = 0) or (mf.MMHeight = 0) then continue; except {$IFDEF DEBUG} ASSERT(false); {$ENDIF} break; end; Printer.NewPage; end; nW := GetDeviceCaps(Printer.Canvas.Handle, HORZRES); nH := GetDeviceCaps(Printer.Canvas.Handle, VERTRES); nCopies0 := nCopies; if gParam.IsAdvancePrtProg then PostMessage(gParam.RcvWnd, WM_POPUP_PRTW_PROGRESS, 0, i + 1); dlg.SetPagePos(i + 1); LB_CollateEmf : Printer.Canvas.StretchDraw(Rect(0, 0, nW, nH), mf); Dec(nCopies0); if (dmCollate = 0) and (nCopies0 > 0) then begin Printer.NewPage; goto LB_CollateEmf; end; except on E: Exception do ETgException.TraceException(Self, E, Format('Fail .. DoPrint .. Step=%d', [nStep])); end; end; Dec(nCopies); if (dmCollate <> 0) and (nCopies > 0) then begin if mf <> nil then FreeAndNil(mf); mf := TMetafile.Create; sImgPath := sImgDir + ImgList[0]; mf.LoadFromFile(sImgPath); Printer.NewPage; goto LB_Collate1; end; end; end; finally if Printer.Printing then Printer.EndDoc; end; end; {$IFEND} finally if png <> nil then FreeAndNil(png); if mf <> nil then FreeAndNil(mf); if bmpWaterP <> nil then FreeAndNil(bmpWaterP); DeleteDir(ExtractFilePath(WInfo.sImgPath)); if dlg <> nil then FreeAndNil(dlg); TerminateProcess(GetCurrentProcess, 9); end; except on E: Exception do begin ETgException.TraceException(Self, E, Format('Fail .. ProcessPrintWaterEnt(), Step=%d', [nStep])); end; end; end; end.