公共字符代码{得到;集;}
公共字符getCode ();
公共无效setCode (
字符charValue
);
一个系统。包含UNICODE字符的字符代码PDFObject文本条目。默认值是0。
的代码属性只适用于文本项,即:,当时的价值ObjectType是PDFObjectType.Text。文本属性,如字体和颜色信息将存储在TextProperties这个对象的属性。
空白字符,比如空格或制表符默认解析并返回单个对象。你可以停止这种行为或操作PDFParsePagesOptions.IgnoreWhiteSpaces枚举成员PDFParsePagesOptions.Objects在选项参数传递给PDFDocument.ParsePages。注意:来重构中的单词和行文本页面没有使用白色字符PDFTextProperties.IsEndOfWord和PDFTextProperties.IsEndOfLine属性。的PDFTextProperties示例演示了这一点。
注意:目前,LEADTOOLS不支持从PDF文件中提取真正的UNICODE字符。只有ASCII字符读取,然后转换为UNICODE。
使用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 obj在page.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))
{
/ /可以嵌入字体,使用Arial
faceName =“天线”;
}
使用(字体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 \图片”;
}
帮助收藏
光栅net|C API|c++类库|HTML5 JavaScript
文档net|C API|c++类库|HTML5 JavaScript
医疗net|C API|c++类库|HTML5 JavaScript
医疗Web查看器net
188宝金博怎么下载
支持的平台上
net, Java, Android和iOS / macOS组件
C / c++类库的API
HTML5 JavaScript库
你的邮件已经发送到支持!有人应该联系!如果你的问题是紧急请回到聊天。
聊天时间:
周一——周五,上午6点等
谢谢你的反馈!
请填写表单重新开始一个新的聊天。
所有代理目前离线。
聊天时间:
周一-周五
早上8:30 - 6点
联系我们请填写这张表格,我们将通过电子邮件联系你。