首页 >

HTML转PDF页面内容太大怎么分页 – CSS – 前端,宽度最大css

css 添加属性,css校验器,css覆盖top属性,CSS中搜索栏代码,css三栏布局模板,纯css放大镜效果,宽度最大cssHTML转PDF页面内容太大怎么分页 - CSS - 前端,宽度最大css

public void writeLog(string sMessage)

{

//FileStream fs = new FileStream(Server.MapPath(“pagetohtml.htm”), FileMode.Append);

try

{

StreamWriter swriter = File.CreateText(Server.MapPath(“pagetohtml.htm”));

swriter.WriteLine(sMessage);

swriter.Close();

}

catch

{ }

}

private System.Drawing.Bitmap bitmap;

private string url;

private int w = 760, h = 900;

public void setBitmap()

{

using (WebBrowser wb = new WebBrowser())

{

wb.Width = w;

wb.Height = h;

wb.ScrollBarsEnabled = false;

wb.Navigate(url);

//确保页面被解析完全

while (wb.ReadyState != WebBrowserReadyState.Complete)

{

System.Windows.Forms.Application.DoEvents();

}

bitmap = new System.Drawing.Bitmap(w, h);

wb.DrawToBitmap(bitmap, new System.Drawing.Rectangle(0, 0, w, h));

wb.Dispose();

}

}

private void CreatPdf()

{

Document doc = new Document(PageSize.A4, 9, 18, 36, 36);//左右上下

MemoryStream ms = new MemoryStream();

try

{

PdfWriter writer = PdfWriter.GetInstance(doc, ms);

writer.CloseStream = false;

doc.Open();

url = Server.MapPath(“pagetohtml.htm”);

Thread thread = new Thread(new ThreadStart(setBitmap));

thread.SetApartmentState(ApartmentState.STA);

thread.Start();

while (thread.IsAlive)

Thread.Sleep(100);

bitmap.Save(Server.MapPath(“pagetohtml.bmp”));

iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bitmap, System.Drawing.Imaging.ImageFormat.Bmp);

img.ScalePercent(75);//560 630

doc.Add(img);

}

catch (Exception err)

{

throw new Exception(err.Message);

}

finally

{

doc.Close();

using (FileStream fs = new FileStream(Server.MapPath(“pagetohtml.pdf”), FileMode.Create))

{

ms.Position = 0;

byte[] bit = new byte[ms.Length];

ms.Read(bit, 0, (int)ms.Length);

fs.Write(bit, 0, bit.Length);

}

ViewPdf(ms);

}

}

private void ViewPdf(Stream fs)

{

Response.Clear();

//中文名的话

//Response.AppendHeader(“Content-Disposition”, “attachment;filename=” +

// HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) + “;charset=GB2312”);

Response.AddHeader(“Content-Disposition”, “attachment;FileName=pagetohtml.pdf”);

Response.AddHeader(“Content-Length”, fs.Length.ToString());

Response.ContentType = “application/pdf”;

long fileLength = fs.Length;

int size = 10240;

byte[] readData = new byte[size];

if (size > fileLength)

size = Convert.ToInt32(fileLength);

long fPos = 0;

bool isEnd = false;

while (!isEnd)

{

if ((fPos + size) >= fileLength)

{

size = Convert.ToInt32(fileLength – fPos);

isEnd = true;

}

readData = new byte[size];

fs.Position = fPos;

fs.Read(readData, 0, size);

Response.BinaryWrite(readData);

Response.OutputStream.Flush();

fPos += size;

}

fs.Close();

Response.OutputStream.Close();

Response.End();

Response.Close();

}

css 添加属性,css校验器,css覆盖top属性,CSS中搜索栏代码,css三栏布局模板,纯css放大镜效果,宽度最大cssHTML转PDF页面内容太大怎么分页 - CSS - 前端,宽度最大css


HTML转PDF页面内容太大怎么分页 - CSS - 前端,宽度最大css
  • 网站改了静态设置 - CSS - 前端,dw cc 2018 css
  • 网站改了静态设置 - CSS - 前端,dw cc 2018 css | 网站改了静态设置 - CSS - 前端,dw cc 2018 css ...

    HTML转PDF页面内容太大怎么分页 - CSS - 前端,宽度最大css
  • 微软希望让Chrome在Windows平台上滚动更流畅 - CSS - 前端,css文本框 选中
  • 微软希望让Chrome在Windows平台上滚动更流畅 - CSS - 前端,css文本框 选中 | 微软希望让Chrome在Windows平台上滚动更流畅 - CSS - 前端,css文本框 选中 ...

    HTML转PDF页面内容太大怎么分页 - CSS - 前端,宽度最大css
  • vivo主题换了 - CSS - 前端,css 文字旋转 90度
  • vivo主题换了 - CSS - 前端,css 文字旋转 90度 | vivo主题换了 - CSS - 前端,css 文字旋转 90度 ...