Einzelnen Beitrag anzeigen

Benutzerbild von sirius
sirius

Registriert seit: 3. Jan 2007
Ort: Dresden
3.443 Beiträge
 
Delphi 7 Enterprise
 
#4

Re: Je Seite ein Bild in RTF Datei darstellen

  Alt 1. Nov 2007, 16:36
Ich hab mal in nem alten Projekt gekramt. Da habe ich noch RTF direkt in ein Textfile geschrieben.
Schau dir das einfach mal an:
Delphi-Quellcode:
procedure TRTF.WritePictureFrame(const PictureFile:string;posx,posy:integer;maxwidth:integer=0;maxheight:integer=0);
var i:integer;
    jpg:tjpegimage;
    bmp:tbitmap;
    hoehe,breite,nbreite,nhoehe:integer;
    mem:TMemorystream;
    data:string;
    b:^Byte;
begin
  if length(picturefile)=0 then exit;
  jpg:=tJpegimage.Create;
  if lowercase(ExtractFileExt(PictureFile))='.bmpthen begin
    bmp:=tbitmap.Create;
    try
      bmp.LoadFromFile(Picturefile);
    except
      exit;
    end;
    jpg.Assign(bmp);
    bmp.Free;
  end else if (lowercase(ExtractFileExt(PictureFile))='.jpg')or
              (lowercase(ExtractFileExt(PictureFile))='.jpeg')or
              (lowercase(ExtractFileExt(PictureFile))='.jpe') then begin
    try
      jpg.LoadFromFile(pictureFile);
    except
      exit;
    end;
  end else exit;
  jpg.JPEGNeeded;
  hoehe:=jpg.Height*20;
  breite:=jpg.Width*20;
  mem:=Tmemorystream.Create;
  jpg.SaveToStream(mem);
  mem.Seek(0,sofrombeginning);
  b:=mem.Memory;
  data:='';
  for i:=1 to mem.Size do begin
    data:=data+inttohex(b^,2);
    inc(b);
  end;
  mem.Free;
  jpg.Free;

  nbreite:=breite;
  nhoehe:=hoehe;
  maxwidth:=maxwidth*20;
  maxheight:=maxheight*20;
  if (nbreite>maxwidth)and(maxwidth>0) then begin
    nhoehe:=round(nhoehe/(nbreite/maxwidth));
    nbreite:=maxwidth;
  end;
  if (nhoehe>maxheight)and(maxheight>0) then begin
    nbreite:=round(nbreite/(nhoehe/maxheight));
    nhoehe:=maxheight;
  end;
  if posx<0 then begin
    inc(posx);
    posx:=9071+posx*20-nbreite;
  end else posx:=posx*20;
  if posy<0 then begin
    inc(posy);
    posy:=14288+posy*20-nhoehe;
  end else posy:=posy*20;

  writeln(Datei,'\pard\pvmrg\phmrg\posx'+inttostr(posx)+'\posy'+inttostr(posy)+'\absw'+inttostr(nbreite)+'\absh'+inttostr(nhoehe)+'\dxfrtext80');
  writeln(Datei,'{\pict\jpegblip\picw'+inttostr(breite)+'\pich'+inttostr(hoehe)+'\picwgoal'+inttostr(nbreite)+'\pichgoal'+inttostr(nhoehe));
  writeln(Datei,data,'}');
  writeln(Datei,'\par\pard ');

end;

procedure TRTF.WriteMetaFilePicture(const Meta:TMetaFile;posx,posy,maxwidth,maxheight:integer);
var b:^byte;
    data:string;
    Stream:TMemorystream;
    i,hoehe,breite,nbreite,nhoehe:integer;
begin
  Stream:=tmemorystream.Create;
  Meta.SaveToStream(Stream);
  Stream.Seek(0,sofrombeginning);
  b:=Stream.Memory;

  data:='';
  for i:=1 to Stream.Size do
  begin
    data:=data+inttohex(b^,2);
    inc(b);
  end;
  Stream.Free;

  nbreite:=Meta.Width;
  nhoehe:=Meta.Height;
  maxwidth:=maxwidth*20;
  maxheight:=maxheight*20;
  if (nbreite>maxwidth)and(maxwidth>0) then
  begin
    nhoehe:=round(nhoehe/(nbreite/maxwidth));
    nbreite:=maxwidth;
  end;
  if (nhoehe>maxheight)and(maxheight>0) then
  begin
    nbreite:=round(nbreite/(nhoehe/maxheight));
    nhoehe:=maxheight;
  end;
  if posx<0 then
  begin
    inc(posx);
    posx:=9071+posx*20-nbreite;
  end else posx:=posx*20;
  if posy<0 then
  begin
    inc(posy);
    posy:=14288+posy*20-nhoehe;
  end else posy:=posy*20;

  writeln(Datei,'\pard\pvmrg\phmrg\posx'+inttostr(posx)+'\posy'+inttostr(posy)+'\absw'+inttostr(nbreite)+'\absh'+inttostr(nhoehe)+'\dxfrtext80');
  writeln(Datei,'{\pict\emfblip\picw'+inttostr(breite)+'\pich'+inttostr(hoehe)+'\picwgoal'+inttostr(nbreite)+'\pichgoal'+inttostr(nhoehe));
  writeln(Datei,data,'}');
  writeln(Datei,'\par\pard ');
end;
Datei ist ein TextFile, was so vorbereitet wurde (:
Delphi-Quellcode:
  write(Datei,'{\rtf1 \ansi\ansicpg1252');
  writeln(Datei,'\deff0{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}}');
  writeln(Datei,'{\info{\title ',Titel,'}{\subject ',Inhalt,'}{\author ',Bearbeiter,'}{\company ',
          Firma,'}{\category Protokoll}{\comment Created by MusterMaus}{\doccomm '+messort+'}{\version1}{\creatim\yr',
          yearof(Zeit),'\mo',monthof(Zeit),'\dy',dayof(Zeit),'\hr',hourof(Zeit),
          '\min',minuteof(Zeit),'\sec',secondof(Zeit),'}}');
  //die Infozeile kannst du weglassen

  writeln(Datei,'\paperw11907\paperh16840\margl1418\margr1418\margt1418\margb1134 ');
  writeln(Datei,'\viewkind1\viewzk2\uc1\pard ');
Vergess dann das "}" am Ende nicht!

Und für nen Seitenumbruch musst du mal in den Spec nachlesen. Ich glaube "/page" ist dann dein Freund.

Edit: Upps, du warst ja schon soweit
Dieser Beitrag ist für Jugendliche unter 18 Jahren nicht geeignet.
  Mit Zitat antworten Zitat