import os
import win32com.client

def try_saveas2(doc_path):
    word = win32com.client.Dispatch("Word.Application")
    word.Visible = False
    
    try:
        if not os.path.exists(doc_path):
            print(f"File not found: {doc_path}")
            return
            
        abs_path = os.path.abspath(doc_path)
        pdf_path = os.path.splitext(abs_path)[0] + "_saveas2.pdf"
        
        doc = word.Documents.Open(abs_path)
        
        # Ensure comments are visible
        word.ActiveWindow.View.ShowComments = True
        word.ActiveWindow.View.RevisionsMode = 0
        word.Options.PrintComments = True
        
        print(f"Saving {os.path.basename(doc_path)} using SaveAs2...")
        
        # FileFormat=17 is wdFormatPDF
        doc.SaveAs2(FileName=pdf_path, FileFormat=17)
        
        doc.Close(SaveChanges=False)
        print(f"Saved to {pdf_path}")
        
    except Exception as e:
        print(f"Error: {e}")
    finally:
        word.Quit()

if __name__ == "__main__":
    file_path = r"C:\Users\Administrator\.gemini\antigravity\scratch\bluebeam-comment-conv\06 17 19 markup.docx"
    try_saveas2(file_path)
