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
 Multiple TIFF files to PDF
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

nantunes1974

Portugal
2 Posts

Posted - Nov 29 2015 :  11:38:32  Show Profile  Reply
Hi all,

I am trying to convert multiple tif files (multi-page) to pdf. From the seventh file, with about 180KB, all PDF have all pages in tif file but only blank pages.
I appreciate any help, please.
Many thanks in advance.

The code i am using is:

function T_Entrega.RenFilesToPDF(const StartDir: String): Boolean;
var
  sr: TSearchRec;
  Res: Integer;
  _page : SmallInt;
begin
  Res := FindFirst(BackSlash(StartDir) + '*.tif', faAnyfile, sr );

  if Res = 0 then

  try
    while res = 0 do begin
      if (sr.Attr and faDirectory <> faDirectory) then

        with ImageEnView1.IO do begin

          Params.PDF_PaperSize := IEStrToPaperSize('A4', iepA4);
          Params.PDF_Compression := ioPDF_G4FAX;

          CreatePDFFile(BackSlash(DirLotesDest) + ChangeFileExt(sr.name, '.pdf'));

          ImageEnView1.Blank;
          LoadFromFile(BackSlash(DirLotesDest) + sr.Name);

          for _page := 0 to Params.TIFF_ImageCount - 1 do begin
            Params.TIFF_ImageIndex := _page;
            SaveToPDF;
          end;

          ClosePDFFile;
        end;

      ImageEnView1.ClearAll;
      Res := FindNext(sr);

  end;
  finally
    FindClose(sr)
  end;
  Result := True;
end;

xequte

39053 Posts

Posted - Dec 02 2015 :  18:32:48  Show Profile  Reply
Hi

There is an issue in your code. When you want another page of a TIFF you need to set TIFF_ImageIndex and then call LoadFromFile() again.


function TForm1.RenFilesToPDF(const StartDir: String): Boolean;
var
  sr: TSearchRec;
  Res: Integer;
  _page : SmallInt;
begin
  Result := False;
  Res := FindFirst( StartDir + '*.tif', faAnyfile, sr );

  if Res = 0 then
  try
    while res = 0 do
    begin
      if (sr.Attr and faDirectory <> faDirectory) then
        with ImageEnView1.IO do
        begin
          Params.PDF_PaperSize := IEStrToPaperSize('A4', iepA4);
          Params.PDF_Compression := ioPDF_G4FAX;

          CreatePDFFile( StartDir + ChangeFileExt(sr.name, '.pdf'));

          ImageEnView1.Blank;

          // Reset index to load
          Params.TIFF_ImageIndex := 0;
          LoadFromFile( StartDir + sr.Name);

          for _page := 0 to Params.TIFF_ImageCount - 1 do
          begin
            Params.TIFF_ImageIndex := _page;
            // Need to reload if we changed the index
            if _page > 0 then
              LoadFromFile( StartDir + sr.Name);
            SaveToPDF;
          end;

          ClosePDFFile;
          Result := True;
        end;

      ImageEnView1.ClearAll;
      Res := FindNext(sr);
    end;
  finally
    FindClose(sr)
  end;
end;


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

nantunes1974

Portugal
2 Posts

Posted - Dec 03 2015 :  05:15:07  Show Profile  Reply
Many thanks, Nigel.
It works fine.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: