Bu unit program TIF dosya işleminde kullanılır.
Kod: Tümünü seç
unit ads_TifUtils;
interface
uses
ILDocImg,Classes,Windows,SysUtils,Forms,dll96v1,Clipbrd,FileCtrl,Graphics,
ExtCtrls,StdCtrls,Buttons,Controls,Dialogs;
{
This unit contains many utilities for manipulating Tif files. This unit
can only be used in conjunction with the Skyline Tools product ImageLib
}
(*The following procedures can be used to create command line utilities
to manipulate *.tif files.
Example:
program TifToTGA;
uses
ads_TifUtils in 'ads_TifUtils.pas';
{$R *.RES}
Begin
TifToTGAAp;
End.
*)
Function TifBindPages(
SourceFiles : TStringList;
DestFile : String): Boolean;
Procedure TifAppendPageAp;
Procedure TifDeletePageAp;
Procedure TifDocBinderAp;
Procedure TifFlipAllPagesAp;
Procedure TifFlipPageAp;
Procedure TifInsertPageAp;
Procedure TifReplacePageAp;
Procedure TifRotateAllPagesAp;
Procedure TifRotateAllPagesLeftAp;
Procedure TifRotateAllPagesRightAp;
Procedure TifRotatePageAp;
Procedure TifRotatePageLeftAp;
Procedure TifRotatePageRightAp;
Procedure TifSwapPagesAp;
Procedure TifSwapPagesInFilesAp;
Procedure TifToBMPAP;
Procedure TifToEPSAp;
Procedure TifToGIFAp;
Procedure TifToGraphicAp;
Procedure TifToJPGAp;
Procedure TifToPCXAp;
Procedure TifToPNGAp;
Procedure TifToTGAAp;
{!~ TifToBMP
This utility converts a *.tif page into a *.BMP graphic format.
The TifPage located in the TifFile is converted to the new
graphic format. The results are output to NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifToBMP(
'Source/00003307.tif',//TifFile : String;
0, //TifPage : Integer;
'New/00000001.BMP' //NewFile : String
); //): Boolean
end;
}
Function TifToBMP(
TifFile : String;
TifPage : Integer;
NewFile : String
): Boolean;
{!~ TifToEPS
This utility converts a *.tif page into a *.EPS graphic format.
The TifPage located in the TifFile is converted to the new
graphic format. The results are output to NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifToEPS(
'Source/00003307.tif',//TifFile : String;
0, //TifPage : Integer;
'New/00000001.EPS' //NewFile : String
); //): Boolean
end;
}
Function TifToEPS(
TifFile : String;
TifPage : Integer;
NewFile : String
): Boolean;
{!~ TifToGIF
This utility converts a *.tif page into a *.GIF graphic format.
The TifPage located in the TifFile is converted to the new
graphic format. The results are output to NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifToGIF(
'Source/00003307.tif',//TifFile : String;
0, //TifPage : Integer;
'New/00000001.GIF' //NewFile : String
); //): Boolean
end;
}
Function TifToGIF(
TifFile : String;
TifPage : Integer;
NewFile : String
): Boolean;
{!~ TifToGraphic
This utility converts a *.tif page into another graphic format.
The graphic formats supported are: BMP, EPS, GIF, JPG, PCX,
PNG, and TGA. The TifPage located in the TifFile is converted
to the graphic format passed as Format. The results are output
to NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifToGraphic(
'BMP', //Format : String;
'Source/00003307.tif',//TifFile : String;
0, //TifPage : Integer;
'New/00000001.BMP' //NewFile : String
); //): Boolean
end;
}
Function TifToGraphic(
Format : String;
TifFile : String;
TifPage : Integer;
NewFile : String
): Boolean;
{!~ TifToJPG
This utility converts a *.tif page into a *.JPG graphic format.
The TifPage located in the TifFile is converted to the new
graphic format. The results are output to NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifToJPG(
'Source/00003307.tif',//TifFile : String;
0, //TifPage : Integer;
'New/00000001.JPG' //NewFile : String
); //): Boolean
end;
}
Function TifToJPG(
TifFile : String;
TifPage : Integer;
NewFile : String
): Boolean;
{!~ TifToPCX
This utility converts a *.tif page into a *.PCX graphic format.
The TifPage located in the TifFile is converted to the new
graphic format. The results are output to NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifToPCX(
'Source/00003307.tif',//TifFile : String;
0, //TifPage : Integer;
'New/00000001.PCX' //NewFile : String
); //): Boolean
end;
}
Function TifToPCX(
TifFile : String;
TifPage : Integer;
NewFile : String
): Boolean;
{!~ TifToPNG
This utility converts a *.tif page into a *.PNG graphic format.
The TifPage located in the TifFile is converted to the new
graphic format. The results are output to NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifToPNG(
'Source/00003307.tif',//TifFile : String;
0, //TifPage : Integer;
'New/00000001.PNG' //NewFile : String
); //): Boolean
end;
}
Function TifToPNG(
TifFile : String;
TifPage : Integer;
NewFile : String
): Boolean;
{!~ TifToTGA
This utility converts a *.tif page into a *.TGA graphic format.
The TifPage located in the TifFile is converted to the new
graphic format. The results are output to NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifToTGA(
'Source/00003307.tif',//TifFile : String;
0, //TifPage : Integer;
'New/00000001.TGA' //NewFile : String
); //): Boolean
end;
}
Function TifToTGA(
TifFile : String;
TifPage : Integer;
NewFile : String
): Boolean;
{!~ TifAppendPage
The page identified by SourcePageNum in the SourceFile is appended to the end
of the pages in the DestFile. If a NewFile is provided then the DestFile is
unchanged and the results of the Append are output to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifAppendPage(
'Source/00003307.tif',//SourceFile : String;
'Dest/00003331.tif', //DestFile : String;
0, //SourcePageNum : Integer;
'New/00000001.tif' //NewFile : String): Boolean;
);
end;
}
Function TifAppendPage(
SourceFile : String;
DestFile : String;
SourcePageNum : Integer;
NewFile : String): Boolean;
{!~ TifDeletePage
The page identified by SourcePageNum in the SourceFile is Deleted.
If a NewFile is provided then the SourceFile is unchanged and the
results of the Deletion are output to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifDeletePage(
'Source/00003307.tif',//SourceFile : String;
0, //SourcePageNum : Integer;
'New/00000001.tif'); //NewFile : String): Boolean;
end;
}
Function TifDeletePage(
SourceFile : String;
SourcePageNum : Integer;
NewFile : String
): Boolean;
{!~ TifFlipAllPages
All pages in the SourceFile arerotated 180 degrees. If a
NewFile is provided then the SourceFile is unchanged and
the results of the Rotation are output to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifFlipAllPages(
'Source/00003307.tif',//SourceFile : String;
'New/00000001.tif' //NewFile : String;
); // ): Boolean;
end;
}
Function TifFlipAllPages(
SourceFile : String;
NewFile : String
): Boolean;
{!~ TifFlipPage
The page identified by SourcePageNum in the SourceFile is
rotated 180 degrees. If a NewFile is provided then the
SourceFile is unchanged and the results of the Rotation
are output to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifFlipPage(
'Source/00003307.tif',//SourceFile : String;
1, //SourcePageNum : Integer;
'New/00000001.tif' //NewFile : String;
); // ): Boolean;
end;
}
Function TifFlipPage(
SourceFile : String;
SourcePageNum : Integer;
NewFile : String
): Boolean;
{!~ TifInsertPage
The page identified by SourcePageNum in the SourceFile is inserted
into the DestFile at the DestPageNum location. If a NewFile is provided
then the DestFile is unchanged and the results of the Insert are output
to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifInsertPage(
'Source/00003307.tif',//SourceFile : String;
'Dest/00003331.tif', //DestFile : String;
0, //SourcePageNum : Integer;
1, //DestPageNum : Integer;
'New/00000001.tif' //NewFile : String): Boolean;
);
end;
}
Function TifInsertPage(
SourceFile : String;
DestFile : String;
SourcePageNum : Integer;
DestPageNum : Integer;
NewFile : String): Boolean;
{!~ TifReplacePage
The page identified by SourcePageNum in the SourceFile replaces the page
in the DestFile at the DestPageNum location. If a NewFile is provided
then the DestFile is unchanged and the results of the Replacement are output
to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifReplacePage(
'Source/00003307.tif',//SourceFile : String;
'Dest/00003331.tif', //DestFile : String;
0, //SourcePageNum : Integer;
1, //DestPageNum : Integer
'New/00000001.tif' //NewFile : String;
); //): Boolean;
end;
}
Function TifReplacePage(
SourceFile : String;
DestFile : String;
SourcePageNum : Integer;
DestPageNum : Integer;
NewFile : String
): Boolean;
{!~ TifRotateAllPagesLeft
All pages in the SourceFile are rotated Left 90 degrees.
If a NewFile is provided then the SourceFile is unchanged
and the results of the Rotation are output to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifRotateAllPagesLeft(
'Source/00003307.tif',//SourceFile : String;
'New/00000001.tif' //NewFile : String;
); // ): Boolean;
end;
}
Function TifRotateAllPagesLeft(
SourceFile : String;
NewFile : String
): Boolean;
{!~ TifRotateAllPagesRight
All pages in the SourceFile are rotated Right 90 degrees.
If a NewFile is provided then the SourceFile is unchanged
and the results of the Rotation are output to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifRotateAllPagesRight(
'Source/00003307.tif',//SourceFile : String;
'New/00000001.tif' //NewFile : String;
); // ): Boolean;
end;
}
Function TifRotateAllPagesRight(
SourceFile : String;
NewFile : String
): Boolean;
{!~ TifRotatePage
The page identified by SourcePageNum in the SourceFile is rotated
Angle degrees CounterClockwise. If a NewFile is provided then the
SourceFile is unchanged and the results of the Rotation are output
to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifRotatePage(
'Source/00003307.tif',//SourceFile : String;
1, //SourcePageNum : Integer;
90, //Angle : Double;
'New/00000001.tif' //NewFile : String;
); // ): Boolean;
end;
}
Function TifRotatePage(
SourceFile : String;
SourcePageNum : Integer;
Angle : Double;
NewFile : String
): Boolean;
{!~ TifRotateAllPages
All pages in the SourceFile are rotated Angle degrees
CounterClockwise. If a NewFile is provided then the
SourceFile is unchanged and the results of the
Rotation are output to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifRotateAllPages(
'Source/00003307.tif',//SourceFile : String;
90, //Angle : Double;
'New/00000001.tif' //NewFile : String;
); // ): Boolean;
end;
}
Function TifRotateAllPages(
SourceFile : String;
Angle : Double;
NewFile : String
): Boolean;
{!~ TifRotatePageLeft
The page identified by SourcePageNum in the SourceFile is
rotated 90 degrees CounterClockwise. If a NewFile is
provided then the SourceFile is unchanged and the results
of the Rotation are output to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifRotatePageLeft(
'Source/00003307.tif',//SourceFile : String;
1, //SourcePageNum : Integer;
'New/00000001.tif' //NewFile : String;
); // ): Boolean;
end;
}
Function TifRotatePageLeft(
SourceFile : String;
SourcePageNum : Integer;
NewFile : String
): Boolean;
{!~ TifRotatePageRight
The page identified by SourcePageNum in the SourceFile is
rotated 90 degrees Clockwise. If a NewFile is provided
then the SourceFile is unchanged and the results of the
Rotation are output to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifRotatePageRight(
'Source/00003307.tif',//SourceFile : String;
1, //SourcePageNum : Integer;
'New/00000001.tif' //NewFile : String;
); // ): Boolean;
end;
}
Function TifRotatePageRight(
SourceFile : String;
SourcePageNum : Integer;
NewFile : String
): Boolean;
{!~ TifSwapPages
The Page1 and Page2 are swapped in the SourceFile. If a NewFile is provided
then the SourceFile is unchanged and the results of the Swap are output
to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifSwapPages(
'Source/00003307.tif',//SourceFile : String;
8, //Page1 : Integer;
9, //Page2 : Integer;
'New/00000001.tif' //NewFile : String;
);
end;
}
Function TifSwapPages(
SourceFile : String;
Page1 : Integer;
Page2 : Integer;
NewFile : String
): Boolean;
{!~ TifSwapPagesInFiles
The SourcePageNum from the SourceFile is swapped
with the DestPageNum from the DestFile.
If NewSourceFile is not empty then the SourceFile
is unchanged and the results of the swap for the
SourceFile are output to the NewSourceFile.
If NewDestFile is not empty then the DestFile
is unchanged and the results of the swap for the
DestFile are output to the NewDestFile.
There are no optional parameters. On the command
line empty values need to be provided with "".
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifSwapPagesInFiles(
'Source/00003307.tif',//SourceFile : String;
'Dest/00003308.tif', //DestFile : String;
8, //SourcePageNum : Integer;
9, //DestPageNum : Integer;
'New/00000001.tif', //NewSourceFile : String;
'New/00000002.tif' //NewDestFile : String;
);
end;
}
Function TifSwapPagesInFiles(
SourceFile : String;
DestFile : String;
SourcePageNum : Integer;
DestPageNum : Integer;
NewSourceFile : String;
NewDestFile : String
): Boolean;
implementation
Procedure Msg(sg : String);
Var
Form : TForm;
pnlTop : TPanel;
Memo : TMemo;
pnlButton : TPanel;
Button : TBitBtn;
Label1 : TLabel;
MmoWidth : Integer;
sgApName : String;
Begin
Form := TForm.Create(nil);
pnlTop := TPanel.Create(Form);
Memo := TMemo.Create(Form);
pnlButton := TPanel.Create(Form);
Button := TBitBtn.Create(Form);
Label1 := TLabel.Create(Form);
Try
sgApName := ExtractFileName(ParamStr(0));
sgApName := Copy(sgApName,1,Length(sgApName)-4);
With Form Do
Begin
Caption := sgApName;
Position := poScreenCenter;
Font.Name := 'Courier';
Width := 800;
End;
With pnlTop Do
Begin
Parent := Form;
BevelInner := bvNone;
BevelInner := bvNone;
BorderWidth := 10;
Caption := ' ';
Height := 40;
Align := alTop;
End;
With Memo Do
Begin
Parent := pnlTop;
BorderStyle := bsNone;
Align := alClient;
ReadOnly := True;
Lines.Clear;
Lines.SetText(PChar(sg));
End;
With pnlButton Do
Begin
Parent := Form;
BevelInner := bvNone;
BevelInner := bvNone;
BorderWidth := 0;
Caption := ' ';
Height := 40;
Align := alBottom;
End;
With Label1 Do
Begin
Parent := pnlButton;
Left := 0;
Top := 0;
Caption := Memo.Lines[0];
AutoSize := True;
MmoWidth := Label1.Width;
End;
With Button Do
Begin
Parent := pnlButton;
Kind := bkOK;
ModalResult := mrOK;
End;
Form.Height := (Memo.Lines.Count * 13) + 20 + 40 + 30;
pnlTop.Align := alClient;
Form.width := 20 + mmoWidth + 10;
Button.Left := (pnlButton.Width - Button.Width) div 2;
Button.Top := (pnlButton.Height - Button.Height) div 2;
Label1.Visible := False;
Form.ShowModal;
Finally
Form .Free;
End;
End;
Function PrintInstructionsTop: String;
Begin
Result :=' ___________________________________________________________________ ' + #13 ;
End;
Function PrintInstructionsBottom: String;
Begin
Result :=
'* *' + #13 +
'* Developed by: *' + #13 +
'* Richard Maley *' + #13 +
'* Advanced Delphi Systems *' + #13 +
'* www.advdelphisys.com *' + #13 +
'* *' + #13 +
'* Required Skyline Tools DLLs: *' + #13 +
'* ILAnot32.DLL *' + #13 +
'* I3Tif32.DLL *' + #13 +
'*___________________________________________________________________*' + #13 ;
End;
Function PrintSyntax(Syntax : String): String;
Var
inLenSyntax : Integer;
inLenLine : Integer;
sgSyntaxLine : String;
sgEmptyLine : String;
Begin
sgEmptyLine := '* *';
inLenLine := Length(sgEmptyLine);
sgSyntaxLine := '* '+Syntax;
inLenSyntax := Length(sgSyntaxLine);
sgSyntaxLine := sgSyntaxLine+Copy(sgEmptyLine,inLenSyntax+1,inLenLine);
Result :=
'* *' + #13 +
'* Syntax: *' + #13 +
sgSyntaxLine + #13 +
'* *' + #13 +
'* Description: *' + #13 ;
End;
Function PrintDescription(Desc : String): String;
Var
inLenDesc : Integer;
inLenLine : Integer;
sgDescLine : String;
sgEmptyLine : String;
Begin
sgEmptyLine := '* *';
inLenLine := Length(sgEmptyLine);
sgDescLine := '* '+Desc;
inLenDesc := Length(sgDescLine);
sgDescLine := sgDescLine+Copy(sgEmptyLine,inLenDesc+1,inLenLine);
Result := sgDescLine + #13;
End;
Function PrintTitle: String;
Var
inLenDesc : Integer;
inLenLine : Integer;
sgDescLine : String;
sgEmptyLine : String;
Desc : String;
Begin
Desc := ExtractFileName(ParamStr(0));
Desc := Copy(Desc,1,Length(Desc)-4);
sgEmptyLine := '* *';
inLenLine := Length(sgEmptyLine);
sgDescLine := '* '+Desc;
inLenDesc := Length(sgDescLine);
sgDescLine := sgDescLine+Copy(sgEmptyLine,inLenDesc+1,inLenLine);
Result := sgDescLine+#13;
End;
Procedure TifToBMPInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifToBMP TifFile TifPage NewFile')+
PrintDescription('This utility converts a *.tif page into a *.BMP graphic format.')+
PrintDescription('The TifPage located in the TifFile is converted to the new')+
PrintDescription('graphic format. The results are output to NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifToEPSInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifToEPS TifFile TifPage NewFile')+
PrintDescription('This utility converts a *.tif page into a *.EPS graphic format.')+
PrintDescription('The TifPage located in the TifFile is converted to the new')+
PrintDescription('graphic format. The results are output to NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifToGIFInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifToGIF TifFile TifPage NewFile')+
PrintDescription('This utility converts a *.tif page into a *.GIF graphic format.')+
PrintDescription('The TifPage located in the TifFile is converted to the new')+
PrintDescription('graphic format. The results are output to NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifToGraphicInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifToGraphic Format TifFile TifPage NewFile')+
PrintDescription('This utility converts a *.tif page into another graphic format.')+
PrintDescription('The graphic formats supported are: BMP, EPS, GIF, JPG, PCX,')+
PrintDescription('PNG, and TGA. The TifPage located in the TifFile is converted')+
PrintDescription('to the graphic format passed as Format. The results are output')+
PrintDescription('to NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifToJPGInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifToJPG TifFile TifPage NewFile')+
PrintDescription('This utility converts a *.tif page into a *.JPG graphic format.')+
PrintDescription('The TifPage located in the TifFile is converted to the new')+
PrintDescription('graphic format. The results are output to NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifToPCXInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifToPCX TifFile TifPage NewFile')+
PrintDescription('This utility converts a *.tif page into a *.PCX graphic format.')+
PrintDescription('The TifPage located in the TifFile is converted to the new')+
PrintDescription('graphic format. The results are output to NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifToPNGInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifToPNG TifFile TifPage NewFile')+
PrintDescription('This utility converts a *.tif page into a *.PNG graphic format.')+
PrintDescription('The TifPage located in the TifFile is converted to the new')+
PrintDescription('graphic format. The results are output to NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifToTGAInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifToTGA TifFile TifPage NewFile')+
PrintDescription('This utility converts a *.tif page into a *.TGA graphic format.')+
PrintDescription('The TifPage located in the TifFile is converted to the new')+
PrintDescription('graphic format. The results are output to NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifAppendPageInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifAppendPage SourceFile DestFile SourcePageNum [NewFile]')+
PrintDescription('The page identified by SourcePageNum in the SourceFile is appended')+
PrintDescription('to the end of the pages in the DestFile. If a NewFile is provided')+
PrintDescription('then the DestFile is unchanged and the results of the Append are')+
PrintDescription('output to the NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifDocBinderInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifDocBinder SourceFile')+
PrintDescription('This utility produces multipage tifs out of single page tifs.')+
PrintDescription('The SourceFile is a text file that is structured as follows:')+
PrintDescription(' FullPathToSinglePageTif,FullPathToNewMultiPageTif')+
PrintDescription('Each single page tif should be listed on a separate line.')+
PrintDescription('The order of the Tif''s in the list establishes the page number')+
PrintDescription('ordering. Each time a new "FullPathToNewMultiPageTif" is found')+
PrintDescription('in the list it is assumed to be page one of a new document. If')+
PrintDescription('"FullPathToNewMultiPageTif" file already exists it is deleted')+
PrintDescription('and replaced with the new document. If no errors occur the')+
PrintDescription('SourceFile is deleted. If errors occur then the SourceFile is')+
PrintDescription('replaced with a new file containing only the failed tifs. To')+
PrintDescription('detect completion of the process check for deletion of the')+
PrintDescription('SourceFile or a change in its DateTime stamp.')+
PrintInstructionsBottom
);
End;
Procedure TifDeletePageInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifDeletePage SourceFile SourcePageNum [NewFile]')+
PrintDescription('The page identified by SourcePageNum in the SourceFile is Deleted.')+
PrintDescription('If a NewFile is provided then the SourceFile is unchanged and the')+
PrintDescription('results of the Deletion are output to the NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifFlipAllPagesInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifFlipAllPages SourceFile [NewFile]')+
PrintDescription('All pages in the SourceFile arerotated 180 degrees. If a')+
PrintDescription('NewFile is provided then the SourceFile is unchanged and')+
PrintDescription('the results of the Rotation are output to the NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifFlipPageInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifFlipPage SourceFile SourcePageNum [NewFile]')+
PrintDescription('The page identified by SourcePageNum in the SourceFile is')+
PrintDescription('rotated 180 degrees. If a NewFile is provided then the')+
PrintDescription('SourceFile is unchanged and the results of the Rotation')+
PrintDescription('are output to the NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifInsertPageInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifInsertPage SourceFile DestFile SourcePageNum DestPageNum [NewFile]')+
PrintDescription('The page identified by SourcePageNum in the SourceFile is inserted')+
PrintDescription('into the DestFile at the DestPageNum location. If a NewFile is')+
PrintDescription('provided then the DestFile is unchanged and the results of the')+
PrintDescription('Insert are output to the NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifReplacePageInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifReplacePage SourceFile DestFile SourcePageNum DestPageNum [NewFile]')+
PrintDescription('The page identified by SourcePageNum in the SourceFile replaces')+
PrintDescription('the page in the DestFile at the DestPageNum location. If a')+
PrintDescription('NewFile is provided then the DestFile is unchanged and the results')+
PrintDescription('of the Replacement are output to the NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifRotateAllPagesLeftInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifRotateAllPagesLeft SourceFile [NewFile]')+
PrintDescription('All pages in the SourceFile are rotated Left 90 degrees.')+
PrintDescription('If a NewFile is provided then the SourceFile is unchanged')+
PrintDescription('and the results of the Rotation are output to the NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifRotateAllPagesRightInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifRotateAllPagesRight SourceFile [NewFile]')+
PrintDescription('All pages in the SourceFile are rotated Right 90 degrees.')+
PrintDescription('If a NewFile is provided then the SourceFile is unchanged')+
PrintDescription('and the results of the Rotation are output to the NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifRotatePageInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifRotatePage SourceFile SourcePageNum Angle [NewFile]')+
PrintDescription('The page identified by SourcePageNum in the SourceFile is rotated')+
PrintDescription('Angle degrees CounterClockwise. If a NewFile is provided then the')+
PrintDescription('SourceFile is unchanged and the results of the Rotation are output')+
PrintDescription('to the NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifRotateAllPagesInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifRotateAllPages SourceFile Angle [NewFile]')+
PrintDescription('All pages in the SourceFile are rotated Angle degrees')+
PrintDescription('CounterClockwise. If a NewFile is provided then the')+
PrintDescription('SourceFile is unchanged and the results of the')+
PrintDescription('Rotation are output to the NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifRotatePageLeftInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifRotatePageLeft SourceFile SourcePageNum [NewFile]')+
PrintDescription('The page identified by SourcePageNum in the SourceFile is')+
PrintDescription('rotated 90 degrees CounterClockwise. If a NewFile is')+
PrintDescription('provided then the SourceFile is unchanged and the results')+
PrintDescription('of the Rotation are output to the NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifRotatePageRightInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifRotatePageRight SourceFile SourcePageNum [NewFile]')+
PrintDescription('The page identified by SourcePageNum in the SourceFile is')+
PrintDescription('rotated 90 degrees Clockwise. If a NewFile is provided')+
PrintDescription('then the SourceFile is unchanged and the results of the')+
PrintDescription('Rotation are output to the NewFile.')+
PrintInstructionsBottom
);
End;
Procedure TifSwapPagesInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintSyntax('TifSwapPages SourceFile Page1 Page2 [NewFile]')+
PrintDescription('The Page1 and Page2 are swapped in the SourceFile. If a')+
PrintDescription('NewFile is provided then the SourceFile is unchanged and')+
PrintDescription('the results of the Swap are output to the NewFile.')+
PrintInstructionsBottom);
End;
Procedure TifSwapPagesInFilesInstr;
Begin
Msg(
PrintInstructionsTop+
PrintTitle+
PrintDescription('')+
PrintDescription('Syntax:')+
PrintDescription(' '+'TifSwapPagesInFiles SourceFile DestFile')+
PrintDescription(' '+'SourcePageNum DestPageNum NewSourceFile NewDestFile')+
PrintDescription('')+
PrintDescription('Description:')+
PrintDescription('The SourcePageNum from the SourceFile is swapped with the')+
PrintDescription('DestPageNum from the DestFile. If NewSourceFile is not empty then')+
PrintDescription('the SourceFile is unchanged and the results of the swap for the')+
PrintDescription('SourceFile are output to the NewSourceFile. If NewDestFile is not')+
PrintDescription('empty then the DestFile is unchanged and the results of the swap')+
PrintDescription('for the DestFile are output to the NewDestFile. There are no')+
PrintDescription('optional parameters. On the command line empty values need to be')+
PrintDescription('provided with "".')+
PrintDescription('* *')+
PrintDescription('* Developed by: Richard Maley, Advanced Delphi Systems *')+
PrintDescription('* www.advdelphisys.com *')+
PrintDescription('* Required DLLs: ILAnot32.DLL, I3Tif32.DLL *')+
PrintDescription('*___________________________________________________________________*')
);
End;
Function AddPageToStream(
TempStream : TMemoryStream;
IL : ILDocumentImage;
HDIB : Thandle;
Append : Boolean;
TifComp : TTiffCompression) : Boolean;
var
Resolution : SmallInt;
Usize : Longint;
p : Pointer;
ImageSize : LongInt;
lStream : TMemoryStream;
begin
Try
Resolution:=24;
ImageSize:=GlobalSize(HDib);
If Not Append Then
Begin
Usize:=LongInt(ImageSize)+ Round(LongInt(ImageSize) / 5);
P := GlobalAllocPtr(HeapAllocFlags, Usize);
If Not Assigned(P) Then raise ErrorInvalid.Create(iOutOfMemory);
TempStream.Clear;
End
Else
Begin
lStream:=TMemoryStream.Create;
TempStream.SaveToStream(lStream);
USize:=lStream.Size;
P := GlobalAllocPtr(HeapAllocFlags, Usize+(LongInt(ImageSize)+ Round(LongInt(ImageSize) / 5)));
if not Assigned(P) then raise ErrorInvalid.Create(iOutOfMemory);
lStream.Seek(0,0);
lStream.Read(P^,USize);
lStream.Free;
TempStream.Clear;
End;
PutTifBlobDib(
P,
USize,
GetTiffCompression(TifComp),
Append,
Resolution,
HDIB,
LongInt(IL),
nil);
TempStream.Write(P^,USize);
GlobalFreePtr(P);
Result := True;
Except
Result := False;
End;
end;
Function ClipBoardProcessor(
Action : String;
DestFile : String;
PageNum : Integer;
IL : ILDocumentImage): Boolean;
Var
hDIB : THandle;
ILDibClass : ILDocuDib;
TifComp : TTiffCompression;
Begin
Try
Result := False;
Action := Trim(UpperCase(Action));
If Clipboard.HasFormat(CF_DIB) Then
Begin
If Not OpenClipBoard(Application.Handle) Then Exit;
hDIB :=GetClipboardData(CF_DIB);
If hDIB <> 0 Then
Begin
ILDibClass :=ILDocuDib.Create;
Try
ILDibClass.DibBitmap:=PBitmapInfo(GlobalLock(IL.AssignDib(hDIB)));
CloseClipboard;
If ILDibClass.Bits < 2 Then
Begin
TifComp:=sFAXCCITT4;
End
Else
Begin
TifComp:=sPACKBITS;
End;
If Action = 'APPEND' Then
Begin
If PutTifFileDib(
DestFile,
GetTiffCompression(TifComp),
True,
ILDibClass.Bits,
GlobalHandle(ILDibClass.DibBitmap),
LongInt(IL),
nil
)
Then Result := True;
Exit;
End;
If Action = 'INSERT' Then
Begin
If InsertTifFileDib(
DestFile,
GetTiffCompression(TifComp),
PageNum,
ILDibClass.Bits,
GlobalHandle(ILDibClass.DibBitmap),
LongInt(IL),
nil)
Then Result := True;
Exit;
End;
If Action = 'REPLACE' Then
Begin
If UpdateTifFileDib(
DestFile,
GetTiffCompression(TifComp),
PageNum,
ILDibClass.Bits,
GlobalHandle(ILDibClass.DibBitmap),
LongInt(IL),
nil)
Then Result := True;
Exit;
End;
Finally
ILDibClass.Free;
End;
End;
End;
Except
Result := False;
End;
End;
{!~ TifAppendPage
The page identified by SourcePageNum in the SourceFile is appended to the end
of the pages in the DestFile. If a NewFile is provided then the DestFile is
unchanged and the results of the Append are output to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifAppendPage(
'Source/00003307.tif',//SourceFile : String;
'Dest/00003331.tif', //DestFile : String;
0, //SourcePageNum : Integer;
'New/00000001.tif' //NewFile : String): Boolean;
);
end;
}
Function TifAppendPage(
SourceFile : String;
DestFile : String;
SourcePageNum : Integer;
NewFile : String): Boolean;
Var
IL : ILDocumentImage;
incounter : Integer;
inPageCount : Integer;
inPageNum : Integer;
NewDir : String;
TempStream : TMemoryStream;
Begin
TempStream :=TMemoryStream.Create;
IL := ILDocumentImage.Create(nil);
Try
Try
Result := False;
IL.TifSaveCompress := sFAXCCITT4;
If Not FileExists(SourceFile) Then Exit;
If Not FileExists(DestFile) Then Exit;
//Validate SourcePageNum
IL.ReadTifFile(SourceFile,0,24);
inPageCount := IL.TiffPageCount;
If SourcePageNum < 0 Then Exit;
If SourcePageNum > inPageCount-1 Then Exit;
//Determine size of DestFile
IL.ReadTifFile(DestFile,0,24);
inPageCount := IL.TiffPageCount;
inPageNum := 0;
For inCounter := 0 To inPageCount-1 Do
Begin
If inPageNum = 0 Then
Begin
IL.ReadTifFile(DestFile,inCounter,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
False, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End
Else
Begin
IL.ReadTifFile(DestFile,inCounter,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
True, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End;
inPageNum := inPageNum + 1;
End;
IL.ReadTifFile(SourceFile,SourcePageNum,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
False, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
If Trim(NewFile) <> '' Then
Begin
NewDir := ExtractFilePath(NewFile);
If NewDir <> '' Then
Begin
If Not DirectoryExists(NewDir) Then ForceDirectories(NewDir);
End;
If FileExists(NewFile) Then DeleteFile(NewFile);
TempStream.SaveToFile(NewFile);
End
Else
Begin
If FileExists(DestFile) Then DeleteFile(DestFile);
TempStream.SaveToFile(DestFile);
End;
Result := True;
Except
Result := False;
End;
Finally
IL .Free;
TempStream .Free;
End;
End;
{!~ TifInsertPage
The page identified by SourcePageNum in the SourceFile is inserted
into the DestFile at the DestPageNum location. If a NewFile is provided
then the DestFile is unchanged and the results of the Insert are output
to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifAppendPage(
'Source/00003307.tif',//SourceFile : String;
'Dest/00003331.tif', //DestFile : String;
'New/00000001.tif', //NewFile : String;
0, //SourcePageNum : Integer;
1 //DestPageNum : Integer): Boolean;
);
end;
}
Function TifInsertPage(
SourceFile : String;
DestFile : String;
SourcePageNum : Integer;
DestPageNum : Integer;
NewFile : String): Boolean;
Var
IL : ILDocumentImage;
incounter : Integer;
inPageCount : Integer;
inPageNum : Integer;
NewDir : String;
TempStream : TMemoryStream;
Begin
TempStream :=TMemoryStream.Create;
IL := ILDocumentImage.Create(nil);
Try
Try
Result := False;
TempStream.Clear;
IL.TifSaveCompress := sFAXCCITT4;
If Not FileExists(SourceFile) Then Exit;
If Not FileExists(DestFile) Then Exit;
//Validate SourcePageNum
IL.ReadTifFile(SourceFile,0,24);
inPageCount := IL.TiffPageCount;
If SourcePageNum < 0 Then Exit;
If SourcePageNum > inPageCount-1 Then Exit;
//Validate DestPageNum
IL.ReadTifFile(DestFile,0,24);
inPageCount := IL.TiffPageCount;
If DestPageNum < 0 Then DestPageNum := 0;
If DestPageNum > inPageCount-1 Then DestPageNum := inPageCount;
inPageNum := 0;
For inCounter := 0 To inPageCount - 1 Do
Begin
If DestPageNum = inCounter Then
Begin
If inPageNum = 0 Then
Begin
IL.ReadTifFile(SourceFile,SourcePageNum,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
False, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End
Else
Begin
IL.ReadTifFile(SourceFile,SourcePageNum,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
True, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End;
inPageNum := inPageNum + 1;
End;
If inPageNum = 0 Then
Begin
IL.ReadTifFile(DestFile,inCounter,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
False, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End
Else
Begin
IL.ReadTifFile(DestFile,inCounter,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
True, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End;
inPageNum := inPageNum + 1;
End;
If DestPageNum >= inPageCount Then
Begin
IL.ReadTifFile(SourceFile,SourcePageNum,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
True, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End;
If Trim(NewFile) <> '' Then
Begin
NewDir := ExtractFilePath(NewFile);
If NewDir <> '' Then
Begin
If Not DirectoryExists(NewDir) Then ForceDirectories(NewDir);
End;
If FileExists(NewFile) Then DeleteFile(NewFile);
TempStream.SaveToFile(NewFile);
End
Else
Begin
If FileExists(DestFile) Then DeleteFile(DestFile);
TempStream.SaveToFile(DestFile);
End;
Result := True;
Except
Result := False;
End;
Finally
IL .Free;
TempStream .Free;
End;
End;
{!~ TifReplacePage
The page identified by SourcePageNum in the SourceFile replaces the page
in the DestFile at the DestPageNum location. If a NewFile is provided
then the DestFile is unchanged and the results of the Replacement are output
to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifReplacePage(
'Source/00003307.tif',//SourceFile : String;
'Dest/00003331.tif', //DestFile : String;
0, //SourcePageNum : Integer;
1, //DestPageNum : Integer
'New/00000001.tif' //NewFile : String;
); //): Boolean;
end;
}
Function TifReplacePage(
SourceFile : String;
DestFile : String;
SourcePageNum : Integer;
DestPageNum : Integer;
NewFile : String): Boolean;
Var
IL : ILDocumentImage;
incounter : Integer;
inPageCount : Integer;
inPageNum : Integer;
NewDir : String;
TempStream : TMemoryStream;
Begin
TempStream :=TMemoryStream.Create;
IL := ILDocumentImage.Create(nil);
Try
Try
Result := False;
TempStream.Clear;
IL.TifSaveCompress := sFAXCCITT4;
If Not FileExists(SourceFile) Then Exit;
If Not FileExists(DestFile) Then Exit;
//Validate SourcePageNum
IL.ReadTifFile(SourceFile,0,24);
inPageCount := IL.TiffPageCount;
If SourcePageNum < 0 Then Exit;
If SourcePageNum > inPageCount-1 Then Exit;
//Validate DestPageNum
IL.ReadTifFile(DestFile,0,24);
inPageCount := IL.TiffPageCount;
If DestPageNum < 0 Then Exit;
If DestPageNum > inPageCount-1 Then Exit;
inPageNum := 0;
For inCounter := 0 To inPageCount - 1 Do
Begin
If DestPageNum = inCounter Then
Begin
If inPageNum = 0 Then
Begin
IL.ReadTifFile(SourceFile,SourcePageNum,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
False, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End
Else
Begin
IL.ReadTifFile(SourceFile,SourcePageNum,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
True, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End;
inPageNum := inPageNum + 1;
Continue;
End;
If inPageNum = 0 Then
Begin
IL.ReadTifFile(DestFile,inCounter,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
False, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End
Else
Begin
IL.ReadTifFile(DestFile,inCounter,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
True, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End;
inPageNum := inPageNum + 1;
End;
If Trim(NewFile) <> '' Then
Begin
NewDir := ExtractFilePath(NewFile);
If NewDir <> '' Then
Begin
If Not DirectoryExists(NewDir) Then ForceDirectories(NewDir);
End;
If FileExists(NewFile) Then DeleteFile(NewFile);
TempStream.SaveToFile(NewFile);
End
Else
Begin
If FileExists(DestFile) Then DeleteFile(DestFile);
TempStream.SaveToFile(DestFile);
End;
Result := True;
Except
Result := False;
End;
Finally
IL .Free;
TempStream .Free;
End;
End;
{!~ TifDeletePage
The page identified by SourcePageNum in the SourceFile is Deleted.
If a NewFile is provided then the SourceFile is unchanged and the
results of the Deletion are output to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifDeletePage(
'Source/00003307.tif',//SourceFile : String;
0, //SourcePageNum : Integer;
'New/00000001.tif'); //NewFile : String): Boolean;
end;
}
Function TifDeletePage(
SourceFile : String;
SourcePageNum : Integer;
NewFile : String
): Boolean;
Var
NewDir : String;
inPageCount : Integer;
IL : ILDocumentImage;
inCounter : Integer;
inPageNum : Integer;
TempStream : TMemoryStream;
Begin
TempStream :=TMemoryStream.Create;
IL := ILDocumentImage.Create(nil);
Try
Try
Result := False;
IL.TifSaveCompress := sFAXCCITT4;
If Not FileExists(SourceFile) Then Exit;
IL.ReadTifFile(SourceFile,SourcePageNum,24);
inPageCount := IL.TiffPageCount;
If SourcePageNum < 0 Then Exit;
If SourcePageNum > inPageCount-1 Then Exit;
inPageNum := 0;
For inCounter := 0 To inPageCount-1 Do
Begin
If inCounter = SourcePageNum Then Continue;
If inPageNum > 0 Then
Begin
IL.ReadTifFile(SourceFile,inCounter,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
il.GetOurDib, //HDIB : Thandle;
True, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End
Else
Begin
IL.ReadTifFile(SourceFile,inCounter,24);
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
il.GetOurDib, //HDIB : Thandle;
False, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End;
inPageNum := inPageNum + 1;
End;
If Trim(NewFile) <> '' Then
Begin
NewDir := ExtractFilePath(NewFile);
If NewDir <> '' Then
Begin
If Not DirectoryExists(NewDir) Then ForceDirectories(NewDir);
End;
If FileExists(NewFile) Then DeleteFile(NewFile);
TempStream.SaveToFile(NewFile);
End
Else
Begin
If FileExists(SourceFile) Then DeleteFile(SourceFile);
TempStream.SaveToFile(SourceFile);
End;
Result := True;
Except
Result := False;
End;
Finally
IL.Free;
TempStream.Free;
End;
End;
{!~ TifSwapPages
The Page1 and Page2 are swapped in the SourceFile. If a NewFile is provided
then the SourceFile is unchanged and the results of the Swap are output
to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifSwapPages(
'Source/00003307.tif',//SourceFile : String;
8, //Page1 : Integer;
9, //Page2 : Integer;
'New/00000001.tif' //NewFile : String;
);
end;
}
Function TifSwapPages(
SourceFile : String;
Page1 : Integer;
Page2 : Integer;
NewFile : String
): Boolean;
Var
DestFile : String;
SourcePageNum : Integer;
DestPageNum : Integer;
NewSourceFile : String;
NewDestFile : String;
Begin
DestFile := SourceFile;
SourcePageNum := Page1;
DestPageNum := Page2;
NewSourceFile := NewFile;
NewDestFile := NewFile;
Result :=
TifSwapPagesInFiles(
SourceFile, //SourceFile : String;
DestFile, //DestFile : String;
SourcePageNum, //SourcePageNum : Integer;
DestPageNum, //DestPageNum : Integer;
NewSourceFile, //NewSourceFile : String;
NewDestFile //NewDestFile : String
); //): Boolean;
End;
{!~ TifRotatePage
The page identified by SourcePageNum in the SourceFile is rotated
Angle degrees CounterClockwise. If a NewFile is provided then the
SourceFile is unchanged and the results of the Rotation are output
to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifRotatePage(
'Source/00003307.tif',//SourceFile : String;
1, //SourcePageNum : Integer;
90, //Angle : Double;
'New/00000001.tif' //NewFile : String;
); // ): Boolean;
end;
}
Function TifRotatePage(
SourceFile : String;
SourcePageNum : Integer;
Angle : Double;
NewFile : String
): Boolean;
Var
IL : ILDocumentImage;
incounter : Integer;
inPageCount : Integer;
inPageNum : Integer;
NewDir : String;
TempStream : TMemoryStream;
Begin
TempStream :=TMemoryStream.Create;
IL := ILDocumentImage.Create(nil);
Try
Try
Result := False;
TempStream.Clear;
IL.TifSaveCompress := sFAXCCITT4;
If Not FileExists(SourceFile) Then Exit;
//Validate SourcePageNum
IL.ReadTifFile(SourceFile,0,24);
inPageCount := IL.TiffPageCount;
If SourcePageNum < 0 Then Exit;
If SourcePageNum > inPageCount-1 Then Exit;
inPageNum := 0;
For inCounter := 0 To inPageCount - 1 Do
Begin
IL.ReadTifFile(SourceFile,inCounter,24);
If SourcePageNum = inCounter Then IL.Rotate(Angle,clWhite);
If inPageNum = 0 Then
Begin
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
False, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End
Else
Begin
AddPageToStream(
TempStream, //TempStream : TMemoryStream;
IL, //IL : ILDocumentImage;
IL.GetOurDib, //HDIB : Thandle;
True, //Append : Boolean;
IL.TifSaveCompress); //TifComp : TTiffCompression) : Boolean;
End;
inPageNum := inPageNum + 1;
End;
If Trim(NewFile) <> '' Then
Begin
NewDir := ExtractFilePath(NewFile);
If NewDir <> '' Then
Begin
If Not DirectoryExists(NewDir) Then ForceDirectories(NewDir);
End;
If FileExists(NewFile) Then DeleteFile(NewFile);
TempStream.SaveToFile(NewFile);
End
Else
Begin
If FileExists(SourceFile) Then DeleteFile(SourceFile);
TempStream.SaveToFile(SourceFile);
End;
Result := True;
Except
Result := False;
End;
Finally
IL .Free;
TempStream .Free;
End;
End;
{!~ TifRotatePageRight
The page identified by SourcePageNum in the SourceFile is
rotated 90 degrees Clockwise. If a NewFile is provided
then the SourceFile is unchanged and the results of the
Rotation are output to the NewFile.
Example:
procedure TForm1.Button1Click(Sender: TObject);
begin
TifRotatePageRight(
'Source/00003307.tif',//SourceFile : String;
1, //SourcePageNum : Integer;
'New/00000001.tif' //NewFile : String;
); // ): Boolean;
end;
}