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
 Generate PDF using this layout
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

yogiyang

India
730 Posts

Posted - Nov 17 2015 :  22:50:59  Show Profile  Reply
I am trying to get ImageEn to generate a single page PDF with layout attached to this post.

I am using following code but am not getting expected result so it seems that I am making some mistake in coding.

procedure CreateAndSavePDF;
var
  PDFFileName: string;
  I, Col: Integer;
  FileComment: String;
  FileName: String;
  LL, LT, LW, LH, NewW, NewH: Integer;
  ieTemp: TImageEnView;
  NewLayerNum: Integer;
  Row: Integer;
begin
  // Initiate PDF file creation
  PDFFileName := IncludeTrailingBackslash(ProjectFolderPath) +
     'projectdetails.pdf';

  ieMain.Background := clWhite;
  ieMain.Clear;
  ieMain.Proc.ImageResize(816, 1056);//Resize canvas/image size to A4 size @96 DPI
  ieMain.SetDPI(96, 96);
  ieMain.IO.AutoAdjustDPI := True;
  ieMain.IO.Params.JPEG_EnableAdjustOrientation := True;

  Col := 1;
  Row := 1;

  ieMain.IO.CreatePDFFile(PDFFileName);

  // Code to add the image to PDF
  for I := 0 to iemComments.ImageCount - 1 do
  begin
    FileComment := Comments[I];
    FileName := iemComments.ImageFileName[I];

    ieTemp := TImageEnView.Create(Application);

    ieTemp.LayersAdd;
    ieTemp.IO.Params.JPEG_EnableAdjustOrientation := True;
    ieTemp.IO.LoadFromFile(FileName);
    LW := ieTemp.CurrentLayer.Width;
    LH := ieTemp.CurrentLayer.Height;

    NewH := 100;
    NewW := 100;

    if LW > LH then
      ieTemp.Proc.Resample(NewW, -1, TResampleFilter(0))
    else
      ieTemp.Proc.Resample(-1, NewH, TResampleFilter(0));

    if Col > 5 then
      Col := 1; //Reset Col to 1

    if Col = 1 then
      LL := 100
    else
      LL := Col * 163;

    LT := Row * 163;

    NewLayerNum := ieMain.LayersAdd;
    ieMain.Layers[NewLayerNum].PosX := LL;
    ieMain.Layers[NewLayerNum].PosY := LT;
    ieMain.Layers[NewLayerNum].Width := NewW;
    ieMain.Layers[NewLayerNum].Height := NewH;

    ieMain.Layers[NewLayerNum].Assign(ieTemp.CurrentLayer);    

    ieTemp.Free;

    Row := Row + 1;
    Col := Col + 1;    

    ieMain.IO.Params.PDF_Compression := ioPDF_JPEG;
    ieMain.IO.SaveToPDF;
  end;

  ieMain.IO.ClosePDFFile;
end;

Can someone please guide me here.

Note: In the code I have not included the part that will add text to keep the code short and simple.

TIA



Yogi Yang

yogiyang

India
730 Posts

Posted - Nov 17 2015 :  23:45:55  Show Profile  Reply
Sorry I forgot to attach the file.

Here it is...





Yogi Yang
Go to Top of Page

yogiyang

India
730 Posts

Posted - Nov 18 2015 :  04:10:01  Show Profile  Reply
Ok now I have been able to get some output in PDF.

Here is updated code:

procedure CreateAndSavePDF;
var
  PDFFileName: string;
  I, Col: Integer;
  FileComment: String;
  FileName: String;
  LL, LT, LW, LH, NewW, NewH: Integer;
  ieTemp: TImageEnView;
  NewLayerNum: Integer;
  Row: Integer;
  ProjectDetails: String;
  iLayerWidth: Integer;
  iLayerHeight: Integer;
begin
  Screen.Cursor := crHourGlass;

  // Initiate PDF file creation
  PDFFileName := IncludeTrailingBackslash(ProjectFolderPath) +
     'projectdetails.pdf';

  
  ieMain.Background := clWhite;
  ieMain.Clear;
  ieMain.Proc.ImageResize(816, 1056);  //Resize canvas/image size to A4 size
  ieMain.SetDPI(96, 96);
  ieMain.IO.AutoAdjustDPI := True;
  ieMain.IO.Params.JPEG_EnableAdjustOrientation := True;

  Col := 1;
  Row := 1;

  ieMain.IO.CreatePDFFile(PDFFileName);

  // Code to add the image to PDF
  for I := 0 to iemComments.ImageCount - 1 do
  begin
    FileComment := Comments[I];
    FileName := iemComments.ImageFileName[I];

    ieTemp := TImageEnView.Create(Application);

    ieTemp.LayersAdd;
    ieTemp.IO.Params.JPEG_EnableAdjustOrientation := True;
    ieTemp.IO.LoadFromFile(FileName);
    LW := ieTemp.CurrentLayer.Width;
    LH := ieTemp.CurrentLayer.Height;

    NewH := 250;
    NewW := 250;

    if LW > LH then
      ieTemp.Proc.Resample(NewW, -1, TResampleFilter(0))
    else
      ieTemp.Proc.Resample(-1, NewH, TResampleFilter(0));

    ieTemp.CurrentLayer.Width := 200;
    ieTemp.CurrentLayer.Height := 200;

    if Col > 5 then
    begin
      Col := 1; //Reset Col to 1
      Row := Row + 1;
    end;

    LL := Col * 250;

    LT := Row * 250;

    NewLayerNum := ieMain.LayersAdd;

    ieMain.Layers[NewLayerNum].Assign(ieTemp.CurrentLayer);

    ieMain.Layers[NewLayerNum].PosX := LL;
    ieMain.Layers[NewLayerNum].PosY := LT;
    ieMain.Layers[NewLayerNum].Width := 200;
    ieMain.Layers[NewLayerNum].Height := 200;

    ieTemp.Free;

    Col := Col + 1;

  end;
  ieMain.LayersMergeAll(True);

  ieMain.IO.Params.JPEG_Quality := 100;
  ieMain.IO.Params.JPEG_Smooth := 0;
  ieMain.IO.Params.PDF_Compression := ioPDF_JPEG;
  ieMain.IO.SaveToPDF;

  ieMain.IO.ClosePDFFile;

  Application.ProcessMessages;

  Screen.Cursor := crDefault;
end;


But yet the images are getting stretched out un-propotionally.

PDF is attached.


TIA


Yogi Yang

attach/yogiyang/2015111841518_projectdetails.zip
2804.41 KB
Go to Top of Page

xequte

39106 Posts

Posted - Nov 18 2015 :  16:45:29  Show Profile  Reply
Hi Yogi

I think you would be best to calculate the adjusted size of the image yourself and then pass that to Resample() and layer.Width/Height.

Please see these functions:

http://www.imageen.com/help/IEAdjustRectToAspectRatio.html
http://www.imageen.com/help/GetImageSizeWithinArea.html
http://www.imageen.com/help/GetImageRectWithinArea.html

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: