I add on a GoView some GoTextNode that i want them to fit on each print page so what it is not cut into 2.
It depends on the printer selected, and you can get that info from PrintDocument PageSettings.
The code below shifts nodes to avoid page breaks, so I think the details here answer your question.
public void ShiftObjectsToAvoidPageSplits(GoView view) {
PrintDocument pd = new PrintDocument();
PageSettings ps = pd.DefaultPageSettings;
int paperw = ps.PaperSize.Width;
int paperh = ps.PaperSize.Height;
int pagew = paperw-ps.Margins.Left-ps.Margins.Right;
int pageh = paperh-ps.Margins.Top-ps.Margins.Bottom;
pd.Dispose();
float viewscale = view.PrintScale;
SizeF pagesize = new SizeF(pagew/viewscale, pageh/viewscale);
PointF origin = view.PrintDocumentTopLeft;
SizeF extent = view.PrintDocumentSize;
view.StartTransaction();
GoSelection sel = new GoSelection(null);
for (float x = origin.X+pagesize.Width; x < origin.X+extent.Width; x += pagesize.Width) {
float maxShift = 0;
foreach (GoObject obj in view.Document) {
if (obj is IGoLink) continue; // skip links, but include nodes and other objects
if (obj.Width >= pagesize.Width) continue; // skip really wide objects
if (obj.Left-1 <= x && x <= obj.Right+1) { // find split objects
maxShift = Math.Max(maxShift, x-obj.Left+1); // distance to move out
}
}
if (maxShift > 0) {
sel.Clear();
foreach (GoObject obj in view.Document) {
if (obj is IGoLink) continue;
if (obj.Width >= pagesize.Width) continue;
if (obj.Right > x) sel.Add(obj); // collect objects that need moving
}
view.MoveSelection(sel, new SizeF(maxShift+1, 0), false);
extent = view.PrintDocumentSize; // recalculate print size
}
}
for (float y = origin.Y+pagesize.Height; y < origin.Y+extent.Height; y += pagesize.Height) {
float maxShift = 0;
foreach (GoObject obj in view.Document) {
if (obj is IGoLink) continue; // skip links, but include nodes and other objects
if (obj.Height >= pagesize.Height) continue; // skip really tall objects
if (obj.Top-1 <= y && y <= obj.Bottom+1) { // find split objects
maxShift = Math.Max(maxShift, y-obj.Top+1); // distance to move out
}
}
if (maxShift > 0) {
sel.Clear();
foreach (GoObject obj in view.Document) {
if (obj is IGoLink) continue;
if (obj.Height >= pagesize.Height) continue;
if (obj.Bottom > y) sel.Add(obj); // collect objects that need moving
}
view.MoveSelection(sel, new SizeF(0, maxShift+1), false);
extent = view.PrintDocumentSize; // recalculate print size
}
}
view.FinishTransaction("shifted objects to avoid page splits");
}
I have tried the code and it’s not working, still i have split objects.
I have manage to fix the problem on landscape, but on portrait for some reason that i haven’t figure it out the PrintDocumentTopLeft is changing when i add a specific new object to the view
If you’re not using a Sheet (and it doesn’t look like you are) then <span =“Apple-style-span” style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; ">PrintDocumentTopLeft will be the topleft of ComputeDocumentBounds(). ComputeDocumentBounds “determines the actual extent of all of the objects in the document as seen by this view”.
So, if you are adding objects to the left (or above) of existing objects, <span =“Apple-style-span” style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; ">PrintDocumentTopLeft should be changing to encompass those new coordinates.
Have you tried more than one printer? It may be the settings on the printer don’t match reality (which may explain why it works in landscape and not portrait).
Yes i don’t use a Sheet.
If you just add a GoRectangle (or some other simple GoObject) do you see the same behavior? Or is it just this GoTextNode with wrapped text?
I tried with GoRectangle and it’s not changing the PrintDocumentTopLeft.
Can you send me your code? I’ll send you an email.