Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# iTextSharp aspx到pdf,服务器。执行错误_C#_Asp.net_Css_Pdf_Itextsharp - Fatal编程技术网

C# iTextSharp aspx到pdf,服务器。执行错误

C# iTextSharp aspx到pdf,服务器。执行错误,c#,asp.net,css,pdf,itextsharp,C#,Asp.net,Css,Pdf,Itextsharp,在ASP.net中,我制作了一个用于填写报价表的网页。 有三个分区。左侧的div中有要填写的文本框。 作为形式本身的中间部门。 右边有按钮的div 到目前为止,我只能将midlesector导出为PDF格式,并在左侧和所有位置填写内容。问题是它完全忽略了CSS,而CSS是使用绝对定位制作的。因此,我想问一下如何包含CSS样式,使它看起来像它应该的样子,而不是一个连续的文本 这是middlesector的代码: <div id="middlesector" runat="server">

在ASP.net中,我制作了一个用于填写报价表的网页。 有三个分区。左侧的div中有要填写的文本框。 作为形式本身的中间部门。 右边有按钮的div

到目前为止,我只能将midlesector导出为PDF格式,并在左侧和所有位置填写内容。问题是它完全忽略了CSS,而CSS是使用绝对定位制作的。因此,我想问一下如何包含CSS样式,使它看起来像它应该的样子,而不是一个连续的文本

这是middlesector的代码:

<div id="middlesector" runat="server">
<%--><asp:GridView ID="GridView1" runat="server"></asp:GridView>--%>
<asp:Image ID="TextArea1" runat="server" ImageUrl="Images\VisserGroup.png"></asp:Image>
<label id="textarea2" runat="server" cols="20" name="S2"></label>
<label id="textarea3" runat="server" cols="20" name="S3">Visser International Trade & Engineering</label>
<label id="textarea4" runat="server" cols="20" name="S4">T.a.v</label>
<label id="textarea5" runat="server" cols="20" name="S5">Postbus</label>
<label id="textarea6" runat="server" name="S6"></label>
<label id="textarea7" runat="server" cols="20" name="S7"></label>
<label id="textarea8" runat="server" cols="20" name="S8"></label>
<label id="textarea9" runat="server" name="S9"></label>
<label id="textarea10" runat="server" cols="20" name="S10"></label>
<label id="textarea11" runat="server" cols="20" name="S11"></label>
<label id="textarea12" runat="server" cols="20" name="S12">-OFFERTE-</label>
<label id="textarea13" runat="server" name="S13">Geachte</label>
<label id="textarea14" runat="server" name="S14"></label>
<label id="textarea15" runat="server" cols="20" name="S15">Met referte aan het aangename onderhoud hebben wij het genoegen u bijgaand onze offerte te doen toekomen voor het leveren van:</label>
<label id="textarea16" runat="server" cols="20" name="S16"></label>
<label id="TextArea17" runat="server" cols="20" name="S17">Wij danken u voor deze aanvraag en hopen u hiermee een passend voorstel te hebben gedaan. Voor het bespreken van verdere details en toelichting op de offerte zullen wij op korte termijn contact met u opnemen. Indien u direct uw eventuele vragen aan ons wenst voor te leggen dan horen wij dit graag van u.</label>
<label id="TextArea18" runat="server" cols="20" name="S18">Wij vertrouwen u hiermee voldoende van dienst te zijn en houden ons van harte aanbevolen voor uw gewaardeerde opdracht.</label>
<label id="TextArea19" runat="server" cols="20" name="S19">Met vriendelijke groet,Visser Supplies B.V.</label>
<label id="TextArea20" runat="server" cols="20" name="S20">Personal info</label>
<label id="TextArea21" runat="server" cols="20" name="S21">Website          : www.vissersupplies.nl</label>
<label id="TextArea22" runat="server" cols="20" name="S22">E-mail           : personal info</label>
<label id="TextArea23" runat="server" cols="20" name="S23">Telefoonnummer   : personal info 9894</label>
<label id="TextArea24" runat="server" cols="20" name="S24">Copyright Visser Supplies B.V.:</label>
<label id="TextArea25" runat="server" cols="20" name="S25">Deze offerte en alle andere informatie mogen alleen door geadresseerde gebruikt worden. Overdracht aan derden, in welke vorm dan ook,  is slechts toegestaan na schriftelijk toestemming van Visser Supplies B.V.</label>
</div>
最后是代码隐藏函数:(编辑:10-10-2013:14:22:GTM+1)

我在以下位置得到一个错误: 执行(“中间扇区”,strWriter); 对于以下情况,也存在相同的错误: Server.Execute(“OfferteForm1.aspx”,strWriter)

它与IUSRS_machinename和ASPNET用户的权限有关。 但我不知道如何添加权限,因为我没有清单,也无法创建清单

我也试过: HtmlDecode(“中间扇区”,strWriter); 以及: HtmlDecode(“OfferteForm1.aspx”,strWriter)

它确实编译了一个PDF,但它只有图像。
我只希望XMLWorker在middlesector Div中包含填写的表单。

您使用的是
HTMLWorker
,而该类不查看CSS。尝试使用XML Worker:问题是我使用的是旧版本的iTextSharp,因为它有不同的许可协议。正如@BrunoLowagie所说,
HTMLWorker
不支持CSS,因此除非您想编写自己的解析器,否则没有解决方案。官方解决方案是使用
XMLWorker
。此外,关于4.x(2.1.7)版本是“免费”的说法还有很多,你可能想了解更多。我现在正在使用“XMLWorker”,但在使用它时遇到了一些问题。我只想把一个div及其内容放在PDF中,但我找不到一个这样做的例子。它使用这个.div.RenderControl(“TextWriter”)与HTMLWorker一起工作,但显然它忽略了CSS。有人知道怎么做吗?
#middlesector {
        position:absolute; left: 150px; top: 60px;
    }
#TextArea1 {
        height: 250px;
        width:  640px;
        position: absolute; top:-40px;
        border:none;
        scrollbar-3dlight-color: #fff;
        scrollbar-arrow-color: #fff;
        scrollbar-base-color: #fff;
    }

   #textarea2 {
       border-style: none;
       border-color: inherit;
       border-width: medium;
       height: 105px;
       width: 320px;
       position:absolute; top:220px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
   }

   #textarea3 {
       border-style: none;
       border-color: inherit;
       border-width: medium;
       height: 30px;
       width: 310px;
       position:absolute; top:215px;
       left: 410px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
   }

   #textarea4 {
       border-style: none;
       border-color: inherit;
       border-width: medium;
       height: 15px;
       width: 310px;
       position:absolute; top:250px;
       left: 410px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
   }

   #textarea5 {
       border-style: none;
       border-color: inherit;
       border-width: medium;
       height: 15px;
       width: 310px;
       position:absolute; top:270px;
       left: 410px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
   }

   #textarea6 {
       border-style: none;
       border-color: inherit;
       border-width: medium;
       height: 15px;
       width: 100px;
       position:absolute; top:290px;
       left: 410px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
   }

   #textarea7 {
       border-style: none;
       border-color: inherit;
       border-width: medium;
       height: 15px;
       width: 310px;
       position:absolute; top:310px;
       left: 410px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
   }

   #textarea8 {
       border-style: none;
       border-color: inherit;
       border-width: medium;
       height: 15px;
       width: 210px;
       position:absolute; top:290px;
       left: 480px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
   }

   #textarea9 {
       border-style: none;
       border-color: inherit;
       border-width: medium;
       height: 15px;
       width: 130px;
       position:absolute; top: 360px; 
       left: 360px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
   }
   #textarea10 {
       height: 15px;
       width: 180px;
       position:absolute; top:360px;
       left: 450px;
       border:none;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
   }

   #textarea11 {
       border-style: none;
       border-color: inherit;
       border-width: medium;
       height: 15px;
       width: 320px;
       position:absolute; top:360px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
       left: 0px;
   }

   #textarea12 {
       border-style: none;
       border-color: inherit;
       border-width: medium;
       font-size: large;
       font-weight: bold;
       height: 25px;
       width: 120px;
       position:absolute; top:400px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
       left: 270px;
   }

   #textarea13 {
       border-style: none;
       border-color: inherit;
       border-width: medium;
       height: 15px;
       width: 75px;
       position:absolute; top:450px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
       left: 0px;
   }

   #textarea14 {
       border-style: none;
       border-color: inherit;
       border-width: medium;
       height: 15px;
       width: 200px;
       position:absolute; top:450px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
       left: 65px;
       margin-left: auto;
   }

   #textarea15 {
        height: 30px;
        width:  640px;
        text-align:start;
        text-anchor:end;
        position: absolute; top:480px;
        border:hidden;
        scrollbar-3dlight-color: #fff;
        scrollbar-arrow-color: #fff;
        scrollbar-base-color: #fff;
        left: 0px;
    }

   #textarea16 {
       border-style: none;
       border-color: inherit;
       border-width: medium;
       font-size:large;
       font-weight: bold;
       height: 25px;
       width: 250px;
       position:absolute; top:540px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
       left: 270px;
   }

   #TextArea17 {
        height: 75px;
        width:  645px;
        text-align:start;
        text-anchor:end;
        position: absolute; top:580px;
        border:hidden;
        scrollbar-3dlight-color: #fff;
        scrollbar-arrow-color: #fff;
        scrollbar-base-color: #fff;
        left: 0px;
   }

   #TextArea18 {
        height: 30px;
        width:  640px;
        text-align:start;
        text-anchor:end;
        position: absolute; top:660px;
        border:hidden;
        scrollbar-3dlight-color: #fff;
        scrollbar-arrow-color: #fff;
        scrollbar-base-color: #fff;
        left: 0px;
    }

   #TextArea19 {
       width: 240px;
       position: absolute; top: 700px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
       border:hidden;
       left: 0px;
   }

   #TextArea20 {
       height: 15px;
       width: 400px;
       position: absolute; top: 760px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
       border:hidden;
       left: 0px;
   }

   #TextArea21 {
       height: 15px;
       width: 400px;
       position: absolute; top: 800px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
       border:hidden;
       left: 0px;
   }

   #TextArea22 {
       height: 15px;
       width: 400px;
       position: absolute; top: 820px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
       border:hidden;
       left: 0px;
   }

   #TextArea23 {
       height: 15px;
       width: 400px;
       position: absolute; top: 840px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
       border:hidden;
       left: 0px;
   }

   #TextArea24 {
       height: 10px;
       width: 400px;
       font-size:smaller;
       position: absolute; top: 880px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
       border:hidden;
       left: 0px;
   }

   #TextArea25 {
       height: 40px;
       width: 550px;
       font-size: x-small;
       position: absolute; top: 895px;
       scrollbar-3dlight-color: #fff;
       scrollbar-arrow-color: #fff;
       scrollbar-base-color: #fff;
       border:hidden;
       left: 0px;
   }
protected void SaveAsPDF(object sender, EventArgs e)
    {
        System.Web.UI.HtmlControls.HtmlGenericControl middlesector = new System.Web.UI.HtmlControls.HtmlGenericControl("middlesector");

        string strHtml = null;
        //MemoryStream memStream = new MemoryStream();
        StringWriter strWriter = new StringWriter();
        Server.Execute("OfferteForm1.aspx", strWriter);
        strHtml = strWriter.ToString();
        strWriter.Close();
        strWriter.Dispose();
        iTextSharp.text.Image addLogo = default(iTextSharp.text.Image);
        addLogo = iTextSharp.text.Image.GetInstance(Server.MapPath("Images") + "/VisserSupplies.jpg");
        iTextSharp.text.Document docWorkingDocument = new iTextSharp.text.Document(PageSize.A4, 40, 40, 40, 40);
        StringReader srdDocToString = null;
        try
        {
            PdfWriter pdfWrite = default(PdfWriter);
            var fileCounter = 1;
            while (File.Exists("C:/Users/milans/Documents/PDFs/" + textarea11.InnerText + " - " + fileCounter + ".pdf"))
            {
                fileCounter++;
            }
            pdfWrite = PdfWriter.GetInstance(docWorkingDocument, new FileStream("C:/Users/milans/Documents/PDFs/" + textarea11.InnerText + " - " + fileCounter + ".pdf", FileMode.Create));
            srdDocToString = new StringReader(strHtml);
            docWorkingDocument.Open();
            addLogo.ScalePercent(50);
            addLogo.Alignment = iTextSharp.text.Image.ALIGN_CENTER;
            docWorkingDocument.Add(addLogo);
            XMLWorkerHelper.GetInstance().ParseXHtml(pdfWrite, docWorkingDocument, srdDocToString);
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
        finally
        {
            if ((docWorkingDocument != null))
            {
                docWorkingDocument.Close();
                docWorkingDocument.Dispose();
            }
            if ((srdDocToString != null))
            {
                srdDocToString.Close();
                srdDocToString.Dispose();
            }
        }
            //Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "myscript", "window.open('C:/Users/milans/Documents/PDFs/" + textarea11.InnerText + ".pdf" + "','_blank','location=0,menubar=0,status=0,titlebar=0,toolbar=0');", true);
    }

    public override void VerifyRenderingInServerForm(Control control)
    {

    }