procedure MakePicture(const dRects: array of TDRect; const EPSLoadFile, EPSSaveFile, JPGLoadFile, JPGSaveFile: WideString);
const
iWidth = 6000;
iHeight = 3898;
iRussianType = 'Печать';
iRDGColor = 'RDG_WHITE';
iNoColor = '[Без цвета]';
var
Illustrator, Document, DOC, Layer, RDG_WHITE, Spots: Variant;
PlacedItem, PathItem: Variant;
EPSSave: _EPSSaveOptions;
ICO: _ImageCaptureOptions;
PresetName, SpotsName: WideString;
CMYKColor: _CMYKColor;
SpotColor: Variant;
i: Integer;
begin
Illustrator := CreateOleObject('Illustrator.Application');
try
if EPSLoadFile <> '' then
begin
Document := Illustrator.Open(EPSLoadFile, aiDocumentCMYKColor, null);
end
else
begin
PresetName := Illustrator.GetPresetFileOfType(aiPrintPreset);
DOC := Illustrator.GetPresetSettings(iRussianType);
DOC.Width := iWidth;
DOC.Height := iHeight;
DOC.DocumentColorSpace := aiDocumentCMYKColor;
DOC.DocumentUnits := aiUnitsPixels;
DOC.DocumentPreviewMode := aiPixelPreview;
DOC.DocumentRasterResolution := aiHighResolution;
DOC.DocumentTransparencyGrid := aiTransparencyGridDark;
Document := Illustrator.Documents.AddDocument(iRussianType, DOC);
Layer := Document.Layers.Add;
end;
// Загрузка палитры цветов.
RDG_WHITE := Null;
for i := 1 to Document.Spots.Count do
begin
Spots := Document.Spots.Item[Variant(i)];
SpotsName := Spots.Name;
if SpotsName = iRDGColor then
RDG_WHITE := Spots.Color;
end;
// Добавляем RDG_WHITE если он отсутствует.
if RDG_WHITE = Null then
begin
CMYKColor := CoCMYKColor.Create;
CMYKColor.Cyan := 0;
CMYKColor.Magenta := 0;
CMYKColor.Yellow := 30;
CMYKColor.Black := 10;
RDG_WHITE := Document.Spots.Add;
RDG_WHITE.Name := iRDGColor;
RDG_WHITE.Color := CMYKColor;
RDG_WHITE.ColorType := aiSpot;
SpotColor := CoSpotColor.Create;
SpotColor.Spot := RDG_WHITE;
SpotColor.Tint := 100;
end;
Document.DefaultFillColor := SpotColor;
Document.DefaultStrokeColor := SpotColor;
// Рисование прямоугольников под картинкой с цветом RDG_WHITE
i := 0;
while i < Length(dRects) do
begin
PathItem := Document.PathItems.Rectangle(dRects[i].Top, dRects[i].Left, dRects[i].Width, dRects[i].Height);
PathItem.FillColor := Document.DefaultFillColor;
PathItem.StrokeColor := Document.DefaultStrokeColor;
inc(i);
end;
// Вставка картинки в файл.
PlacedItem := Document.PlacedItems.Add;
PlacedItem.File := JPGLoadFile;
PlacedItem.Left := 0;
PlacedItem.Top := iHeight;
PlacedItem.Width := iWidth;
PlacedItem.Height := iHeight;
PlacedItem.Embed;
// Сохранение в EPS
if EPSSaveFile <> '' then
begin
EPSSave := CoEPSSaveOptions.Create;
try
EPSSave.CMYKPostScript := False;
EPSSave.EmbedAllFonts := True;
Document.SaveAs(EPSSaveFile, EPSSave);
finally
EPSSave := nil;
end;
end;
// Сохранение геометрической области в файл JPG.
if JPGSaveFile <> '' then
begin
ICO := CoImageCaptureOptions.Create;
try
Document.ImageCapture(JPGSaveFile, Document.GeometricBounds, ICO);
finally
ICO := nil;
end;
end;
finally
Illustrator.quit;
Illustrator := Unassigned;
end;
end;
procedure TFromIllustratorTest.FullActionClick(Sender: TObject);
begin
MakePicture([DRect(3898, 0000, 1200, 1945),
DRect(1945, 0000, 1200, 1945),
DRect(1945, 2400, 1200, 1945)],
'', 'C:\33.eps', 'C:\32.jpg', '');
end;