``` import os from azure.core.credentials import AzureKeyCredential from azure.ai.documentintelligence import DocumentIntelligenceClient from azure.ai.documentintelligence.models import AnalyzeDocumentRequest, ContentFormat, DocumentAnalysisFeature, AnalyzeResult from azure.core.exceptions import HttpResponseError from dotenv import find_dotenv, load_dotenv def analyze_documents_output_in_markdown_with_queryfields(): # [START analyze_documents_output_in_markdown_with_queryfields] endpoint = "DOCUMENTINTELLIGENCE_ENDPOINT" key = "API_KEY" url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/documentintelligence/azure-ai-documentintelligence/samples/sample_forms/forms/Invoice_1.pdf" document_intelligence_client = DocumentIntelligenceClient(endpoint=endpoint, credential=AzureKeyCredential(key)) # Analyze document with markdown output format and query fields poller = document_intelligence_client.begin_analyze_document( "prebuilt-layout", AnalyzeDocumentRequest(url_source=url), output_content_format=ContentFormat.MARKDOWN, features=[DocumentAnalysisFeature.QUERY_FIELDS], query_fields=["Address", "InvoiceNumber"], ) result: AnalyzeResult = poller.result() # Print the content in markdown format print(f"Markdown format:\n{result.content}") # Print detected query fields if result.documents: for doc in result.documents: if doc.fields and doc.fields["Address"]: print(f"Address: {doc.fields['Address'].value_string}") if doc.fields and doc.fields["InvoiceNumber"]: print(f"Invoice number: {doc.fields['InvoiceNumber'].value_string}") # [END analyze_documents_output_in_markdown_with_queryfields] if __name__ == "__main__": try: load_dotenv(find_dotenv()) analyze_documents_output_in_markdown_with_queryfields() except HttpResponseError as error: # Handle HttpResponseError print(f"An HTTP error occurred: {error}") except Exception as ex: # Handle any other errors print(f"An error occurred: {ex}") ```