Skip to content

编辑文本和图像属性

ComPDFKit 支持修改文本与图像属性。您可以使用CPDFViewerPDFEditActiveHandler事件来设置文本和图像属性。

编辑文本属性

ComPDFKit 支持修改文本属性,如字体大小、名称、颜色、对齐方式、斜体、粗体、透明度等。

以下是如何将文本设置为12pt、红色和粗体的示例代码:

C#
viewer.PDFEditActiveHandler += Viewer_PDFEditActiveHandler;
private void Viewer_PDFEditActiveHandler(object sender, PDFEditEvent e)
{
    // 文本属性。
    if (e.EditType == CPDFEditType.EditText)
    {
        e.FontColor = Colors.Red;
        e.FontSize = 12;
        e.TextAlign = TextAlignType.AlignJustify;
        e.FontWeight = FontWeights.Bold;
        e.FontStyle = FontStyles.Italic;
        e.FontFamily = new FontFamily("TimesNewRoman");
        e.Transparency = 255;
        e.UpdatePDFEditByEventArgs();
    }
}

编辑图像属性

ComPDFKit 支持修改图像属性,如旋转、裁剪、镜像和设置透明度。

以下是如何旋转图像并将其设置为半透明的示例代码:

C#
viewer.PDFEditActiveHandler += Viewer_PDFEditActiveHandler;
private void Viewer_PDFEditActiveHandler(object sender, PDFEditEvent e)
{
    //图片属性。
    if (e.EditType == CPDFEditType.EditImage)
    {
        e.VerticalMirror = true;
        e.HorizontalMirror = true;
        e.ClipImage = true;
        e.Rotate = 90;
        e.ReplaceImagePath = "***";
        e.Transparency = 255;
        e.UpdatePDFEditByEventArgs();
    }
}