ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 PDF stream to Image conversion

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Oribi Posted - Jul 17 2017 : 09:14:26
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?
3   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Jul 18 2017 : 04:25:10
Thanks, I have updated it.

Apologies for the oversight.


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Oribi Posted - Jul 17 2017 : 09:44:16
After looking at the code again I think it would be better (and enough) to just switch the if statements.

So instead of:

if filename <> '' then
readOK := TIEMiscPluginsImageMagick.MagickPingImage(..)
else
if mstream <> nil then
readOK := TIEMiscPluginsImageMagick.MagickPingImageBlob(..);

do:

if mstream <> nil then
readOK := TIEMiscPluginsImageMagick.MagickPingImageBlob(..)
else
if filename <> '' then
readOK := TIEMiscPluginsImageMagick.MagickPingImage(..);

Oribi Posted - Jul 17 2017 : 09:38:33
I debugged the code and it appears that there is a bug in the "procedure TIEMiscPluginsImageMagick_ReadImageStream" method.

In this method the following check is used to decide which MagickReadImage (file or stream) is used:

if filename <> '' then

However, when this code is executed the filename is [0] for a stream.
Because of this the:

if mstream <> nil then
readOK := TIEMiscPluginsImageMagick.MagickReadImageBlob(mwand, mstream.Memory, mstream.Size);

is never executed.
When I replaced the if statement with

if Stream is TIEWideFileStream then

The read from stream code worked fine.