我试图让用户在pdf中创建一个矩形。用户可以在屏幕上拖动一个矩形。
在mouseup事件上,创建一个Rect对象并传递给方法AddRectAnnotationToPage(Rectangle rect)
问题是矩形注释与用户拖动的矩形不同。当用户点击或滚动时,注释矩形会获得正确的大小(等于作为参数传递的拖动矩形)
为什么不立即采取正确的尺寸?为什么每当我点击pdf中的随机点时它会调整到正确的大小?
private void AddRectAnnotationToPage(Rectangle rect)
{
if (rect != null)
{
if (this.m_pageNumber < 0)
{
m_pageNumber = this.GetCurrentPage();
}
_cur_page = this.m_pageNumber;
if (_cur_page < 0)
{
return;
}
double width = rect.Width;
double height = rect.Height;
double startX = rect.Left;
double startY = rect.Bottom;
double endX = rect.Right;
double endY = rect.Top;
double X1 = startX;
double Y1 = startY;
double X2 = endX;
double Y2 = endY;
ConvScreenPtToPagePt(ref X1, ref Y1, this.GetCurrentPage());
ConvScreenPtToPagePt(ref X2, ref Y2, this.GetCurrentPage());
Rect pos = new Rect(X1,Y1,X2,X2);
Polygon poly = pdftron.PDF.Annots.Polygon.Create(m_PdfDocument.GetSDFDoc(), pos);
pdftron.PDF.Point p = new pdftron.PDF.Point();
p.x = X1; p.y = Y1;
poly.SetVertex (0, p);
p.x = X1; p.y = Y2;
poly.SetVertex (1, p);
p.x = X2; p.y = Y2;
poly.SetVertex (2, p);
p.x = X2; p.y = Y1;
poly.SetVertex (3, p);
PDFDoc doc = GetDoc();
doc.Lock();
pdftron.PDF.Page pag = doc.GetPage(_cur_page);
Obj annots = pag.GetAnnots();
if (annots == null)
{
// If there are no annotations, create a new annotation
// array for the page.
annots = m_PdfDocument.CreateIndirectArray();
pag.GetSDFObj().Put("Annots", annots);
}
pag.AnnotPushBack(poly);
doc.Unlock();
}
}
答案 0 :(得分:0)
通过在设置顶点
后调用Refreshappearance()来修复