Created
April 15, 2016 08:00
-
-
Save Polaringu/bee53d4857332d010aef677741e8bf79 to your computer and use it in GitHub Desktop.
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 class DrawPagesCallback : PDFXEdit.IPXV_PagesViewDrawCallback | |
{ | |
public PDFXEdit.IAUX_Inst m_aInst; | |
public PDFXEdit.IUIX_Inst m_uiInst; | |
private PDFXEdit.IColor m_clrFill; | |
private PDFXEdit.IColor m_clrBorder; | |
private PDFXEdit.PXC_Rect m_rcDraw; | |
PDFXEdit.IUIX_Brush m_Brush; | |
PDFXEdit.IUIX_Pen m_Pen; | |
public DrawPagesCallback(PDFXEdit.IAUX_Inst aInst, PDFXEdit.IUIX_Inst uiInst) | |
{ | |
m_aInst = aInst; | |
m_uiInst = uiInst; | |
m_clrFill = m_aInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB); | |
m_clrFill.SetRGB(0.0f, 1.0f, 1.0f); | |
m_clrBorder = m_aInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB); | |
m_clrBorder.SetRGB(0.0f, 1.0f, 0.0f); | |
m_rcDraw.left = 0; | |
m_rcDraw.right = 100; | |
m_rcDraw.top = 100; | |
m_rcDraw.bottom = 0; | |
m_Brush = m_uiInst.CreateNewBrush(); | |
m_Pen = m_uiInst.CreateNewPen(); | |
m_Brush.Color0 = m_clrFill.RGB; | |
m_Brush.Color1 = m_clrFill.RGB; | |
m_Pen.Brush.Color0 = m_clrBorder.RGB; | |
m_Pen.Brush.Color1 = m_clrBorder.RGB; | |
m_Pen.Width = 10; | |
m_Pen.Inside = true; | |
} | |
public void OnDrawPagesView(PDFXEdit.IPXV_PagesView pView, PDFXEdit.PXV_PagesViewDrawStage nStage, PDFXEdit.IUIX_RenderContext pRC, PDFXEdit.IPXV_PagesLayoutRegions pPageRegions) | |
{ | |
if (pView == null) | |
return; | |
//Drawing rectangle on the foreground | |
if (nStage == PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground) | |
{ | |
DrawRectangle(pView, pRC, 0); | |
} | |
} | |
public void DrawRectangle(PDFXEdit.IPXV_PagesView pView, PDFXEdit.IUIX_RenderContext pRC_, uint nPage) | |
{ | |
PDFXEdit.IPXV_PagesLayoutManager plm = pView.Layout; | |
if (plm == null) | |
return; | |
PDFXEdit.PXC_Matrix p2v = plm.GetPageToDeviceMatrix(nPage, true); | |
PDFXEdit.PXC_Rect rc = m_rcDraw; | |
m_aInst.MathHelper.Matrix_TransformRect(ref p2v, ref rc); | |
//Flipping rectangle top and bottom coordinates and converting it's type | |
PDFXEdit.tagRECT rcDR; | |
rcDR.left = (int)rc.left; | |
rcDR.right = (int)rc.right; | |
rcDR.top = (int)rc.bottom; | |
rcDR.bottom = (int)rc.top; | |
pRC_.DrawRect(rcDR, m_Brush, m_Pen, ref rcDR, 1); | |
} | |
} | |
DrawPagesCallback m_DPClbk = null; | |
private void drawRectangleOnPageToolStripMenuItem_Click(object sender, EventArgs e) | |
{ | |
if (m_DPClbk == null) | |
{ | |
m_DPClbk = new DrawPagesCallback(auxInst, uiInst); | |
//Registering callback at the needed document's pages view | |
pdfCtl.Doc.ActiveView.PagesView.RegisterDrawCallback(PDFXEdit.PXV_PagesViewDrawStage.PXV_PagesViewDraw_Foreground, m_DPClbk); | |
//!!! Do not forget to unregister it when document closes !!! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment