public PdfDocument(); public PdfDocument(string filename); public PdfDocument(byte[] bytes); public PdfDocument(Stream stream); public PdfDocument(string filename, string password); public PdfDocument(byte[] bytes, string password); public PdfDocument(Stream stream, string password);
public void LoadFromHTML(string Url, bool enableJavaScript, bool enableHyperlinks, bool autoDetectPageBreak)
{
// This item is obfuscated and can not be translated.
PdfHtmlLayoutFormat format;
int num;
goto Label_001E;
Label_008F:
num = 0;
Label_0002:
switch (num)
{
case 0:
break;
case 1:
if (!autoDetectPageBreak)
{
format.Layout = PdfLayoutType.OnePage;
format.FitToPage = Clip.Width;
format.FitToHtml = Clip.Height;
num = 2;
}
else
{
num = 3;
}
goto Label_0002;
case 2:
switch ((1 == 1))
{
case 2:
goto Label_008F;
}
if (0 != 0)
{
}
break;
case 3:
format.Layout = PdfLayoutType.Paginate;
format.FitToPage = Clip.Width;
goto Label_008F;
default:
goto Label_001E;
if (1 != 0)
{
}
format = new PdfHtmlLayoutFormat();
num = 1;
goto Label_0002;
}
this.Sections.Add().LoadFromHTML(Url, enableJavaScript, enableHyperlinks, format);
}
namespace Spire.Pdf.HtmlConverter
{
public enum AspectRatio
public enum Clip
[ToolboxItem(false)]
public class HtmlConverter : UserControl, sprᰐ, sprᶪ, sprṳ, sprẝ, sprẏ
public enum ImageType
public class PdfHtmlLayoutFormat
}
private Metafile (); static HtmlConverter(); public HtmlConverter(); public int Authenticate(ref IntPtr phwnd, ref IntPtr pszUsername, ref IntPtr pszPassword); public HtmlToPdfResult Convert(string url, ImageType type, int width, int height, AspectRatio aspectRatio); public HtmlToPdfResult Convert(string html, string baseurl, ImageType type, int width, int height, AspectRatio aspectRatio); public HtmlToPdfResult Convert(string url, ImageType type, int width, int height, AspectRatio aspectRatio, string username, string password); public Image ConvertToImage(string url, ImageType type); public Image ConvertToImage(Stream stream, Encoding encoding, ImageType type); public Image ConvertToImage(string url, ImageType type, int width); public Image ConvertToImage(Stream stream, Encoding encoding, ImageType type, int width); public Image ConvertToImage(string url, ImageType type, int width, int height); public Image ConvertToImage(string url, ImageType type, string username, string password); public Image ConvertToImage(Stream stream, Encoding encoding, ImageType type, int width, int height); public Image ConvertToImage(string url, ImageType type, int width, int height, AspectRatio aspectRatio); public Image ConvertToImage(string url, ImageType type, int width, string username, string password); public Image ConvertToImage(Stream stream, Encoding encoding, ImageType type, int width, int height, AspectRatio aspectRatio); public Image ConvertToImage(string url, ImageType type, int width, int height, string username, string password); public Image ConvertToImage(string url, ImageType type, int width, int height, AspectRatio aspectRatio, string username, string password); [DispId(-5512)] public int CustomizeDownload(); protected override void Dispose(bool disposing); public Image FromString(string html, ImageType type, int width); public Image FromString(string html, string baseUrl, ImageType type); public Image FromString(string html, ImageType type, int width, int height); public Image FromString(string html, string baseUrl, ImageType type, int width); public Image FromString(string html, ImageType type, int width, int height, AspectRatio aspectRatio); public Image FromString(string html, string baseUrl, ImageType type, int width, int height); public Image FromString(string html, string baseUrl, ImageType type, int width, int height, AspectRatio aspectRatio); public Image FromString(string html, string baseUrl, ImageType type, int width, int height, AspectRatio aspectRatio, string username, string password); public Image[] GetImagesFromString(string html, string baseUrl, ImageType type); public int QueryService(ref Guid guidService, ref Guid riid, out IntPtr ppvObject);int sprẏ.GetSecurityId(string pwszUrl, IntPtr pbSecurityId, ref uint pcbSecurityId, ref uint dwReserved); int sprẏ.GetSecuritySite(out IntPtr pSite); int sprẏ.GetZoneMappings(uint dwZone, out IEnumString ppenumString, uint dwFlags); int sprẏ.MapUrlToZone(string pwszUrl, out uint pdwZone, uint dwFlags); int sprẏ.ProcessUrlAction(string pwszUrl, uint dwAction, IntPtr pPolicy, uint cbPolicy, IntPtr pContext, uint cbContext, uint dwFlags, uint dwReserved); int sprẏ.QueryCustomPolicy(string pwszUrl, ref Guid guidKey, out IntPtr ppPolicy, out uint pcbPolicy, IntPtr pContext, uint cbContext, uint dwReserved); int sprẏ.SetSecuritySite(IntPtr pSite); int sprẏ.SetZoneMapping(uint dwZone, string lpszPattern, uint dwFlags); int sprᶪ.GetContainer(object ppContainer); int sprᶪ.GetMoniker(uint dwAssign, uint dwWhichMoniker, object ppmk); int sprᶪ.OnShowWindow(bool fShow); int sprᶪ.RequestNewObjectLayout(); int sprᶪ.SaveObject(); int sprᶪ.ShowObject();
/// <summary>
/// 指定路径发送GET请求
/// </summary>
/// <param name="getUrl"></param>
/// <returns></returns>
public static string HttpGet(string getUrl)
{
try
{
if (string.IsNullOrEmpty(getUrl))
throw new ArgumentNullException(getUrl);
var request = WebRequest.Create(getUrl) as HttpWebRequest;
if (request == null)
return null;
var cookieContainer = new CookieContainer();
request.CookieContainer = cookieContainer;
request.AllowAutoRedirect = true;
request.Method = "GET";
request.ContentType = "application/x-www-form-urlencoded";
var response = request.GetResponse() as HttpWebResponse;
if (response != null)
{
var instream = response.GetResponseStream();
if (instream == null)
throw new ArgumentNullException("getUrl");
string content;
using (var sr = new StreamReader(instream, Encoding.UTF8))
{
content = sr.ReadToEnd();
}
return content;
}
}
catch (Exception er)
{
throw new Exception(er.Message);
}
return null;
}
/// <summary>
/// 取得HTML中所有图片的 URL。
/// </summary>
/// <param name="url">HTML代码</param>
/// <returns>图片的URL列表</returns>
public static string HtmlCodeRequest(string url)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentNullException(url);
}
try
{
//创建一个请求
var httprequst = (HttpWebRequest)WebRequest.Create(url);
//不建立持久性链接
httprequst.KeepAlive = true;
//设置请求的方法
httprequst.Method = "GET";
//设置标头值
httprequst.UserAgent = "User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705";
httprequst.Accept = "*/*";
httprequst.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.5");
httprequst.ServicePoint.Expect100Continue = false;
httprequst.Timeout = 5000;
//是否允许302
httprequst.AllowAutoRedirect = true;
ServicePointManager.DefaultConnectionLimit = 30;
//获取响应
var webRes = (HttpWebResponse)httprequst.GetResponse();
//获取响应的文本流
string content;
using (var stream = webRes.GetResponseStream())
{
using (var reader = new StreamReader(stream, Encoding.GetEncoding("utf-8")))
{
content = reader.ReadToEnd();
}
}
//取消请求
httprequst.Abort();
//返回数据内容
return content;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
PdfDocument doc = new PdfDocument();
doc.LoadFromHTML(url, false, true, true);
doc.Close();
HtmlConverter.Convert
("http://www.wikipedia.org/","HTMLtoPDF.pdf",
//enable javascript
true,
//load timeout
* 1000,
//page size
new SizeF(612, 792),
//page margins
new PdfMargins(0, 0));
public static void TextLayout()
{
//Create a pdf document.
PdfDocument doc = new PdfDocument();
// Create one page
PdfPageBase page = doc.Pages.Add();
float pageWidth = page.Canvas.ClientSize.Width;
float y = 0;
//page header
PdfPen pen1 = new PdfPen(Color.LightGray, 1f);
PdfBrush brush1 = new PdfSolidBrush(Color.LightGray);
PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Italic));
PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Right);
String text = "Demo of Spire.Pdf";
page.Canvas.DrawString(text, font1, brush1, pageWidth, y, format1);
SizeF size = font1.MeasureString(text, format1);
y = y + size.Height + 1;
page.Canvas.DrawLine(pen1, 0, y, pageWidth, y);
//title
y = y + 5;
PdfBrush brush2 = new PdfSolidBrush(Color.Black);
PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
PdfStringFormat format2 = new PdfStringFormat(PdfTextAlignment.Center);
format2.CharacterSpacing = 1f;
text = "Summary of Science";
page.Canvas.DrawString(text, font2, brush2, pageWidth / 2, y, format2);
size = font2.MeasureString(text, format2);
y = y + size.Height + 6;
//icon
PdfImage image = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Wikipedia_Science.png");
page.Canvas.DrawImage(image, new PointF(pageWidth - image.PhysicalDimension.Width, y));
float imageLeftSpace = pageWidth - image.PhysicalDimension.Width - 2;
float imageBottom = image.PhysicalDimension.Height + y;
//refenrence content
PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 9f));
PdfStringFormat format3 = new PdfStringFormat();
format3.ParagraphIndent = font3.Size * 2;
format3.MeasureTrailingSpaces = true;
format3.LineSpacing = font3.Size * 1.5f;
String text1 = "(All text and picture from ";
String text2 = "Wikipedia";
String text3 = ", the free encyclopedia)";
page.Canvas.DrawString(text1, font3, brush2, 0, y, format3);
size = font3.MeasureString(text1, format3);
float x1 = size.Width;
format3.ParagraphIndent = 0;
PdfTrueTypeFont font4 = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Underline));
PdfBrush brush3 = PdfBrushes.Blue;
page.Canvas.DrawString(text2, font4, brush3, x1, y, format3);
size = font4.MeasureString(text2, format3);
x1 = x1 + size.Width;
page.Canvas.DrawString(text3, font3, brush2, x1, y, format3);
y = y + size.Height;
//content
PdfStringFormat format4 = new PdfStringFormat();
text = System.IO.File.ReadAllText(@"..\..\..\..\..\..\Data\Summary_of_Science.txt");
PdfTrueTypeFont font5 = new PdfTrueTypeFont(new Font("Arial", 10f));
format4.LineSpacing = font5.Size * 1.5f;
PdfStringLayouter textLayouter = new PdfStringLayouter();
float imageLeftBlockHeight = imageBottom - y;
PdfStringLayoutResult result
= textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight));
if (result.ActualSize.Height < imageBottom - y)
{
imageLeftBlockHeight = imageLeftBlockHeight + result.LineHeight;
result = textLayouter.Layout(text, font5, format4, new SizeF(imageLeftSpace, imageLeftBlockHeight));
}
foreach (LineInfo line in result.Lines)
{
page.Canvas.DrawString(line.Text, font5, brush2, 0, y, format4);
y = y + result.LineHeight;
}
PdfTextWidget textWidget = new PdfTextWidget(result.Remainder, font5, brush2);
PdfTextLayout textLayout = new PdfTextLayout();
textLayout.Break = PdfLayoutBreakType.FitPage;
textLayout.Layout = PdfLayoutType.Paginate;
RectangleF bounds = new RectangleF(new PointF(0, y), page.Canvas.ClientSize);
textWidget.StringFormat = format4;
textWidget.Draw(page, bounds, textLayout);
//Save pdf file.
doc.SaveToFile("TextLayout.pdf");
doc.Close();
//Launching the Pdf file.
PDFDocumentViewer("TextLayout.pdf");
}
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");
}
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");
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有