小编Bro*_*mdh的帖子

CSS样式未使用iTextSharp应用于PDF

我试图使用iTextSharp将我的网页的一部分转换为pdf,虽然pdf生成工作正常,但没有应用任何css样式.我尝试过一次一个地应用这些样式,但这似乎不起作用.这是我到目前为止所提出的:

//Get the portion of the page to convert.
StringBuilder sb = new StringBuilder();
print_div.RenderControl(new HtmlTextWriter(new StringWriter(sb)));
string html = sb.ToString();

//Generate a random filename to use for the pdf
Guid random_guid;
random_guid = Guid.NewGuid();
string fileName = random_guid.ToString() + ".pdf";
string filename_with_folder = @"pdf\sl_" + fileName;
string fullFilePath = System.IO.Path.Combine(Request.PhysicalApplicationPath, filename_with_folder);

using (Document doc = new Document())
{
    // Create the pdf
    PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(fullFilePath, FileMode.Create));
    doc.Open();
    try
    {
        //Set the font size for all elements …
Run Code Online (Sandbox Code Playgroud)

c# pdf-generation itextsharp

8
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

itextsharp ×1

pdf-generation ×1