VDF常見問題整理(三十三):如何在特殊情況下將圖形居中放置在紙上?
VectorDraw Developer Framework(VDF)是一個(gè)用于應(yīng)用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw Developer Framework試用版下載
問:
如何在不損失軟件邊距的情況下將繪圖集中在紙張上。CenterDrawingToPaper方法將所有軟件邊距設(shè)置為0并重新計(jì)算,這個(gè)原因?qū)е挛覠o法使用它。
答:
您需要像以前一樣設(shè)置邊距,然后排列PrintWindow和/或PrintScale。
具體的請(qǐng)參見以下代碼:
doc.New(); vdLayout layout = doc.LayOuts.Add("test"); doc.ActiveLayOut = layout; layout.Entities.AddItem(new vdRect(doc, new gPoint(-100, 0), 150, 150, 0)); layout.Printer.margins = new MARGINS(50, 50, 50, 50); layout.Printer.paperSize = new Rectangle(0, 0, 827, 1169); layout.Printer.PrintScale = new PrinterScale(1, 1); layout.Printer.PrinterName = "c:\\test.pdf"; layout.Printer.PrintWindow = new Box(new gPoint(-100, 0), new gPoint(-100 + 150, 150)); doc.ZoomAll(); doc.Redraw(true); doc.Prompt("press any key to continue"); doc.ActionUtility.getUserString(); doc.Prompt(null);// just to create something on screen //get a clone of selected printer window in Drawing Units Box printwindowDU =new Box( layout.Printer.PrintWindow); gPoint mid = printwindowDU.MidPoint; //calculate the printable paper area in drawing Units relative to the Layout // convert printer hinches to drawing units depend of printer scale double PrinterHInch2DUScale = (Globals.INCH_MM / 100.0f) * (layout.Printer.PrintScale.Denumerator / layout.Printer.PrintScale.Numerator); //Get the rectanle in Drawing Units of Current View for the selected printer paper without the hard Margins. Box printableAreaDU = layout.Printer.PrintablePaperDU(); //Subtract from the paper the the selected soft margins double printableAreaDU_Width = printableAreaDU.Width - (layout.Printer.margins.Left + layout.Printer.margins.Right) * PrinterHInch2DUScale; double printableAreaDU_Height = printableAreaDU.Height - (layout.Printer.margins.Top + layout.Printer.margins.Bottom) * PrinterHInch2DUScale; //Center the printWindow to the paper. //Calculate the new printer PrintWindow to be center to paper area by keeping its center and change the width and height to be equal to printable area. Box newPrintWindow = new Box(mid + new gPoint(-printableAreaDU_Width*0.5,-printableAreaDU_Height*0.5),mid + new gPoint(printableAreaDU_Width*0.5,printableAreaDU_Height*0.5)); layout.Printer.PrintWindow = newPrintWindow; layout.Printer.Update(); doc.Redraw(true);
對(duì)于以上問答,如果您有任何的疑惑都可以在評(píng)論區(qū)留言,我們會(huì)及時(shí)回復(fù)。此系列的問答教程我們會(huì)持續(xù)更新,如果您感興趣,可以多多關(guān)注本教程。
熱門文章推薦:
如果您對(duì)想要購買正版授權(quán)VectorDraw Developer Framework(VDF),可以聯(lián)系在線客服>>咨詢相關(guān)問題。
關(guān)注慧聚IT微信公眾號(hào) ???,了解產(chǎn)品的最新動(dòng)態(tài)及最新資訊。