2011年1月28日金曜日

iTextSharpでPDFファイル結合

using iTextSharp.text;
using iTextSharp.text.pdf;

//出力ファイルが存在している場合は削除
//1番目のファイルが合体するファイル
if (File.Exists(args[0].ToString()))
{
File.Delete(args[0].ToString());
}

Document doc = null; // 出力ファイルDocument
PdfCopy copy = null; // 出力ファイルPdfCopy

try
{
//-------------------------------------------------------------------------------------
// ファイル件数分、ファイル結合
//-------------------------------------------------------------------------------------
for (int i = 1; i < args.Length; i++)
{
// リーダー取得
PdfReader reader = new PdfReader(args[i].ToString());

// 入力ファイル1を出力ファイルの雛形にする
if (i == 1)
{
// Document作成
doc = new Document(reader.GetPageSizeWithRotation(1));

// 出力ファイルPdfCopy作成
copy = new PdfCopy(doc, new FileStream(args[0].ToString(), FileMode.Create));

// 出力ファイルDocumentを開く
doc.Open();

// 文章プロパティ設定
doc.AddKeywords((string)reader.Info["Keywords"]);
doc.AddAuthor((string)reader.Info["Author"]);
doc.AddTitle((string)reader.Info["Title"]);
doc.AddCreator((string)reader.Info["Creator"]);
doc.AddSubject((string)reader.Info["Subject"]);
}

// PDFコンテンツを取得、copyオブジェクトに追加
for (int iPageCnt = 1; iPageCnt <= reader.NumberOfPages; iPageCnt++)
{
PdfImportedPage page = copy.GetImportedPage(reader, iPageCnt);
copy.AddPage(page);
}

// フォーム入力を結合
PRAcroForm form = reader.AcroForm;
if (form != null)
copy.CopyAcroForm(reader);

// リーダーを閉じる
reader.Close();
}
}
finally
{
if (copy != null)
copy.Close();

if (doc != null)
doc.Close();
}

vbscriptでショートカット(リンクアイコン)を作成

デスクトップ上にシュートカットアイコンを作成します

Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("WScript.Shell")
desktop = ws.SpecialFolders("Desktop")
' ショートカット作成
Set shortcut = ws.CreateShortcut(desktop & "\Lotus Notes 7.lnk")
With shortcut
.TargetPath = "C:\Program Files\lotus\notes\notes.exe"
.WorkingDirectory = desktop
.Save
End With

2011年1月27日木曜日

iTextSharpの文字印刷

//文字列の出力
//フォントの作成(使用するフォントをあらかじめ準備)
Font font = new Font(
BaseFont.CreateFont(@"c:\windows\fonts\msgothic.ttc,0", BaseFont.IDENTITY_H,
BaseFont.NOT_EMBEDDED));

pcb.BeginText();
//文字の出力(文字の出力時は必ず、BeginTextとEndTextで囲む必要がある)

pcb.SetFontAndSize(font.BaseFont, 16);

//構成・出力文字列・X・Y・rotation(回転):水平時は0
pcb.ShowTextAligned(Element.ALIGN_LEFT, "BarCode", 10, 380, 270);

pcb.EndText();

UniPaas エラーイメージ

UniPaasのエラープロパティにイメージが追加されている

追加されたUniPaasバージョン 1.5

UniPaasエラーログ出力

エラーログ出力の機能

エラーのプロパティー部分にエラーログ出力の属性が追加

追加されたUniPaasバージョン 1.5

2011年1月26日水曜日

iTextSharpでテンプレートを使用する方法

iTextSharpでテンプレートを使用する方法
CodeZineや@ITにも方法が載っていたが、バージョンが古いせいか
コピペで動作しなかった。

iTextSharp 5.0.5で動作確認

using iTextSharp.text;
using iTextSharp.text.pdf;

// step 1: creation of a document-object
Document doc = new Document();

// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
String vTempFile = iPDFFileName + "_.pdf";
PdfReader pr = new PdfReader(iPDFFileName);
PdfWriter pw = PdfWriter.GetInstance(doc, new FileStream(vTempFile, FileMode.Create));

// step 3: we open the document
doc.Open();

// template.pdfを現在のPDF文書に対して適用
PdfImportedPage page = pw.GetImportedPage(pr, 1);
PdfContentByte pcb = pw.DirectContent; //旧だとGetDirectContent;
pcb.AddTemplate(page, 0, 0);

// step 4: we add content
//iTextSharp.text.Image bmp = iTextSharp.text.Image.GetInstance(iBarCodeFileName);
Image bmp = Image.GetInstance(iBarCodeFileName);
bmp.SetAbsolutePosition(50, 630);

pcb.AddImage(bmp);

//doc.Add(bmp);

// step 5: we close the document
doc.Close();

C# コマンドラインからパラメータを取得する

C# コマンドラインからパラメータを取得する

Mainメソッドのパラメータで取得する方法
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("コマンドライン引数はありません。");
}
else
{
foreach (string arg in args)
Console.WriteLine(arg);
}
}

.NETでPDF帳票を出力する

iTextSharpは、iTextというJavaのライブラリをC#に移植したものです。.NETで動作するiTextには、iTextSharp以外にも、iText.NETという移植版が存在します。
開発者が日本人(氏原さん)のため多国語処理に強く
日本語の情報が充実しているメリットがあります。

ソースは、SourceForgeより

CodeZineの記事
http://codezine.jp/article/detail/462

delphiでプリンター属性を変更する




delphiでプリンター属性を変更する 
以下がソース
ただし、Windows95までは権限が無かったのでOKだったが
NTからはプリンター属性を変更するのに権限が必要
Wins32のDevModeを使用しています

function SetPaper(PaperName: String): boolean;
var
 DrvName, PrtName, PortName: array[0..512] of char;
 h: THandle;
 pDevMode: PDEVICEMODE;
 PaperCount, i: Integer;
 Papers: array[0..255] of array[0..63] of Char;
 PaperNo: array[0..255] of Word;
begin
 Result := False;
 Printer.GetPrinter(DrvName, PrtName, PortName, h);
 Printer.SetPrinter(DrvName, PrtName, PortName, 0);
 Printer.GetPrinter(DrvName, PrtName, PortName, h);
 pDevMode := GlobalLock(h);
 try
   // 用紙サイズ配列数を取得
   PaperCount := DeviceCapabilities(DrvName, PortName, DC_PAPERS,
    nil, pDevMode);
   // 用紙サイズ番号をPaperNoに保存
   DeviceCapabilities(DrvName, PortName, DC_PAPERS, @PaperNo, nil);
   // 用紙サイズ名ををPapersに格納
   DeviceCapabilities(DrvName, PortName, DC_PAPERNAMES, @Papers, nil);
   // 指定した用紙名で用紙サイズ番号を検索
   for i := 0 to PaperCount -1 do
   begin
     if PaperName=Papers[i] then
     begin
       // 検索された用紙サイズのdmPaperSizeを設定
       pDevMode^.dmPaperSize := PaperNo[i];
       Result := True;
       Break;
     end;
   end;
 finally
   GlobalUnlock(h);
 end;
end;

Delphiでファイルのタイムスタンプを変更する

Delphiでファイルのタイムスタンプを変更する

引数 FileName … タイムスタンプを変更したいファイルの名前です。
DateTime … タイムスタンプです。TDateTime 型で指定して下さい。
戻り値 タイムスタンプの変更が成功すれば True、失敗すれば(ファイルが存在しない場合など) False を返します。
 
uses SysUtils;
function FileSetDate2(FileName: string; DateTime: TDateTime): Boolean;
var hFile: Integer;
begin
  hFile := FileOpen(FileName, fmOpenWrite);
  Result := hFile > 0;
  if Result then begin
     Result := FileSetDate(hFile, DateTimeToFileDate(DateTime)) = 0;
     FileClose(hFile);
   end;
end;

C#からVB.NET

C#からVB.NET

C#から、VB.NETにソース変換
逆の VB.NETからC#もこのurl上で出来る
 

Windows DCを降格出来ない

DCを降格出来ない

DCPROMOコマンドでコメインコントローラーを降格出来ない場合
 
DCPROMO /forceremoval   オプションを追加すると、強制的に降格出来る。
 
その後、ADでそのサーバの残骸が削除する
  残骸とは、管理サーバの一覧から削除
  ドメイン参加になっている一覧から削除
 

Oracle DBConsole構築方法

DBConsole構築方法

コマンドプロンプトから
emca -deconfig dbcontrol db
emca -config dbcontrol db

GhostScriptLiteを.Netから使用する

GhostScriptを.Netから使用する。

http://www.codeproject.com/KB/cs/GhostScriptUseWithCSharp.aspx

.NetのPDFライブラリー

.NetでのPDFライブラリー

http://pdfsharp.codeplex.com/

ライセンスはMIT

UniPaasのファイル名一覧取得

UniPaasのファイル名の一覧を取得する方法

FileListGet関数を使用する

対象Ver:UniPaas 1.5