【问题标题】:How do you change the icon size of a PDF sticky note placed via iTextSharp?如何更改通过 iTextSharp 放置的 PDF 便签的图标大小?
【发布时间】:2017-04-07 14:03:36
【问题描述】:

我正在尝试放大 PDF 便签的图标。这是一张显示我在 PDF 第一页上标记的粘性图标的图像:

我的印象是图标是由一个可以操作的矩形引导的。这是我尚未生效的代码:

using (PdfStamper stamp = new PdfStamper(reader, fs))
{
    PdfWriter attachment = stamp.Writer;
    foreach (string file in files_to_attach)
    {
        PdfFileSpecification pdfAttch = PdfFileSpecification.FileEmbedded(attachment, file, file, null);
        stamp.AddFileAttachment(file, pdfAttch);
    }

    //Create Note for first page
    Rectangle rect = new Rectangle(850, 850, 650, 650);
    PdfAnnotation annotation = PdfAnnotation.CreateText(stamp.Writer, rect, "TITLE OF NOTE", "Body text of the note", false, "Comment");

    //Enlarge the Sticky Note icon
    PdfDictionary page = reader.GetPageN(1);
    PdfArray annots = page.GetAsArray(PdfName.ANNOTS);
    PdfDictionary sticky = annots.GetAsDict(0);
    PdfArray stickyRect = sticky.GetAsArray(PdfName.RECT);
    PdfRectangle stickyRectangle = new PdfRectangle(
        stickyRect.GetAsNumber(0).FloatValue - 50, stickyRect.GetAsNumber(1).FloatValue - 20,
        stickyRect.GetAsNumber(2).FloatValue, stickyRect.GetAsNumber(3).FloatValue - 30);
    sticky.Put(PdfName.RECT, stickyRectangle);

    //Apply the Note to the first page
    stamp.AddAnnotation(annotation, 1);

    stamp.Close();
}

我认为我可以更改浮点值,这会改变图标的​​形状,但到目前为止还没有影响到这一切。感谢您的任何建议。

【问题讨论】:

    标签: c# pdf itext pdfstamper pdf-annotations


    【解决方案1】:

    你不能。为“评论”注释显示的图标由查看器提供。 rect 属性仅用于定义查看器在页面上放置图标的左下角。根据“文本”类型注释的 PDF 规范,“符合标准的阅读器应为至少以下标准名称提供预定义的图标外观:注释、键、注释、帮助、新段落、段落、插入。

    但是,您可以创建自己的任意大小的图像,并将其用作“图章”注释的外观。它甚至可以看起来完全像一个“评论”图标,只是更大。它最终会以相同的方式为最终用户运行。

    【讨论】:

    • 因此,为了使其“以与最终用户相同的方式发挥作用”,它仍需要表示为注释,对吧?如: PdfAnnotation annotation = PdfAnnotation.CreateText(stamp.Writer, rect, "TITLE OF NOTE", "Body text of note", false, "Comment");但不是“评论”,而是我会传递一张图片。 "Comment" 是字符串,什么语法可以让图片变成字符串?
    • 参见 Bruno 的 AddStamp 示例。它是 Java,但你会明白的。 developers.itextpdf.com/examples/actions-and-annotations/…
    猜你喜欢
    • 2012-10-14
    • 2014-09-01
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多