使用 pdfnet 下划线会导致不同的线条粗细 [英] Underlining with pdfnet results in different line thickness

查看:81
本文介绍了使用 pdfnet 下划线会导致不同的线条粗细的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用于为所选文本加下划线的代码.我开始调用 addUnderline() 方法,其他方法是辅助方法.

The code that i use for underlining a selection of text. I begin calling the addUnderline() method, the other methods are helper methods.

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();
                }
            }
        }

如果您仔细观察,您会在图像中看到某些线条比其他线条更粗或更细.这是可以修复的吗?顺便说一句,当我放大/缩小时,问题就消失了......

You can see in the image if you look closely that some lines are thicker or thinner than others. Is this fixable? by the way, when i zoom in/out the problem is gone...

推荐答案

您需要在 pdf 视图控件上设置以下内容:

You need to set the following on your pdf view control:

PDFViewCtrl.SetThinLineAdjustment(true, true);

这将消除线条上的锯齿,意味着所有 1.5px 的线条都是 1px,依此类推.请参阅此处:https://www.pdftron.com/pdfnet/mobile/docs/WinRT/html/M_pdftron_PDF_PDFViewCtrl_SetThinLineAdjustment.htm

That will remove the aliasing on the lines, and mean all lines that are 1.5px are 1px, and so on. See here: https://www.pdftron.com/pdfnet/mobile/docs/WinRT/html/M_pdftron_PDF_PDFViewCtrl_SetThinLineAdjustment.htm

这篇关于使用 pdfnet 下划线会导致不同的线条粗细的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆