详解高效而稳定的企业级.NET Office 组件Spire(.N(4)

public void XPStoPDF() { //xps file String file = @"..\..\..\..\..\..\Data\Sample4.xps"; //open xps document PdfDocument doc = new PdfDocument(); doc.LoadFromXPS(file); //convert to pdf file. doc.SaveToFile("Sample4.pdf"); doc.Close(); //Launching the Pdf file. PDFDocumentViewer("Sample4.pdf"); }

 6.Image转换为PDF:

public void ImageToPdf() { //Create a pdf document. PdfDocument doc = new PdfDocument(); // Create one page PdfPageBase page = doc.Pages.Add(); //Draw the text page.Canvas.DrawString("Hello, World!", new PdfFont(PdfFontFamily.Helvetica, 30f), new PdfSolidBrush(Color.Black), 10, 10); //Draw the image PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SalesReportChart.png"); float width = image.Width * 0.75f; float height = image.Height * 0.75f; float x = (page.Canvas.ClientSize.Width - width) / 2; page.Canvas.DrawImage(image, x, 60, width, height); //Save pdf file. doc.SaveToFile("Image.pdf"); doc.Close(); //Launching the Pdf file. PDFDocumentViewer("Image.pdf"); }

以上提供了对网站发起HTTP请求,获取网站页面信息,以及采用Spire.PDF组件创建PDF文档。如果有需要可以直接将HTTP请求获取到的信息直接加载如Spire.PDF的组件中,

由组件直接将网页信息转化为PDF文件,在这里就不再做更多的赘述,由于官方提供了很完善的demo和操作文档,在这里就不再过多的介绍使用方法。

四.总结:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjyydj.html