ststeiger / PdfSharpCore

Port of the PdfSharp library to .NET Core - largely removed GDI+ (only missing GetFontData - which can be replaced with freetype2)
Other
1.08k stars 237 forks source link

How to get Chinese Annotations?Help Help!! #320

Open 1031918012 opened 1 year ago

1031918012 commented 1 year ago

企业微信截图_16722212804536

PdfPage page = document.AddPage(); PdfTextAnnotation textAnnot = new PdfTextAnnotation { Title = "标题乱码", Subject = "22222", Contents = "11111.\r11111.123", Opacity = 0.5, Open = true, Icon = PdfTextAnnotationIcon.NoIcon,

};

XGraphics gfx = XGraphics.FromPdfPage(page);

XFont font = new XFont("KaiTi", 14, XFontStyle.Bold);

gfx.DrawString("这是我要写的一句话", font, XBrushes.Black, 30, 50, XStringFormats.BottomLeft);

// Convert rectangle from world space to page space. This is necessary because the annotation is // placed relative to the bottom left corner of the page with units measured in point. XRect rect = gfx.Transformer.WorldToDefaultPage(new XRect(30, 30, 30, 30)); textAnnot.Rectangle = new PdfRectangle(rect);

page.Annotations.Add(textAnnot);