ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 TImageEnMIO.SaveToFilePDF, lock file

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
gynefab Posted - Nov 16 2016 : 06:58:19
Hello.

I'm using a registered version of ImageEn 6.2.0 with Delphi 2007.

After using this method,
TImageEnMIO.MIO.SaveToFilePDF(PdfFileName);
the PDF can't be deleted while the main application is still running.
The file is locked.

I think the stream file writer is not closed in your code.

Best regards.

Fab.
2   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Nov 16 2016 : 19:23:47
Hi Fab

Bill is correct. As ImageEn closes the file it should no longer be locked. Can you reproduce the problem with the PDF demo?



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
w2m Posted - Nov 16 2016 : 10:57:36
ImageEnIO has a ClosePDFFile method but ImageEnMIO does not because it calls IEPDFClose. You could try using ImageEnView1.IO.CreatePDFFile, ImageEnView1.IO.LoadFromFile, ImageEnView1.IO.SaveToPDF and ImageEnView1.IO.ClosePDFFile to see it resolves your problem. Also see the demo for this.
ImageEnView1.IO.CreatePDFFile( 'D:\output.pdf' );

// load and save page 1
ImageEnView1.IO.LoadFromFile('C:\page1.tiff');
ImageEnView1.IO.Params.PDF_Compression := ioPDF_G4FAX; // G4Fax compression
ImageEnView1.IO.SaveToPDF;

// load and save page 2
ImageEnView1.IO.LoadFromFile('C:\page2.tiff');
ImageEnView1.IO.Params.PDF_Compression := ioPDF_G4FAX; // G4Fax compression
ImageEnView1.IO.SaveToPDF;

...Other pages...
// close PDF file
ImageEnView1.IO.ClosePDFFile;


ImageEnMIO calls IEPDFClose:

procedure TImageEnMIO.SaveToStreamPDF(Stream: TStream; SelectedOnly : boolean = false);
var
  Param: TIOParams;
  Progress: TProgressRec;
  bmp: TIEBitmap;
  NullProgress: TProgressRec;
  han: pointer;
  imgCount: integer;

  procedure _SaveImg(ImgIdx, FileIdx: integer);
  begin
    Param := fParamsList.Params[ImgIdx];
    if FileIdx = 0 then
      han := IEPDFCreate(Param);
    Attached_CopyToIEBitmap( ImgIdx, bmp );
    bmp.DefaultDitherMethod := fDefaultDitherMethod;
    IEPDFSave(han, bmp, Param, NullProgress);
    
    with Progress do
      if assigned(fOnProgress) then
        fOnProgress(Sender, trunc(per1 * FileIdx));
  end;

var
  i: integer;
begin
  try
    fAborting := False;
    if not IsAttached() then
      exit;

    if SelectedOnly and assigned( fImageEnMView ) then
      imgCount := (fImageEnMView as TImageEnMView).MultiSelectedImagesCount
    else
      imgCount := GetIEMBitmap.Count;

    if imgCount = 0 then
      exit;

    Progress := ProgressRec( Self, fOnProgress, fAborting );
    NullProgress := NullProgressRec( Progress.Aborting );

    Progress.per1 := 100 / imgCount;
    bmp := TIEBitmap.Create;
    han := nil;

    i := 0;
    while not fAborting and (i < imgCount) do
    begin
      if SelectedOnly and assigned( fImageEnMView ) then
        _SaveImg((fImageEnMView as TImageEnMView).MultiSelectedImages[i], i)
      else
        _SaveImg(i, i);
      inc(i);
    end;
    if imgCount > 0 then
      Param := fParamsList.Params[0];
    IEPDFClose(han, Stream, Param);
    FreeAndNil(bmp);
  finally
    DoFinishWork;
  end;
end;
{$endif}

{!!
<FS>TImageEnMIO.SaveToFilePDF

<FM>Declaration<FC>
procedure SaveToFilePDF(const FileName: string; SelectedOnly: Boolean = False);

<FM>Description<FN>
Creates a multipage Adobe PDF file with all images in the attached <A TImageEnMView> or <A TIEMultiBitmap>.
If <FC>SelectedOnly<FN> = True and the component is attached to a <A TImageEnMView> then only the selected images are output.

Note: If an internal save error is encountered <A TImageEnMIO.Aborting> will return true. Saving issues due to insufficient write permissions and disk write failures will raise an exception.

<FM>Example<FC>
// load a multipage TIFF and save it as a PDF file
ImageEnMView.MIO.LoadFromFile('C:\multipage.tiff');
ImageEnMView.MIO.SaveToFilePDF('D:\output.pdf');
!!}
{$ifdef IEINCLUDEPDFWRITING}
procedure TImageEnMIO.SaveToFilePDF(const FileName: string; SelectedOnly: Boolean = False);
var
  fs: TFileStream;
begin
  fAborting := False;
  fs := TFileStream.Create(FileName, fmCreate);
  try
    SaveToStreamPDF(fs, SelectedOnly);
  finally
    FreeAndNil(fs);
  end;
end;
{$endif}

Nigel may have other ideas or comments.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development