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
 SaveToFilePDF output
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

aleatprog

127 Posts

Posted - Oct 01 2018 :  02:36:12  Show Profile  Reply
My application processes e.g. PDF, TIF and JPG images.

A) In case of JPG or TIF, I load the image with Batch.MIO.LoadFromFile(path) and save it e.g. with Batch.MIO.SaveToFileTIFF(path) or Batch.MIO.SaveToFilePDF(path) without any problems.

B) In case of PDF, I create a TBitmap and fill it with the rendered PDF image (Bitmap := Pdf.RenderPage(0,0,Pdf.PageWidth,Pdf.PageHeight)). As result, ImageEnMView shows the Bitmap with the correct colors and proportions. But saving this Bitmap with Batch.MIO.SaveToFileTIFF(path) the TIF file is empty (size property = 0 byte), and saving it with Batch.MIO.SaveToFilePDF(path) the PDF file contains an image with wrong colors and proportions.

As A) works, maybe I miss something while creating the Bitmap in process B).

Any ideas what could cause the output problem, maybe missing parameters or similar?

xequte

38311 Posts

Posted - Oct 01 2018 :  14:27:24  Show Profile  Reply
Hi

Please show your full code for B, loading a PDF, rendering it to a bitmap and assigning the bitmap to the TImageEnMView.

Also, what plug-in do you use for PDF support?



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

aleatprog

127 Posts

Posted - Oct 01 2018 :  17:25:27  Show Profile  Reply
PDF support by Pdfium.


procedure TformMain.Button1Click(Sender: TObject);
var
  i: Integer;
  Bitmap: TBitmap;
begin
  if OpenDialog.Execute then
    begin
      Pdf.FileName := OpenDialog.FileName;
      Pdf.Active := True;
      try
        for i := 1 to Pdf.PageCount do
          begin
            Pdf.PageNumber := i;
            Bitmap := Pdf.RenderPage(0,0,Round(Pdf.PageWidth),Round(Pdf.PageHeight));
            try
              Batch.AppendImage(Bitmap);
            finally
              FreeAndNil(Bitmap);
            end;
          end;
      finally
        Pdf.PageNumber := 1;
        Pdf.Active := False;
      end;
   end;
end;
Go to Top of Page

xequte

38311 Posts

Posted - Oct 02 2018 :  02:01:10  Show Profile  Reply
I cannot see anything wrong in your code. I assume the page looks OK in the TImageEnMView?

Are you able to create a simple demo that shows it, and email it to us (replacing the pdfium code with some generic bitmap painting code).

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

aleatprog

127 Posts

Posted - Oct 02 2018 :  06:10:57  Show Profile  Reply
This is exactly the point: The bitmap looks perfect in TImageEnMView but not in the PDF file saved by TImageEnMView.

I created some simple demos using a JPG image and all run fine.

As I wrote in the opening post, without the usage of Pdfium, the quality of the bitmap inside TImageEnView and the saved file are both perfect. The problem starts with the rendering process of Pdfium.

The image below shows in the upper part the rendering result in TImageEnMView (color + size ok) and in the lower part the PDF file saved by TImageEnMView (b/n, stretched).

Are there any parameters I may add to the TImageEnMView MIO.SaveToFileTIFF and MIO.SaveToFilePDF process in order to guarantee that the shown bitmap in TImageEnMView got the same properties as the bitmap inside the file saved by TImageEnMView?

Go to Top of Page

xequte

38311 Posts

Posted - Oct 02 2018 :  15:03:58  Show Profile  Reply
Most importantly, what is the Bitmap.PixelFormat value after the PDF.Render call?


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

aleatprog

127 Posts

Posted - Oct 02 2018 :  16:18:34  Show Profile  Reply
BitsPerSample and SamplesPerPixel are identical for both, bitmaps load from JPG/TIF and bitmaps from PDF passed by Pdfium.

Meanwhile I wrote a PDF Export function which saves the single bitmaps from TImageEnMView to file using the ImageEnMView.GetTIEBitmap.Write function, and reassempling the PDF page per page. This works for both bitmap sources.
Go to Top of Page

xequte

38311 Posts

Posted - Oct 02 2018 :  18:40:53  Show Profile  Reply
Yes, but please confirm what is the value of TBitmap.PixelFormat. It should not be pfDevice.


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

aleatprog

127 Posts

Posted - Nov 05 2018 :  06:29:17  Show Profile  Reply
Hi Nigel, setting the PixelFormat to 24bit the bitmap is saved correctly. Thank you for the hint. :)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: