如何使用css样式将html div内容导出为pdf [英] How to export a html div content to pdf with css style

查看:285
本文介绍了如何使用css样式将html div内容导出为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将格式化的div内容导出为pdf。我的页面包含有关具有一些网格视图数据和普通asp标签控件的学生配置文件的信息。 plz给出解决方案,如果有任何

解决方案

这被多次询问意味着如果你只是谷歌它你会发现很多例子。这是最近的一个问题,有很多链接让你去。



如何在离线状态下使用C#将Div区域转换为Pdf和Excel格式 [ ^ ]


你需要使用linq to xml来读取div内容或使用regex获取数据后使用这些工具之一从头开始创建pdf文件,这里它们是 itext pdfsharp

我试过这个功能导出到excel你可以这样试试,也许可以帮到你







函数exportToExcel(){



controlRange = document.getElementById( bdy1)。createTextRange();



controlRange.execCommand(复制);



var objExcel = new ActiveXObject(Excel.Application);



// objExcel.Visible = true;



objExcel.Visible = false;



var objWorkbook = objExcel.Workbooks.Add;



objExcel .Application.IgnoreRemoteRequests = true;



var objWorksheet = objWorkbook.Worksheets(1);



objWorksheet .Paste;



objExcel.Cells.ColumnWidth = 20;



objWorksheet.Range(A12 ,A20)。ColumnWidth = 2;



objWorksheet.Range(B12,B20)。ColumnWidth = 2;



//objExcel.Cells.RowWidth=20;



objExcel.Cells.columns.AutoFit;



objWorksheet.Range(A12,A20)。EntireColumn.AutoFit;



objWorksheet.Range(B12,B20)。EntireColumn.AutoFit;



objExcel.Cells.rows.AutoFit;



if(objWorksheet.Shapes(1).Name ==图片1)



{



objWorksheet.Shapes(1).Visible = - 1;



objWorksheet.Shapes(2).Visible = 0;



}



objExcel.Application.Dialogs(5).Show('C:\\DocumentsandSettings \\arun\\');



// objExcel.Visible = false;

}


i have a requirement of exporting a formated div content to pdf. my page has information about a student profile with some grid view data and plain asp lable control. plz give the solution if any

解决方案

This is asked many times meaning if you just google it you'll find lots of examples. Here is a recent question of the same that has many links to get you going.

How Do I Convert Div Region Into Pdf And Excel Format Using C# In Offline[^]


you need to use linq to xml to read the div content or use regex once you get the data use one of this tools to create pdf file from scratch , here they are itext , pdfsharp


i have tried this funtion to export to excel you can try like this ,may be it help you



function exportToExcel() {

controlRange = document.getElementById("bdy1").createTextRange();

controlRange.execCommand("Copy");

var objExcel = new ActiveXObject("Excel.Application");

// objExcel.Visible = true;

objExcel.Visible = false;

var objWorkbook = objExcel.Workbooks.Add;

objExcel.Application.IgnoreRemoteRequests = true;

var objWorksheet = objWorkbook.Worksheets(1);

objWorksheet.Paste;

objExcel.Cells.ColumnWidth=20;

objWorksheet.Range("A12", "A20").ColumnWidth=2;

objWorksheet.Range("B12", "B20").ColumnWidth=2;

//objExcel.Cells.RowWidth=20;

objExcel.Cells.columns.AutoFit;

objWorksheet.Range("A12", "A20").EntireColumn.AutoFit;

objWorksheet.Range("B12", "B20").EntireColumn.AutoFit;

objExcel.Cells.rows.AutoFit;

if(objWorksheet.Shapes(1).Name == "Picture 1")

{

objWorksheet.Shapes(1).Visible=-1;

objWorksheet.Shapes(2).Visible=0;

}

objExcel.Application.Dialogs(5).Show('C:\\DocumentsandSettings\\arun\\');

// objExcel.Visible = false;
}


这篇关于如何使用css样式将html div内容导出为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆