←选择平台

代码属性

总结
字符代码的价值PDFObject文本条目。
语法
c#
c++ / CLI
Java
公共字符代码{得到;;}
公共字符getCode ();公共无效setCode (字符charValue);
公共:财产字符代码{字符get ();无效集(字符);}

属性值

一个系统。包含UNICODE字符的字符代码PDFObject文本条目。默认值是0。

讲话

代码属性只适用于文本项,即:,当时的价值ObjectTypePDFObjectType.Text。文本属性,如字体和颜色信息将存储在TextProperties这个对象的属性。

空白字符,比如空格或制表符默认解析并返回单个对象。你可以停止这种行为或操作PDFParsePagesOptions.IgnoreWhiteSpaces枚举成员PDFParsePagesOptions.Objects选项参数传递给PDFDocument.ParsePages注意:来重构中的单词和行文本页面没有使用白色字符PDFTextProperties.IsEndOfWordPDFTextProperties.IsEndOfLine属性。的PDFTextProperties示例演示了这一点。

注意:目前,LEADTOOLS不支持从PDF文件中提取真正的UNICODE字符。只有ASCII字符读取,然后转换为UNICODE。

例子
c#
使用Leadtools;使用Leadtools.Codecs;使用Leadtools.Pdf;使用Leadtools.WinForms;使用Leadtools.Drawing;公共无效PDFObjectExample (){字符串pdfFileName = Path.Combine (LEAD_VARS.ImagesDir,@“Leadtools.pdf”);字符串pngFileName = Path.Combine (LEAD_VARS.ImagesDir,@“LEAD_png.png”);/ /创建一个PDF文档,文件在200 DPI使用(PDFDocument文档=PDFDocument (pdfFileName)){文档。分辨率= 200;/ /解析对象的第一页document.ParseDocumentStructure (PDFParseDocumentStructureOptions.Fonts);document.ParsePages (PDFParsePagesOptions。字体| PDFParsePagesOptions。对象,1,1);/ /获取页面PDFDocumentPage页面= document.Pages [0];/ /获取页面的图像我们可以使用它来得到源图像对象使用(RasterImage pageImage = document.GetPageImage (,page.PageNumber)){/ /创建位图绘制的对象使用(位图btmp =位图(页面。WidthPixels, page.HeightPixels)){btmp.SetResolution(文档。分辨率,document.Resolution);使用(图形g = Graphics.FromImage (btmp)){g.Clear (Color.White);/ /渲染对象/ /文本行LeadRect textRect = LeadRect.Empty;textFontHeight = 0;StringBuilder textLine =StringBuilder ();foreach(PDFObject objpage.Objects){开关(obj.ObjectType){情况下PDFObjectType.Image:RenderImage (g, pageImage,页面,obj);打破;情况下PDFObjectType.Text:/ /添加文本代码和矩形textLine.Append (obj.Code);PDFRect rc = page.ConvertRect (PDFCoordinateType。Pdf、PDFCoordinateType。像素,obj.Bounds);LeadRect objRect = LeadRect.FromLTRB ((intrc。离开,(intrc。,(intrc。对的,(int)rc.Bottom);如果(textRect.IsEmpty){textRect = objRect;}其他的{textRect = LeadRect。联盟(textRect objRect);}textFontHeight =数学。马克斯(textFontHeight obj.TextProperties.FontHeight);/ /如果这是在一行的最后一个对象,呈现它如果(obj.TextProperties.IsEndOfLine){RenderText (g,文档,页面,textLine.ToString (), textRect, obj。TextProperties textFontHeight);textLine =StringBuilder ();textRect = LeadRect.Empty;}打破;}}}btmp。保存(pngFileName System.Drawing.Imaging.ImageFormat.Png);}}}}私人静态无效RenderImage(图形g, RasterImage pageImage, PDFDocumentPage页面,PDFObject obj){LeadRect destRect =LeadRect(0, 0,页面。WidthPixels page.HeightPixels);/ /得到对象像素坐标PDFRect rc = page.ConvertRect (PDFCoordinateType。Pdf、PDFCoordinateType。像素,obj.Bounds);LeadRect destClipRect = LeadRect.FromLTRB ((intrc。离开,(intrc。,(intrc。对的,(int)rc.Bottom);/ /画图形页面图像到目的地RasterPaintProperties道具= RasterPaintProperties.Default;道具。PaintEngine = RasterPaintEngine.GdiPlus;RasterImagePainter.Paint (pageImage,克,LeadRect.Empty,LeadRect.Empty,destRect,destClipRect,道具);}私人静态无效RenderText(图形g, PDFDocument文档,PDFDocumentPage页面,字符串文本,LeadRect textRect, PDFTextProperties textProperties,textFontHeight){/ /创建字体/ /字体集合中找到它字符串faceName =;如果(文档。字体! =& & textProperties。FontIndex < document.Fonts.Count){PDFFont字体= document.Fonts [textProperties.FontIndex];faceName = font.FaceName;}如果(字符串.IsNullOrEmpty (faceName)){/ /可以嵌入字体,使用ArialfaceName =“天线”;}使用(字体f =字体(faceName, (浮动)textFontHeight * 72 / g.DpiY)){使用(刷子刷=SolidBrush (RasterColorConverter.ToColor (textProperties.Color))){矩形矩形=矩形(textRect。X, textRect。Y, textRect。宽度,textRect.Height);使用(StringFormat科幻=StringFormat ()){科幻小说。对齐= StringAlignment.Center;科幻小说。LineAlignment = StringAlignment.Center;科幻小说。FormatFlags | = StringFormatFlags。NoClip | StringFormatFlags.NoWrap;g。拉带(文本、f,刷,矩形,科幻小说);}}}}静态LEAD_VARS{公共常量字符串ImagesDir =@“C: \ LEADTOOLS22 \ Resources \图片”;}
需求

目标平台

另请参阅

参考

PDFObject结构

PDFObject成员

Leadtools。Pdf组装
188金宝搏的网址客服|支持|联系我们|知识产权的通知
©1991 - 2023领先的技术公司。保留所有权利。