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
 Extract the images from a PDF
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

jeffp

USA
42 Posts

Posted - Oct 17 2024 :  09:17:58  Show Profile  Reply
Is there a way to extract or pull out the images contained in an image PDF file.

For example, we do a lot with scanned documents. So we get a tons of image based PDF files. Sometimes we need to pull out the image, clean it up, and the put the image back in the PDF.

Can this be done?

jp

xequte

38608 Posts

Posted - Oct 17 2024 :  17:40:50  Show Profile  Reply
Yes, please see the image example at:

http://www.imageen.com/help/TIEPdfViewer.Objects.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

jeffp

USA
42 Posts

Posted - Oct 25 2024 :  14:29:48  Show Profile  Reply
I can pull the image out of the page, but it's not letting me put the image back in the page. I'm trying to pull an image out of a PDF page, clean it up, and then put it right back in. Here's my code.

It's crashing on the line: oPDF.SetImage(B);

function TEnDoc.CleanupPDFPage(AOpts: TRecCleanupOptions; APageNo: Integer = 0): TRecCleanupResult;
var
  i: Integer;
  B: TBitmap;
  oPDF: TPdfObject;
begin
  Result := TRecCleanupResult.Create;
  if (AOpts <> []) then
  begin
    SelectPage(APageNo);
    if (CurrentPage > 0) then
    begin
      for i := 0 to FViewer.PdfViewer.Objects.Count - 1 do
      begin
        oPDF := FViewer.PdfViewer.Objects[i];
        if (oPDF.ObjectType = ptImage) then
        try
          B := oPDF.GetImage;
          try
            Result := EN_CleanupBitmap(B, AOpts);
            oPDF.SetImage(B);
            FViewer.PdfViewer.ReloadPage;
          finally
            B.Free;
          end;
          FModified := True;
        except  end;
        break; //NOTE: We are only going to clean if One image on page.
      end;
    end;
  end;
end;


jp
Go to Top of Page

xequte

38608 Posts

Posted - Oct 25 2024 :  18:14:33  Show Profile  Reply
Hi Jeff

I'll need to investigate that. If you comment out the line:

// Result := EN_CleanupBitmap(B, AOpts);

(i.e. set the same bitmap, you extract).

Does it still fail? If not, what occurs in EN_CleanupBitmap()?

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

jeffp

USA
42 Posts

Posted - Oct 26 2024 :  09:25:37  Show Profile  Reply
Yes, it still fails even if you just get the Bitmap and immediately re-set it.

jp
Go to Top of Page

xequte

38608 Posts

Posted - Oct 26 2024 :  17:31:40  Show Profile  Reply
OK, thanks. Can you email me a sample PDF where it occurs. 32 or 64bit application? What version of Delphi?

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

jeffp

USA
42 Posts

Posted - Oct 26 2024 :  21:06:46  Show Profile  Reply
It's a 32bit application. Using Delphi Delphi 11 Version 28.0.48361.3236

jp

attach/jeffp/2024102621719_ColorTest.pdf
Go to Top of Page

xequte

38608 Posts

Posted - Oct 27 2024 :  08:40:32  Show Profile  Reply
Thanks, I'll test it once I'm back in the office.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

38608 Posts

Posted - Nov 05 2024 :  00:31:17  Show Profile  Reply
Hmm, your code with the PDF above works fine for me:

procedure TfrmMain.Button3Click(Sender: TObject);
var
  i: Integer;
  B: TBitmap;
  oPDF: TPdfObject;
  FViewer: TImageEnView;
begin
  OpenFile( 'D:\Testing_Multimedia\PDF\ColorTest.pdf' );
  FViewer := ImageEnView1;

  for i := 0 to FViewer.PdfViewer.Objects.Count - 1 do
  begin
    oPDF := FViewer.PdfViewer.Objects[i];
    if (oPDF.ObjectType = ptImage) then
    try
      B := oPDF.GetImage;
      try
        // Result := EN_CleanupBitmap(B, AOpts);
        oPDF.SetImage(B);
        FViewer.PdfViewer.ReloadPage;
      finally
        B.Free;
      end;
    except
      Raise;
    end;
    //break; //NOTE: We are only going to clean if One image on page.
  end;
end;



As do both of the following:

// Reduce the size of the PDF file by lowering the quality of the images (B is a TIEBitmap)
for i := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do
begin
  oPDF := ImageEnView1.PdfViewer.Objects[i];
  if (oPDF.ObjectType = ptImage) then
  begin
    B := TIEBitmap.Create();
    try
      if oPDF.GetImage( B ) then
      begin
        B.Resample( 0.5 );
        oPDF.SetImage(B);
       end;
    finally
      B.Free;
    end;
  end;
end;
ImageEnView1.PdfViewer.ReloadPage();

// Same as above but B is a TBitmap (must add iexHelperFunctions to your uses clause for TBitmap.Proc)
for i := 0 to ImageEnView1.PdfViewer.Objects.Count - 1 do
begin
  oPDF := ImageEnView1.PdfViewer.Objects[i];
  if (oPDF.ObjectType = ptImage) then
  begin
    B := oPDF.GetImage();
    if B <> nil then
    try
      B.Proc.Resample( 0.5 );
      oPDF.SetImage(B);
    finally
      B.Free;
    end;
  end;
end;
ImageEnView1.PdfViewer.ReloadPage();



Are you using ImageEn v13.6.0?

Does it happen with all PDF files you test.

Can you check your version of the iepdf32.dll, by right-clicking it and selecting Properties? It should be v 125.0.6406.0.

Is there any further information you can provide?

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: