←选择平台

LoadFromFile方法

总结
创建一个SvgDocument对象从一个SVG文件在磁盘上。
语法
c#
VB
objective - c
c++
Java
公共静态SvgDocumentLoadFromFile (字符串文件名,SvgLoadOptions选项)
公共共享函数LoadFromFile (_按值传递文件名作为字符串,_按值传递选项作为SvgLoadOptions_)作为SvgDocument
(可空instancetype) initWithFile:(NSString *)文件选择:(nullable LTSvgLoadOptions *)选项错误:错误(NSError * *)
公共静态SvgDocument loadFromFile(字符串文件名,SvgLoadOptions选项)
公共:静态SvgDocument ^LoadFromFile (字符串^文件名,SvgLoadOptions ^选项)

参数

文件名
路径SVG文件在磁盘上

选项
在加载选项来使用。如果这个参数是,然后一个默认SvgLoadOptions对象将被使用。

返回值

SvgDocument这个方法创建对象。

讲话

获取和设置文档的范围和分辨率的信息,请参考SVG大小、范围和持平

例子

这个例子将使用Leadtools.Document.Writer.DocumentWriter从SVG文件创建一个PDF文件。

c#
VB
使用Leadtools;使用Leadtools.Codecs;使用Leadtools.Drawing;使用Leadtools.Forms.DocumentWriters;使用Leadtools.Svg;使用LeadtoolsExamples.Common;公共无效SvgLoadFromFileExample (){/ /创建SVG页面我们将使用字符串srcFileName = Path.Combine (ImagesPath.Path,“Leadtools.doc”);字符串dstFileName = Path.Combine (ImagesPath.Path,“Example.pdf”);字符串outDir = Path.Combine (ImagesPath.Path,“TempSvgPages”);如果(! Directory.Exists (outDir))Directory.CreateDirectory (outDir);intpageCount = CreateSvgPages (srcFileName outDir);/ /创建一个PDF文档使用文档的作家vardocumentWriter =DocumentWriter ();documentWriter。BeginDocument (dstFileName DocumentFormat.Pdf);字符串svgPageTemplateName = Path.Combine (outDir,”页面“{0}.);(intpageNumber = 1;pageNumber < = pageCount;pageNumber + +){/ /加载这个SVG字符串pageFileName =字符串.Format (svgPageTemplateName pageNumber);Console.WriteLine (加载“{0}”,pageFileName);使用(SvgDocument SvgDocument = SvgDocument.LoadFromFile (pageFileName,)){/ /检查是否我们需要平它如果(svgDocument.IsFlat !)svgDocument.Flat ();如果(svgDocument.Bounds.IsValid !)svgDocument.CalculateBounds ();/ /将其添加到文档的作家Console.WriteLine (“添加……”);DocumentSvgPage svgPage =DocumentSvgPage ();svgPage。SvgDocument = SvgDocument;documentWriter.AddPage (svgPage);}}/ /结束Console.WriteLine (“完成……”);documentWriter.EndDocument ();}私人静态intCreateSvgPages (字符串srcFileName,字符串outDir){/ /从源文件中提取的所有页面作为SVG使用(var编解码器=RasterCodecs ()){/ /设置300作为加载文档文件的默认值codecs.Options.RasterizeDocument.Load。分辨率= 300;/ /得到输入目录的所有文件intpageCount = codecs.GetTotalPages (srcFileName);(intpageNumber = 1;pageNumber < = pageCount;pageNumber + +){使用(SvgDocument SvgDocument =编解码器。LoadSvg (srcFileName pageNumber,)作为SvgDocument){/ /保存到磁盘字符串dstFileName =路径。结合(outDir Path.Combine (字符串.Format (”页面“{0}.,pageNumber)));Console.WriteLine (“拯救{0}”,dstFileName);svgDocument.SaveToFile (dstFileName);}}返回pageCount;}}
进口Leadtools进口Leadtools.Codecs进口Leadtools.Drawing进口Leadtools.Forms.DocumentWriters进口Leadtools.Svg公共共享SvgLoadFromFileExample ()我们将使用“创建SVG页面昏暗的srcFileName作为字符串= Path.Combine (Common.ImagesPath.Path“Leadtools.doc”)昏暗的dstFileName作为字符串= Path.Combine (Common.ImagesPath.Path“Example.pdf”)昏暗的outDir作为字符串= Path.Combine (Common.ImagesPath.Path“TempSvgPages”)如果Directory.Exists (outDir)然后Directory.CreateDirectory (outDir)结束如果昏暗的pageCount作为整数= CreateSvgPages (srcFileName outDir)“创建一个PDF文档使用文档的作家昏暗的documentWriter作为DocumentWriter ()documentWriter。BeginDocument (dstFileName DocumentFormat.Pdf)昏暗的svgPageTemplateName作为字符串= Path.Combine (outDir”页面“{0}.)pageNumber作为整数= 1pageCountSVG的加载这个昏暗的pageFileName作为字符串=字符串.Format (svgPageTemplateName pageNumber)Console.WriteLine (加载“{0}”pageFileName)使用svgDocument作为SvgDocument = svgDocument.LoadFromFile (pageFileName,没有什么)检查是否我们需要平它如果svgDocument.IsFlat然后svgDocument.Flat (没有什么)结束如果如果svgDocument.Bounds.IsValid然后svgDocument.CalculateBounds ()结束如果将其添加到文档的作家Console.WriteLine (“添加……”)昏暗的svgPage作为DocumentSvgPage ()svgPage。SvgDocument = SvgDocumentdocumentWriter.AddPage (svgPage)结束使用下一个的结束Console.WriteLine (“完成……”)documentWriter.EndDocument ()结束私人共享函数CreateSvgPages (srcFileName作为字符串,outDir作为字符串)作为整数从源文件中提取的所有页面的SVG使用编解码器作为RasterCodecs ()“300设置为默认值加载文档文件codecs.Options.RasterizeDocument.Load。分辨率= 300“从输入目录的所有文件昏暗的pageCount作为整数= codecs.GetTotalPages (srcFileName)pageNumber作为整数= 1pageCount使用svgDocument作为SvgDocument =DirectCast(编解码器。LoadSvg (srcFileName pageNumber,没有什么),SvgDocument)将其保存到磁盘昏暗的dstFileName作为字符串= Path.Combine (outDirPath.Combine(字符串.Format (”页面“{0}.pageNumber)))Console.WriteLine (“拯救{0}”dstFileName)svgDocument.SaveToFile (dstFileName没有什么)结束使用下一个返回pageCount结束使用结束函数
需求

目标平台

另请参阅

参考

SvgDocument类

SvgDocument成员

Leadtools.Svg作为sembly
188金宝搏的网址客服|支持|联系我们|知识产权的通知
©1991 - 2021领先的技术公司。保留所有权利。