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
 Merge 2 files into one
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

lorife

Italy
44 Posts

Posted - Feb 11 2022 :  11:45:42  Show Profile  Reply
Hello,

I have 2 jpg on a format A4 portrait and I need to create one A4 PDF landscape of 1 page, containing both images shrinked, one next to another.
Could you help me doing that?
thank you

xequte

38608 Posts

Posted - Feb 12 2022 :  00:29:44  Show Profile  Reply
Hi Lorenzo

Here's an example that creates a PDF document from two stacked landscape images

  bmp1 := TIEBitmap.Create();
  bmp2 := TIEBitmap.Create();
  destBmp := TIEBitmap.Create();

  bmp1.Read( 'D:\im1.jpg' );
  bmp2.Read( 'D:\im2.jpg' );

  IEJoinBitmaps( destBmp, bmp1, bmp2, True { Vertical }, clWhite );

  destBmp.ParamsEnabled := True;
  destBmp.Params.PDF_PaperSize := iepA4;
  destBmp.Params.PDF_Compression := ioPDF_Jpeg;

  destBmp.Write('D:\out.pdf');

  bmp1.Free();
  bmp2.Free();
  destBmp.Free();


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

lorife

Italy
44 Posts

Posted - Feb 14 2022 :  03:47:21  Show Profile  Reply
nice! I will try it out, thank you
Go to Top of Page

lorife

Italy
44 Posts

Posted - Feb 18 2022 :  08:17:33  Show Profile  Reply
Hello,
I have tried it but something is not working corretly.
first, I had to change this line like this:
IEJoinBitmaps( destBmp, bmp1, bmp2, FALSE, clWhite );

then, if I use the same original images I obtain different situations:
- sometimes merged page is empty
- sometimes I just have left image
- sometimes I just have right image
- sometimes it works correctly.

it seems the problem might be with this:
bmp1.Read('c:\temp\File1.pdf');
bmp2.Read('c:\temp\File2.pdf');
which sometimes it loads and sometimes it does not

Same program, just close and reopen it.
Any idea of what could it be?
thanks


EDIT: I have sent you both PDF in private.
Go to Top of Page

xequte

38608 Posts

Posted - Feb 22 2022 :  23:09:19  Show Profile  Reply
Hi Lorenzo

I received the files you sent and tested it as follows:

procedure TfrmMain.Button3Click(Sender: TObject);
const
  Iteration_Count = 1000;
var
  bmp1,bmp2, destBmp: TIEBitmap;
  I: Integer;
begin
  for I := 1 to Iteration_Count do
  begin
    Caption := IntToStr( i ) + '/' + IntToStr( Iteration_Count );

    bmp1 := TIEBitmap.Create();
    bmp2 := TIEBitmap.Create();
    destBmp := TIEBitmap.Create();

    bmp1.Read( 'D:\im1.pdf' );
    bmp2.Read( 'D:\im2.pdf' );

    IEJoinBitmaps( destBmp, bmp1, bmp2, FALSE, clWhite );

    if destBmp.Width < 100 then
      raise Exception.create( 'destBmp Invalid' );
    if bmp1.Width < 100 then
      raise Exception.create( 'bmp1 Invalid' );
    if bmp2.Width < 100 then
      raise Exception.create( 'bmp2 Invalid' );

    destBmp.ParamsEnabled := True;
    destBmp.Params.PDF_PaperSize := iepA4;
    destBmp.Params.PDF_Compression := ioPDF_Jpeg;

    destBmp.Write('D:\out.pdf');

    ImageEnView1.IO.LoadFromFile( 'D:\out.pdf');
    ImageEnView2.Assign( bmp1 );
    ImageEnView3.Assign( bmp2 );

    if ImageEnView1.IEBitmap_Width < 100 then
      raise Exception.create( 'ImageEnView1 Invalid' );
    if ImageEnView2.IEBitmap_Width < 100 then
      raise Exception.create( 'ImageEnView2 Invalid' );
    if ImageEnView3.IEBitmap_Width < 100 then
      raise Exception.create( 'ImageEnView2 Invalid' );

    bmp1.Free();
    bmp2.Free();
    destBmp.Free();
  end;
end;


I didn't encounter any errors. Can you give me more information?

What version of Delphi are you using? 32 or 64bit apps?

Please ensure you are not running in a thread. PDFium does not support threading.

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

lorife

Italy
44 Posts

Posted - Feb 23 2022 :  03:38:01  Show Profile  Reply
Hello,
Yes I was in a sub-thread, outside of it, works.

Please tell me there's a workaround....I really need this to be in a subthread.
There's only one thread active, so dll is not shared.

Why is it not working? I can't believe I'm the only one using threads; I have to process many files 24/7 I cannot do it without threads..

thanks

EDIT:
Is seems that running this inside the subtread works. What do you think?

TThread.Synchronize(nil,
        procedure
        begin
          bmp1    := TIEBitmap.Create();
          bmp2    := TIEBitmap.Create();
          destBmp := TIEBitmap.Create();
          bmp1.Read('.\in_1.pdf');
          bmp2.Read('.\in_2.pdf');
          IEJoinBitmaps( destBmp, bmp1, bmp2, false, clWhite);
          destBmp.Write('.\out.pdf');
          bmp1.Free();
          bmp2.Free();
          destBmp.Free();
        end
      );


I don't really like this way though. Consider that I have a service doing many different things 24/7. Doing this I guess it makes the service hang until it's finished. I have many PDF, often big, I can't allow the service to stop for 5 minutes every 5 minutes.....

I tried using critical sections when loading/saving but it does not seem to work.

Also, the resulting page is portrait, how can i make it landscape?
thanks
Go to Top of Page

xequte

38608 Posts

Posted - Feb 23 2022 :  15:00:27  Show Profile  Reply
Hi

It is a limitation of PDFium that prevents it from being used in a thread, so it is not something we can resolve. Synchronizing the code should allow you to workaround it.

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

lorife

Italy
44 Posts

Posted - Feb 24 2022 :  03:26:15  Show Profile  Reply
Hello.

this is really bad news, and a huge limitation.
I cannot syncronize the code for dozen of big PDF every 5 minutes inside a service.

What part of the code is responsible for this? both load and save? Also IEJoinBitmaps?

How can I make the PDF landscape? It comes out portrait.

thanks!
Go to Top of Page

xequte

38608 Posts

Posted - Feb 24 2022 :  15:05:30  Show Profile  Reply
Hi Lorenzo

Any part that uses PDFium cannot be used in a thread (i.e. loading and rendering PDF files). Blame Google for that limitation

All the ImageEn code is thread-safe.

You might want to use WPViewPDF for PDF support instead:

https://www.imageen.com/wpviewpdf/


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

lorife

Italy
44 Posts

Posted - Feb 24 2022 :  15:56:10  Show Profile  Reply
Ok I will think about that.
Thanks

Could you help me on having the PDF landscape instead of portrait? The code you posted creates a portrait.

Thanks
Go to Top of Page

xequte

38608 Posts

Posted - Feb 24 2022 :  17:01:51  Show Profile  Reply
Hi Lorenzo

Email me for an update. You can use:

// Set PDF paper size to A4 Landscape
ImageEnView1.IO.Params.PDF_PaperSize   := iepA4;
ImageEnView1.IO.Params.PDF_PaperLayout := ielLandscape;


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

lorife

Italy
44 Posts

Posted - Feb 25 2022 :  03:39:13  Show Profile  Reply
Hello,
it works. thank you.

What's the difference with WPViewPDF, other than (I guess) it's thread-safe? Does it offer something more (or less)?

thanks
Go to Top of Page

xequte

38608 Posts

Posted - Feb 27 2022 :  16:13:39  Show Profile  Reply
Hi

If you're only rasterizing PDF files (showing as images) then there probably isn't much difference. Some users report that PDFium gives better quality, but I have not confirmed it. WPViewPDF has the advantage of being thread-safe.

The ImageEnView1.PDFViewer only works with the PDFium plug-in (text selection, form editing, native rendering, page manipulation, all pages view, etc).

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