Page 1 of 1

Trying delete first page from a DOCX

Posted: Thu Sep 26, 2019 10:18 am
by aristeo
I'm trying delete first page of a document with this code:

Code: Select all

var
  i:Integer;
  Temp:String;
begin
  F:TForm;
  with TDOCXReadWrite.Create(nil) do
    try
      LoadFromFile(Path);
      F:=TForm.Create(nil);
      try
        with TAXWPreviewVcl.Create(nil) do
         try
           Parent:=F;
           Document:=Editor;
           Paint;
           Editor.Pages.Delete(0);           
           ShowMessage(IntToStr(Editor.Pages.Count));
           SaveToFile(Path);
         finally
           Free;
         end;
      finally
        FreeANdNil(F);
      end;
    finally
      Free;
    end;
end;
When ShowMessage is executed, the page count showed is ok... The Editor.Pages.Delete(0) worked ok however when the document is saved the first page isn't delete.

What's the problem? Thanks

Re: Trying delete first page from a DOCX

Posted: Sun Sep 29, 2019 7:48 am
by larsa
Hello

To delete a specific page, use code like this:

Code: Select all

DOCX.Editor.MainDoc.Selections.Add(DOCX.Editor.MainDoc.Pages[0].FirstPos.Para,
                                   DOCX.Editor.MainDoc.Pages[0].FirstPos.CharPos,
                                   DOCX.Editor.MainDoc.Pages[0].LastPos.Para,
                                   DOCX.Editor.MainDoc.Pages[0].LastPos.CharPos);
DOCX.Editor.MainDoc.Selections.Delete;