資源簡介
C#生成PDF 讀取PDF文本內容 獲取PDF內圖片完整源碼(調用第三方DLL)

代碼片段和文件信息
using?iTextSharp.text.pdf;
using?Spire.Pdf;
using?Spire.Pdf.Graphics;
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Drawing.Imaging;
using?System.IO;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
namespace?ReadPDF
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????//1.?生成一個PDF將文本和圖片添加到PDF里面。
????????//2.?從PDF文檔中提取所有圖片。
????????//3.?從PDF文檔中提取所有文本。
???????//生成一個PDF文件?里面包含文本和圖片
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????Spire.Pdf.PdfDocument?doc?=?new?Spire.Pdf.PdfDocument();
????????????PdfPagebase?page?=?doc.Pages.Add();
????????????//添加文本??
????????????page.Canvas.DrawString(“Hello!Welcome?to?my?house!“
????????????new?Spire.Pdf.Graphics.PdfFont(PdfFontFamily.Helvetica?20f)
????????????new?PdfSolidBrush(Color.Black)?10?10);//中文漢字字符均不能正確生成?英文字母可以
????????????//添加圖片
????????????Spire.Pdf.Graphics.PdfImage?image?=?Spire.Pdf.Graphics.PdfImage.FromFile(“ff.jpg“);
????????????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);
????????????//Spire.Pdf.Graphics.PdfImage?image2?=?Spire.Pdf.Graphics.PdfImage.FromFile(“image.jpg“);
????????????//width?=?image2.Width?*?0.75f;
????????????//height?=?image2.Height?*?0.75f;
????????????//page.Canvas.DrawImage(image2?x?-?100?220?width?height);
????????????doc.SaveToFile(“sample.pdf“);
????????}
????????//讀取圖片?獲取圖片個數?并把圖片保存到本地
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????Spire.Pdf.PdfDocument?doc?=?new?Spire.Pdf.PdfDocument();
????????????doc.LoadFromFile(“sample.pdf“);
????????????IList?images?=?new?List();
????????????foreach?(PdfPagebase?page?in?doc.Pages)
????????????{
????????????????if?(page.ExtractImages()?!=?null)
????????????????{
????????????????????foreach?(Image?image?in?page.ExtractImages())
????????????????????{
????????????????????????images.Add(image);
????????????????????}
????????????????}
????????????}
????????????doc.Close();
????????????int?index?=?0;
????????????int?aa?=?images.Count;
????????????label3.Text?=?aa.ToString();
????????????foreach?(Image?image?in?images)
????????????{
????????????????String?imageFileName?=?String.Format(“Image-{0}.png“?index++);
????????????????image.Save(imageFileName?ImageFormat.Png);
????????????}
????????}
????????//讀取文本
????????private?void?button3_Click(object?sender?EventArgs?e)
????????{
????????????Spire.Pdf.PdfDocument?doc?=?new?Spire.Pdf.PdfDocument();
????????????doc.LoadFromFile(“sample.pdf“);
????????????StringBuilder?buffer?=?new?StringBuilder();
????????????foreach?(PdfPage
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????189??2017-06-27?15:17??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\App.config
?????文件?????179075??2017-06-27?15:05??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\aa.pdf
?????文件?????211915??2017-06-21?09:23??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\ff.jpg
?????文件????1121466??2019-02-14?09:16??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\Image-0.png
?????文件????4059136??2016-10-07?20:33??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\itextsharp.dll
?????文件????8032448??2017-03-13?16:32??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\Microsoft.mshtml.dll
?????文件??????13312??2019-02-14?09:18??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\ReadPDF.exe
?????文件????????189??2017-06-27?15:17??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\ReadPDF.exe.config
?????文件??????32256??2019-02-14?09:18??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\ReadPDF.pdb
?????文件??????11592??2019-02-14?09:18??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\ReadPDF.vshost.exe
?????文件????????189??2017-06-27?15:17??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\ReadPDF.vshost.exe.config
?????文件????????490??2013-03-18?17:00??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\ReadPDF.vshost.exe.manifest
?????文件?????328897??2019-02-14?09:16??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\sample.pdf
?????文件??????44032??2014-02-25?14:19??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\Spire.License.dll
?????文件???12144640??2015-01-13?09:15??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\Spire.Pdf.dll
?????文件?????????41??2017-06-27?16:03??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\bin\Debug\TextInPdf.txt
?????文件???????5045??2019-02-14?09:18??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\Form1.cs
?????文件???????7520??2019-02-14?09:18??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\Form1.Designer.cs
?????文件???????5817??2019-02-14?09:18??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\Form1.resx
?????文件?????????42??2017-06-27?15:41??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\obj\Debug\CoreCompileInputs.cache
?????文件????????867??2019-02-14?09:17??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????6787??2019-02-14?09:18??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件???????1914??2019-02-14?09:18??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\obj\Debug\ReadPDF.csproj.FileListAbsolute.txt
?????文件????????975??2019-02-14?09:18??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\obj\Debug\ReadPDF.csproj.GenerateResource.Cache
?????文件??????20040??2019-02-14?09:18??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\obj\Debug\ReadPDF.csprojResolveAssemblyReference.cache
?????文件??????13312??2019-02-14?09:18??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\obj\Debug\ReadPDF.exe
?????文件????????180??2019-02-14?09:18??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\obj\Debug\ReadPDF.Form1.resources
?????文件??????32256??2019-02-14?09:18??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\obj\Debug\ReadPDF.pdb
?????文件????????180??2017-06-27?15:47??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\obj\Debug\ReadPDF.Properties.Resources.resources
?????文件??????????0??2017-06-27?15:17??C#生成PDF?讀取PDF文本內容?獲取PDF內圖片\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
............此處省略22個文件信息
評論
共有 條評論