Open From Stream Follow by SaveDocument

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Post Reply
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Open From Stream Follow by SaveDocument

Post by jeffp »

I'm using your OpenDocumentFromStream example to open my documents because I like the fact that doing it this way releases the lock on the PDF File.

However, once I open the document in this manner and then call your SaveDocument procedure, it appears that the PDF file at that point remains locked. Is this correct?

If I want to release the lock on the file after saving it, what do I need to do?

Thanks.
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: Open From Stream Follow by SaveDocument

Post by Corwin - Tracker Sup »

Hi,

Can you please, send us your example project, so we can test it here?
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: Open From Stream Follow by SaveDocument

Post by jeffp »

Below is my code to Open and Save a document. I've discovered that if I save using PXCVA_DocumentSaveAs a lock is placed on the saved file. However, if I use PXCVA_DocumentSaveCopyAs, a lock is NOT placed on the files.

Does this make sense? If so, I can just use PXCVA_DocumentSaveCopyAs which seems to be fine.

Code: Select all

function TPDFViewerAX.OpenDocument(AFileName: String; APassword: String = ''; ADispFileName: String = ''): Integer;
var
  AStream: IStream;
  ADataIn, ADataOut: OLEVariant;
  vArr: array of OLEVariant;
  AFlags: Integer;
  AWideStr: WideString;
begin
  Result := 0;
  if FileExists(AFileName) then
  begin
    SetDevInfo;
    AFlags := 0; //AFlags := PXCVA_NoUI;

    try
      //Set UseStreamsDirectly
      FControl.SetProperty('Documents.UseStreamsDirectly', 'False', 0);

      //OpenDocument
      AWideStr := AFileName;
      SHCreateStreamOnFileW(PWideChar(AWideStr), 0, AStream); //STGM_READ
      SetLength(vArr, 2);
      vArr[0] := AStream;
      vArr[1] := APassword;
      ADataIn := vArr;
      FControl.DoVerb('', 'OpenDocument', ADataIn, ADataOut, AFlags);

      Result := ADataOut;

      //Seet DispFileName
      if (ADispFileName = '') then ADispFileName := AFileName;
      ADataIn := ADispFileName;
      FControl.SetDocumentProperty(Result, 'DispFileName', ADataIn, 0);

      //Set Modified 
      if not SameText(AFileName, ADispFileName) then
      begin
        ADataIn := ord(True);
        FControl.SetDocumentProperty(Result, 'Modified', ADataIn, 0);
      end;

      InitializeDoc;
    except end;
  end;
end;



function TPDFViewerAX.SaveDocument(ADocID: Integer; AFileName: String): Boolean;
begin
  Result := False;
  if not IsValidDocID(ADocID) then exit;

  //SaveModes
  //PXCVA_DocumentSaveAs = $00000001;
  //PXCVA_DocumentSaveCopyAs = $00000003;
  //PXCVA_DocumentSaveInc = $00000004;  //MUST USE WITH DIGITAL SIGNATURE
  //PXCVA_DocumentSaveForWeb = $00000008;

  if ForceDirectories(ExtractFilePath(AFileName)) then
  begin
    FControl.SaveDocument(ADocID, AFileName, PXCVA_DocumentSaveCopyAs, 0);
    Result := True;
  end;
end;
Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: Open From Stream Follow by SaveDocument

Post by Corwin - Tracker Sup »

In cases where you open a document from a stream, you do not need to specify PXCVA_DocumentSaveAs flag in the SaveDocument function.

When you use PXCVA_DocumentSaveAs Viewer open saved file and it becomes locked. If you don’t want it to lock the file then you can use PXCVA_DocumentSaveCopyAs flag.

HTH.
Post Reply