Skip to content

Instantly share code, notes, and snippets.

@bonus630
Last active December 2, 2022 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bonus630/b7a2815ef7573117b02fc57348e59b40 to your computer and use it in GitHub Desktop.
Save bonus630/b7a2815ef7573117b02fc57348e59b40 to your computer and use it in GitHub Desktop.
Fit content to page in CorelDraw
public void FitContentToPage(Page p,bool proportion = true, double margin = 0)
{
try
{
corelApp.Optimization = true;
ShapeRange sr = p.Shapes.All();
ShapeRange guides = p.FindShapes(Type: cdrShapeType.cdrGuidelineShape);
sr.RemoveRange(guides);
Rect bBox = p.BoundingBox;
double h = sr.SizeHeight;
double w = sr.SizeWidth;
if (!proportion || w == h)
sr.SetSize(bBox.Width - 2 * margin, bBox.Height - 2 * margin);
else
{
if (w / h > bBox.Width / bBox.Height)
{
sr.SizeWidth = bBox.Width - 2 * margin;
sr.SizeHeight *= sr.SizeWidth / w ;
}
else
{
sr.SizeHeight = bBox.Height - 2 * margin;
sr.SizeWidth *= sr.SizeHeight / h;
}
}
sr.CenterX = p.CenterX;
sr.CenterY = p.CenterY;
}
catch { }
finally
{
corelApp.Optimization = false;
corelApp.Refresh();
}
}
public void FitContentInPages(bool proportion = true, double margin = 0)
{
Pages ps = corelApp.ActiveDocument.Pages;
for (int i = 1; i <= ps.Count; i++)
{
FitContentToPage(ps[i],proportion,margin);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment