Can we skip the first couple of pages while translating a document using Azure Translator?

Amulya Sharma 20 Reputation points
2025-01-16T05:08:59.4066667+00:00

So i am working with some files that have some addresses in the first 2 pages, and I do not wish for them to be translated. Is it possible to skip the first two pages when translating the PDFs using Azure translator API?

Azure Translator
Azure Translator
An Azure service to easily conduct machine translation with a simple REST API call.
436 questions
0 comments No comments
{count} votes

Accepted answer
  1. Saideep Anchuri 1,285 Reputation points Microsoft Vendor
    2025-01-16T06:06:39.9166667+00:00

    Hi Amulya Sharma

    Welcome to Microsoft Q&A Forum, thank you for posting your query here!

    The Azure Document Translator API does not currently support skipping specific pages during translation. The API translates entire documents without the ability to exclude particular sections or page 1 and takes a blob URL for source and destination. 

    However, you can manually remove or exclude the addresses from the first two pages before submitting the document for translation. This way, you can ensure that only the desired content is translated.

    Here is an example to read a pdf file and save content from page 2 onwards only.

     from PyPDF2 import PdfFileReader, PdfFileWriter
    
     
    input_file = 'example.pdf'
    output_file = 'example-updated.pdf'
     
    # Create a PdfFileReader object
    reader = PdfFileReader(input_file)
     
    # Create a PdfFileWriter object
    writer = PdfFileWriter()
     
    # Loop through the pages and add pages starting from the third page
    for page_num in range(2, reader.getNumPages()):
        writer.addPage(reader.getPage(page_num))
     
    # Write the output PDF
    with open(output_file, 'wb') as output_pdf:
        writer.write(output_pdf)
     
    print(f"Output PDF '{output_file}' created with pages starting from the third page.")
    
    
    

    Output pdfs can be uploaded to blob storage for document translation using AZ copy command from local directory.upload-a-file

    Kindly refer below documentation: document-translation-sdk

    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful.

    Thank You.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.