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
 Transforming images to single PDF files
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

981 Posts

Posted - Aug 24 2017 :  18:47:54  Show Profile  Reply
I need to transform a bunch of image files each to single PDF files. So I use this code in a loop:

ThisIEBitmap.Read(fl.Items[i].Path);
ThisIEBitmap.Write('R:\test' + IntToStr(i) + '.pdf');


The created PDF files must meet the following requirements:

• The page orientation of the PDFs must follow the page orientation of the images, i.e. if the image width is larger than the image height then the PDF page orientation must be Landscape and vice-versa.

• The image on the PDF must be centered on the page and there must be a white margin with a fixed size for all PDFs.

• The PDF page dimensions must follow the image dimensions, but the longest dimension (width or height) must have a minimum and a maximum size.

Is this possible?

That's what I tried myself, following the advice in the documentation: "If you set PDF_PaperWidth and PDF_PaperHeight to 0 the page will be output at the size of the image.":

ThisIEBitmap.Read(fl.Items[i].Path);
ThisIEBitmap.Params.PDF_PaperWidth := 0; // EAccessViolation !!!
ThisIEBitmap.Params.PDF_PaperHeight := 0;
ThisIEBitmap.Write('R:\test' + IntToStr(i) + '.pdf');


These are the details of the exception:

Exception:
--------------------------------------------------------------------------------------------------------------
2.2 Address: 01C6697F
2.5 Type : EAccessViolation
2.6 Message: Access violation at address 01C6697F in module 'XYZ.exe'. Write of address 00000548.
2.7 ID : 84D30000
2.11 Sent : 0

xequte

39052 Posts

Posted - Aug 24 2017 :  20:00:04  Show Profile  Reply
Hi Peter

You must call:

ThisIEBitmap.ParamsEnabled := True;

Before reading, if you wish to access the Params.


To automatically set the page size, you can call:

ImageEnView1.IO.Params.PDF_PaperSize := iepAuto;

(Same as setting PDF_PaperWidth/PDF_PaperHeight to zero).





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

PeterPanino

981 Posts

Posted - Aug 25 2017 :  03:46:14  Show Profile  Reply
1. I now use the following code which works very well:

ThisIEBitmap := TIEBitmap.Create;
try
  for i := 0 to fl.Items.Count - 1 do
  begin      
     ThisIEBitmap.ParamsEnabled := True;
     ThisIEBitmap.Params.PDF_PaperSize := iepAuto;
     ThisIEBitmap.Read(fl.Items[i].Path);
     ThisIEBitmap.Resample(500, 500, rfHermite, True);
     ThisIEBitmap.Resize(ThisMargin, ThisMargin, ThisMargin, ThisMargin, clWhite);
     ThisIEBitmap.Write('R:\test' + IntToStr(i) + '.pdf');
  end;
finally
  ThisIEBitmap.Free;
end;


Is there anything which must be additionally freed/released in this code to avoid memory leaks?

2. The Resample method is wonderful! Specifically, the following code with both parameter values of 500 results in a PDF with the largest dimension (width or height) to be exactly 194.0 mm:

ThisIEBitmap.Resample(500, 500, rfHermite, True);

Now, to define the values in the Resample method not in Pixel but in resulting mm in the PDF, I could write an interpolation equation. But I am sure that there is already a method to translate the Pixel values into resulting mm?
Go to Top of Page

xequte

39052 Posts

Posted - Aug 25 2017 :  15:49:01  Show Profile  Reply
Hi Peter

1. No, the code looks line.

2. ImageEn will apply the DPI of the image to the PDF, so for example:

widthInches := 500 / ThisIEBitmap.Params.DPIX;
widthMM := widthInches * 25.4;


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