I can successfully convert a PDF to an image using the LoadFromFile (using the code below)
procedure TFrmMain.btnLoadPDFFromFileClick(Sender: TObject);
begin
if not FImageMagick then
begin
TIEMiscPluginsImageMagick.RegisterPlugin;
FImageMagick := True;
end;
if dlgOpen.Execute(Self.Handle) then
begin
imgView.IO.Params.ImageIndex := 0;
imgView.IO.Params.Dict.Insert('PDF:Density', 300);
imgView.IO.LoadFromFile(dlgOpen.FileName);
end;
end;
However, I need to be able to convert a PDF stream directly to an image, without having to save it to a file first.
I tried the following code:
procedure TFrmMain.btnLoadPDFFromStreamClick(Sender: TObject);
var
fs: TFileStream;
begin
if not FImageMagick then
begin
TIEMiscPluginsImageMagick.RegisterPlugin;
FImageMagick := True;
end;
if dlgOpen.Execute(Self.Handle) then
begin
fs := TFileStream.Create(dlgOpen.FileName, fmShareDenyNone);
try
imgView.IO.Params.ImageIndex := 0;
imgView.IO.Params.Dict.Insert('PDF:Density', 300);
imgView.IO.LoadFromStream(fs);
finally
fs.Free;
end;
end;
end;
but that doesn't work.
Should this work? Or do I have to use a different method to convert the PDF to an image?