Last active
December 2, 2022 03:17
-
-
Save bonus630/b7a2815ef7573117b02fc57348e59b40 to your computer and use it in GitHub Desktop.
Fit content to page in CorelDraw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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