CDT Automation & Scripting 3 — Questions and Answers
Question 1: A Python script uses PyPDF2 to merge documents but the output PDF has scrambled fonts. What is the MOST likely cause?
- The script ran with insufficient memory
- Source PDFs use embedded subsets that are not properly reconciled during merge (Correct answer)
- The output filename contains a space character
- PyPDF2 does not support portrait orientation
Correct answer: Source PDFs use embedded subsets that are not properly reconciled during merge
When PDFs with subsetted (partially embedded) fonts are merged, font resource name conflicts can cause glyphs to map incorrectly in the combined file.
Question 2: Which PowerShell cmdlet would you use to iterate over all DOCX files in a directory and its subdirectories for automated processing?
- Get-Item *.docx
- Get-ChildItem -Path . -Filter *.docx -Recurse (Correct answer)
- Select-Object -Filter docx
- Invoke-Expression dir *.docx
Correct answer: Get-ChildItem -Path . -Filter *.docx -Recurse
Get-ChildItem with -Recurse traverses all subdirectories and -Filter restricts results to files matching the wildcard pattern.
Question 3: A document automation script must insert a watermark only on pages that contain the phrase 'CONFIDENTIAL'. What technique enables this conditional logic?
- Applying the watermark to all pages then removing it randomly
- Parsing each page's text layer, checking for the phrase, then conditionally stamping only matching pages (Correct answer)
- Scanning the document thumbnail images for the word
- Splitting every document into single pages before any processing
Correct answer: Parsing each page's text layer, checking for the phrase, then conditionally stamping only matching pages
Extracting the text layer per page and testing it with a string search or regex allows the script to selectively apply the watermark only where appropriate.
Question 4: When scheduling automated document processing jobs on a Linux server, which tool is most commonly used to define time-based execution?
- init.d service
- cron (crontab) (Correct answer)
- systemd target
- inotifywait daemon
Correct answer: cron (crontab)
cron is the standard Linux scheduler; crontab entries define the schedule (minute/hour/day/month/weekday) and the command to run.
Question 5: A script that automates form filling must handle a PDF where some fields are read-only. What should the script do when it encounters a read-only field?
- Delete the field and recreate it as editable
- Skip the field or log it as a warning without attempting to write to it (Correct answer)
- Force-write the value using raw byte patching
- Flatten the entire PDF to remove all field restrictions
Correct answer: Skip the field or log it as a warning without attempting to write to it
Attempting to write to a read-only field will fail or corrupt the document; the script should detect the read-only flag and log a warning instead.
Question 6: In document workflow automation, what is a 'dead letter queue'?
- A folder that stores successfully processed documents for archival
- A holding area where messages or documents are placed when processing fails repeatedly and cannot be retried automatically (Correct answer)
- A queue that processes documents in reverse chronological order
- A log file containing completed script execution records
Correct answer: A holding area where messages or documents are placed when processing fails repeatedly and cannot be retried automatically
A dead letter queue captures documents that have exhausted retry attempts so they can be inspected and reprocessed manually without blocking the main workflow.
Question 7: Which approach provides the MOST reliable way to detect whether an automated document conversion succeeded without opening the output file?
- Check that the output file size is greater than zero bytes
- Validate the output file's structure (e.g., PDF header, page count) and compare against expected values (Correct answer)
- Confirm the conversion process exited without an error code
- Check that the output filename matches the input filename
Correct answer: Validate the output file's structure (e.g., PDF header, page count) and compare against expected values
Structural validation (checking the PDF header, page count, and key metadata) catches corrupt or truncated outputs that a simple file-size or exit-code check would miss.
A Python script uses PyPDF2 to merge documents but the output PDF has scrambled fonts.
What is the MOST likely cause?