Replies: 1 comment
-
I added an example how to render to a specific scale. This example does not support margins. The following code is just an excerpt: def save_to_scale(
size_in_inches: tuple[float, float] = (8.5, 11),
origin: tuple[float, float] = (0, 0), # of modelspace area to render
scale: float = 1,
dpi: int = 300,
):
doc = make_doc(offset=(1, 2), size=(6.5, 8))
msp = doc.modelspace()
...
ctx = RenderContext(doc)
fig = plt.figure(dpi=dpi)
ax = fig.add_axes([0, 0, 1, 1])
# Get render limits in drawing units:
min_x, min_y, max_x, max_y = render_limits(
origin, size_in_inches, scale
)
ax.set_xlim(min_x, max_x)
ax.set_ylim(min_y, max_y)
out = MatplotlibBackend(ax)
# Finalizing invokes auto-scaling by default!
Frontend(ctx, out).draw_layout(msp, finalize=False)
# Set output size in inches:
fig.set_size_inches(size_in_inches[0], size_in_inches[1], forward=True)
fig.savefig(DIR / f"image_scale_1_{scale}.pdf", dpi=dpi)
plt.close(fig) Define the render limits in inches: def render_limits(
origin: tuple[float, float],
size_in_inches: tuple[float, float],
scale: float,
) -> tuple[float, float, float, float]:
"""Returns the render limits in drawing units. """
min_x, min_y = origin
max_x = min_x + size_in_inches[0] * scale
max_y = min_y + size_in_inches[1] * scale
return min_x, min_y, max_x, max_y For drawings in other base units a conversion is required e.g. mm to inch: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
my program generates a DXF file of a guitar neck, I would like to print it to a PDF file at 1:1 scale.
But I just get a scaled version of my drawing to a random proportion I can't figure out.
Can somebody provide a suggestion?
Thanks
This is the code i use
Beta Was this translation helpful? Give feedback.
All reactions