Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: binären Inhalt z.b PDF in einen String laden

  Alt 8. Aug 2023, 12:10
So vielleicht?
Delphi-Quellcode:
program project1;

uses
  SysUtils, Classes;

procedure ReadBinaryFile(const FileName: string; var Data: AnsiString);
var
  Stream: TFileStream;
begin
  Stream := TFileStream.Create(FileName, fmOpenRead);
  try
    SetLength(Data, Stream.Size);
    Stream.ReadBuffer(Data[1], Stream.Size);
  finally
    Stream.Free;
  end;
end;

procedure WriteBinaryFile(const FileName: string; const Data: AnsiString);
var
  Stream: TFileStream;
begin
  Stream := TFileStream.Create(FileName, fmCreate);
  try
    Stream.WriteBuffer(Data[1], Length(Data));
  finally
    Stream.Free;
  end;
end;

var
  head, foot, data: AnsiString;
begin
  head := '--__BOUNDARY__--' + LineEnding + '%PDF-1.3' + LineEnding + '1 0 obj' + LineEnding + '<</Type/Catalog/PageLayout/SinglePage/Pages 3 0 R>' + LineEnding;
  foot := LineEnding + '--__BOUNDARY__--';
  ReadBinaryFile('.\file.bin', data);
  WriteBinaryFile('.\file.bin' + '.new', head + data + foot);
  ReadLn;
end.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat