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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Get number of images in a pdf file
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

w2m

USA
1990 Posts

Posted - Dec 14 2016 :  13:27:50  Show Profile  Reply
Despite many years using ImageEn I have not tried to load pdf images. Having said that, I cannot get the number of images in a pdf file:
// Read the count of the images in a file
function GetPDFPageCount(const AFileName: String): Integer;
var
  iImageEnIO: TImageEnIO;
  iPages: Integer;
begin
  Result := -1;
  iImageEnIO := TImageEnIO.Create(nil);
  iImageEnIO.ParamsFromFile(AFileName);
  iPages := iImageEnIO.Params.ImageCount;
  Result := iPages;
  iImageEnIO.Free;
end;

GetPDFPageCount returns a value of 1 with a pdf file that has 6 images.

If I substitute a value of 6 for the GetPDFPageCount function the file loads all the frames successfully into TImageEnMView.
procedure TForm1.Open1Click(Sender: TObject);
var
  i: Integer;
  iPageCount: Integer;
  iFilename: string;
begin
  if OpenPictureDialog1.Execute then
  begin
    if TIEMiscPluginsImageMagick.IsAvailable then
    begin
      ImageEnMView1.Clear;
      iFilename := OpenPictureDialog1.FileName;
      if FileExists(iFilename) then
      begin
        iPageCount := GetPDFPageCount(iFilename);
        for i := 0 to iPageCount - 1 do
          ImageEnMView1.AppendImage(iFilename + IEM_Path_Index_Delimiter +
            IntToStr(i));
        ImageEnView1.IO.Params.ImageIndex := 1;
        ImageEnView1.IO.Params.Dict.Insert('PDF:Density', 200);
        ImageEnView1.IO.LoadFromFile(iFilename);
        ImageEnView1.Fit;
        Caption := 'PDF- ' + iFilename;
        StatusBar1.Panels[0].Text := ExtractFileDir(iFilename);
        StatusBar1.Panels[1].Text := ExtractFileName(iFilename);
        StatusBar1.Panels[2].Text := IntToStr(iPageCount);
      end;
    end
    else
    begin
      MessageBox(0, 'Failed to load ImageMagick plugin.', 'Warning',
        MB_ICONWARNING or MB_OK);
    end;
  end;
end;

I found a small dll that is supposed to do this but I cannot get it to function.
attach/w2m/20161214131651_pdfpagecount.zip
58.42 KB
http://www.angusj.com/delphitips/pdfpagecount.php
Is there a way to do this?

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development

xequte

38611 Posts

Posted - Dec 14 2016 :  23:44:29  Show Profile  Reply
Hi Bill

You should use IEGetFileFramesCount:

http://www.imageen.com/help/IEGetFileFramesCount.html

Though you will get the same result as you are calling IEPDFFrameCount anyway. Unfortunately the existing method does not support all PDF formats.

In the next update (or the one on our git repository), it will use available PDF plug-ins such as the good wpviewpdf plug-in to more accurately get the page count.



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

w2m

USA
1990 Posts

Posted - Dec 15 2016 :  09:52:37  Show Profile  Reply
IEGetFileFramesCount does not work correctly with any pdf files I have. It is a bit much to spend about $500 just to get the number of frames in a pdf file. I urge you to develop a method to do this correctly so that TImageEnMView can load multiframe pdf images. Without this method it is not possible. Perhaps the link to the code I posted can help Fabrizio write a method to accomplish this.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

xequte

38611 Posts

Posted - Dec 15 2016 :  17:08:18  Show Profile  Reply
Hi Bill

Remember that ImageEn cannot open PDF files without a plug-in, so naturally IEGetFileFramesCount does not work well without a plug-in.

Of course, if you install a plug-in (either Ghostscript which is free or wpviewpdf which is inexpensive at 60 Euro - I will buy it for you for Xmas) then ImageEn can open PDF files and IEGetFileFramesCount will work (as long as you install 6.3.3).


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

w2m

USA
1990 Posts

Posted - Dec 15 2016 :  17:42:01  Show Profile  Reply
Nigel,

In my app I have both ImageMagick and Ghostscript installed so I thought that would have been sufficient. But anyway I do not see any prices below 215 euro for wPDFControl V4 standard. http://www.wpcubed.com/pdf/order/dllproducts/ Am I looking at the wrong page? Currently for testing I using a invisible PDF Viewer control by Developers Express to get the frame count. It works but of course it is not optimum. Once I get the frame count TImageEnMView loads the frames correctly and I can access the images through IEBitmap. I can also load one frame at a time into TImageENView without using TImageEnMView with no problem.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

xequte

38611 Posts

Posted - Dec 15 2016 :  19:07:39  Show Profile  Reply
Hi Bill

Are you using the updated version of IEPDFFrameCount() from our Git repository? I have just emailed you the source code for it. If not then IEGetFileFramesCount will not use the plug-in.

You can find the WPViewPDF plug-in on our store, right below your book Let me buy it for you for Xmas.

http://www.imageen.com/order/

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

w2m

USA
1990 Posts

Posted - Dec 16 2016 :  10:09:22  Show Profile  Reply
Nigel,

I ordered WPViewPDF MakeImage for testing.

Thanks.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: