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
 PDF to picture( TParallel.For and For)
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

foxdingding

65 Posts

Posted - Jan 21 2022 :  04:49:28  Show Profile  Reply
PDF to picture( TParallel.For)

Some pictures were found to be blank

Can I use it like this?



Var
    PDFView: TImageEnView;
.....
Begin
  PDFView.PdfViewer.AllowFormEditing := false;//True;
  PDFView.PdfViewer.Enabled := True;
  ImageEnMView1.AttachedImageEnView := PDFView;
.....
  PDFView.PdfViewer.Enabled := True;
  try
    PDFView.IO.LoadFromFile( OpenPDF.Filename );
    Self.Hint:=OpenPDF.Filename;

    PDFView.MouseInteractGeneral := [ miScroll, miZoom ];
  except
    on e:Exception do
      MessageDlg( 'Error encountered loading PDF file: ' + e.message, mtError, [ mbOK ], 0 );
  end;

..........

            tmpiTask:=TTask.Run(
              procedure
              Begin
                TParallel.For(0,ImageEnMView1.ImageCount - 1,
                  procedure (Hidx: Integer)
                  var
                    tmpIENView:TImageEnView;
                    tmpFileName_Back,
                    tmpFileName_Do:String;
                  begin
                    
tmpFileName_Do :=...

                    tmpIENView:=TImageEnView.Create(Nil);
                    Try
                     
                      ImageEnMView1.CopyToIEBitmap( Hidx, tmpIENView.IEBitmap,TRUE );

                      Try
                        tmpIENView.IO.SaveToFileIEN(tmpFileName_Do);
                      Except
                        TInterlocked.Increment(TInterlocked_Err_Count);
                      End;
                    Finally
                      tmpIENView.Free;
                    End;
                  end);
              End);

......

TTask.WaitForAll([tmpiTask]);
......



Some pictures were found to be blank









foxdingding

65 Posts

Posted - Jan 21 2022 :  04:52:37  Show Profile  Reply
PDF to picture( For)

This is OK!
No blank image.
But it's slow!


       tmpImageEnView:=TImageEnView.Create(Nil);
       Try
         for I := 0 to ImageEnMView1.ImageCount-1 do
         Begin
            Application.ProcessMessages;

            tmpImageEnView.ClearAll;
            ImageEnMView1.CopyToIEBitmap(I,tmpImageEnView.IEBitmap,TRUE );
.....            
tmpFileName_Do:=.........
.....
            Try
            
                tmpIENView.IO.SaveToFileIEN(tmpFileName_Do);
            Except
		....
            End;

         End;
       Finally
          tmpImageEnView.Free;
       End;




Go to Top of Page

xequte

38191 Posts

Posted - Jan 23 2022 :  23:28:36  Show Profile  Reply
Hi

PDFium should NOT be used in threads.

Can you describe what you are wanting to do?

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

foxdingding

65 Posts

Posted - Jan 24 2022 :  07:24:08  Show Profile  Reply
Quickly convert PDF pages to images.
Is there any good way?
Go to Top of Page

xequte

38191 Posts

Posted - Jan 24 2022 :  16:19:55  Show Profile  Reply
Why not just load and save each file? Something like:

tempIE := TImageEnView.Create(nil);
try
  tempIE.PdfViewer.Enabled := True;
  for i := 0 to ssFileList - 1 do
  begin
    tempIE.IO.LoadFromFilePDF( ssFileList[i] );
    tempIE.IO.SaveToFileJPEG( ChangeFileExt( ssFileList[i], '.jpeg' );
  end;
finally
  tempIE.Free;
end;


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

foxdingding

65 Posts

Posted - Jan 24 2022 :  21:14:14  Show Profile  Reply
It's too slow. I want to be faster.
First show all the pages
Then let the user choose
Then convert the selected page.
Go to Top of Page

xequte

38191 Posts

Posted - Jan 24 2022 :  22:45:22  Show Profile  Reply
OK, so you have PDF pages showing in a TImageEnMView, the user specifies (or selects) indexes of pages to save as images, clicks a button and they are then saved in a batch?

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

foxdingding

65 Posts

Posted - Jan 24 2022 :  23:25:46  Show Profile  Reply
YES
Go to Top of Page

xequte

38191 Posts

Posted - Jan 25 2022 :  17:43:12  Show Profile  Reply
Hi

Saving to PDF can be done in threads, it is only loading that does not support threading (PDFium does not support it).

I expect the cause of the blank frames in your first post is due to threading. Is your TImageEnMView StoreType ietThumb/ietFastThumb? If so, then ImageEnMView1.CopyToIEBitmap( idx, bmp, TRUE ); forces the TImageEnMView to load the PDF from file (i.e. threading is not possible).

If TImageEnMView StoreType is ietNormal then loading will not occur then and threading can be used, but that would make your initial fill of TImageEnMView much slower.

So I think LoadFromFilePDF/SaveToFileJPEG is the fastest method overall (Unless they are saving most/all of the images in the TImageEnMView).

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

foxdingding

65 Posts

Posted - Jan 25 2022 :  21:07:12  Show Profile  Reply
yes,TImageEnMView StoreType is ietFastThumb

I will test LoadFromFilePDF/SaveToFileJPEG,today
Go to Top of Page

foxdingding

65 Posts

Posted - Jan 26 2022 :  01:29:30  Show Profile  Reply
20% faster
Old:Operating time:51.635 s
New:Operating time:44.411 s


New Code

........

       PDFView.LockUpdate;
       PDFView.LockPaint;
       Try
         SW:=TStopwatch.StartNew;
         for I := 0 to PDFView.PdfViewer.PageCount-1 do
         Begin
            Self.ProgressBar1.Position:=I;
            Application.ProcessMessages;

            tmpImageEnView.ClearAll;

            PDFView.PdfViewer.PageIndex:=I;
            PDFView.PdfViewer.DrawTo( tmpImageEnView.IEBitmap,
                        MulDiv(PDFView.PdfViewer.PageWidth,300,72),
                        MulDiv(PDFView.PdfViewer.PageHeight,300,72)
                          );
            tmpImageEnView.Update;
........
         End;
         Writeln('Operating time:'+(SW.ElapsedMilliseconds/1000).ToString+'s');
........

       Finally
          PDFView.UnlockUpdate;
          PDFView.UnlockPaint;
      End


Operating time:44.411s
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: