Agents In Use
What’s new todayLast update
160 use cases added today

How to use Claude to add graphics to DOCX files

Claude added and visually checked DOCX graphics, but human code review exposed a slowdown. Benchmarking and template reuse reduced the reported generation time from about 2.2 to 1.2 seconds.

Source published news.ycombinator.comAgent: Claude
FROM THE SOURCE

Original prompt

Shared by the source author. See source notes for context.

look, we are using a template to avoid regenerating boilerplate with every page. you can add a placeholder to the template and replace it with graphics using xml patching code you already wrote for another part of the doc generation

Evidence at a glance

Sourced account
Source poster / publisher
zem
Original account
Read the source ↗
Published
Source link checked
Reported result
The author reports correctly aligned graphics and a cleaner implementation generating roughly 400 pages in about 1.2 seconds, compared with about 2.2 seconds after the initial addition.
Human involvement
The author inspected the generated commit, requested performance measurements, and explicitly directed reuse of templates and existing XML patching.

A linked account supports attribution. It does not mean we independently reproduced its result.

Report an issue with this caseOpen correction email

Opens your email app with the case link included. Nothing is sent automatically.

How the agent did it

  1. The author asked Claude to add graphics to generated DOCX documents.
  2. Claude inserted XML graphics and checked their alignment through PDF output.
  3. The author requested benchmarks, and Claude identified and fixed a quadratic loop.

The author asked Claude to add graphics to a project that generates large, repetitive DOCX documents. Claude worked out the XML graphics elements, identified insertion points in the document structure, and printed the result to PDF for visual alignment checks. The author says this initial work took about five minutes.

Reviewing the generated code prompted a performance question: the author suspected excessive work inside an inner loop and asked Claude to benchmark it. Adding graphics had increased generation time for roughly 400 pages from about one second to about 2.2 seconds. Claude identified and fixed an accidentally quadratic loop without further prompting.

The author then supplied architectural direction: reuse the existing template approach by adding a placeholder and replacing it through XML patching code already present elsewhere in the project. The final implementation was cleaner and ran in approximately 1.2 seconds. Claude performed finer-grained benchmarking, which the author says attributed the remaining overhead to inserting the XML. The post emphasizes that reviewing one commit made the problem easier to spot.

Who it's for: Developers adding repeated document elements may benefit from combining visual checks with code review and performance measurements.

Prompt
Original prompt

Source: Hacker News · zem

Frequently asked questions

How did Claude check the graphics placement?

The author says Claude printed the document to PDF and checked it visually to align the graphics with the text.

What human intervention improved the implementation?

The author requested benchmarks after inspecting the inner loop, then directed Claude to reuse the document template with a placeholder and existing XML patching code.

More details

Remaining steps

  1. The author directed template reuse, and Claude implemented and benchmarked the cleaner version.

About this account

Claude implemented graphics, checked alignment, diagnosed a loop, and benchmarked changes, with human architectural direction.

Platform: Hacker News. Attribution: https://news.ycombinator.com/item?id=48522457. Prompt: Original (quoted from source). Sourced by the Agents In Use pipeline.

Credit: zem on Hacker News

Source published

Added to Agents In Use

Source checked

Tools and topics

Claude · DOCX XML · PDF export · Benchmarking

DOCX · Performance · Code review

Editorial completeness: 100/100. Measures documented fields, not agent performance or verified outcomes.