我用来强调选择文本的代码。我开始调用addUnderline()方法,其他方法是辅助方法。
private pdftron.SDF.Obj CreateUnderlineAppearance(pdftron.PDF.Rect bbox)
{
ElementBuilder builder = new ElementBuilder();
ElementWriter writer = new ElementWriter();
builder.PathBegin();
builder.MoveTo(bbox.x1, bbox.y1);
builder.LineTo(bbox.x2, bbox.y1);
Element line = builder.PathEnd();
//Set color attributes for the line...
line.SetPathFill(false);
line.SetPathStroke(true);
GState gs = line.GetGState();
gs.SetStrokeColorSpace(ColorSpace.CreateDeviceRGB());
gs.SetStrokeColor(new ColorPt(0, 0, 0)); // black
gs.SetLineWidth(2);
writer.Begin(m_document);
writer.WriteElement(line);
pdftron.SDF.Obj stm = writer.End();
builder.Dispose();
writer.Dispose();
// Set the bounding box
stm.PutRect("BBox", bbox.x1, bbox.y1, bbox.x2, bbox.y2);
stm.PutName("Subtype", "Form");
return stm;
}
public Annot CreateUnderlineAnnot(pdftron.PDF.Rect rect)
{
Annot underlineAnnot = Annot.Create(m_document, Annot.Type.e_Underline, rect);
underlineAnnot.SetAppearance(CreateUnderlineAppearance(rect));
return underlineAnnot;
}
public void AddUnderline()
{
if (m_document != null)
{
PDFViewCtrl.Selection selection = m_pdfViewer.GetSelection();
int pageNumber = selection.GetPageNum();
double[] quads = selection.GetQuads();
int numQuads = quads.Length / 8;
if (quads.Length % 8 == 0) //must have at least 8 points to be valid
{
Console.WriteLine("GetRectsFromQuads - numQuads: " + numQuads.ToString());
for (int i = 0; i < numQuads; i++)
{
Rect selectionRect = GetSelectionRect(ref quads, i);
//Console.WriteLine("GetRectsFromQuads - aRect: " + rectX1.ToString() + " | " + rectY1.ToString() + " | " + rectX2.ToString() + " | " + rectY2.ToString());
Annot underlineAnnot = CreateUnderlineAnnot(selectionRect);
m_pdfViewer.AddUnderlineAnnotationToPage(underlineAnnot, pageNumber);
//m_pdfViewer.Refresh(); --> to see how this algorithm works when debugging
}
m_pdfViewer.RefreshAnnotations();
}
}
}
如果您仔细观察某些线条比其他线条更粗或更薄,您可以在图像中看到。这可以解决吗?顺便说一句,当我放大/缩小时,问题就消失了......
答案 0 :(得分:0)
您需要在pdf视图控件上设置以下内容:
Class: Data Structures | Number Of Students: 7
Students In Course One Capacity: 10
0 Peter Jones
1 Lisa Walker
2 Kevin Medara
3 Joe Sansone
4 Shari Bemis
5 Vishnu
6 Kieth Naeck
7 NEW STUDENT 1
_____________________________________
Class: Database Systems | Number Of Students: 6
Students In Course Two Capacity: 15
0 Jacob Fraser
1 Bob Walker
2 Kevin Medara
3 Joe Sansone
4 Shari Bemis
5 Melissa Johnson
6
______________________________________
Class: Data Structures | Number Of Students: 12
Students In Course Three Capacity: 20
0 Peter Jones
1 Lisa Walker
2 Kevin Medara
3 Joe Sansone
4 Shari Bemis
5 Vishnu
6 Kieth Naeck
7 NEW STUDENT 1
8 NEW STUDENT 2
9 NEW STUDENT 3
10 NEW STUDENT 4
11 NEW STUDENT 5
12
_____________________________________
Course One after dropping myself
Class: Data Structures | Number Of Students: 6
Students In Course One Capacity: 10
0 Peter Jones
1 Lisa Walker
2 Joe Sansone
3 Shari Bemis
4 Vishnu
5 Kieth Naeck
_____________________________________
Cleared Course One
Class: Data Structures | Number Of Students: 0
Students In Course One Capacity: 10
0
_____________________________________
Course 3 After Dropping Shari Bemis
Class: Data Structures | Number Of Students: 11
Students In Course Three Capacity: 20
0 Peter Jones
1 Lisa Walker
2 Kevin Medara
3 Joe Sansone
4 Vishnu
5 Kieth Naeck
6 NEW STUDENT 1
7 NEW STUDENT 2
8 NEW STUDENT 3
9 NEW STUDENT 4
10 NEW STUDENT 5
11
_____________________________________
这将删除行上的别名,并表示1.5px的所有行都是1px,依此类推。见这里:https://www.pdftron.com/pdfnet/mobile/docs/WinRT/html/M_pdftron_PDF_PDFViewCtrl_SetThinLineAdjustment.htm