Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.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的几个问题_C#_Asp.net_.net_Gridview_Itextsharp - Fatal编程技术网

C# 关于iTextSharp的几个问题

C# 关于iTextSharp的几个问题,c#,asp.net,.net,gridview,itextsharp,C#,Asp.net,.net,Gridview,Itextsharp,我正在尝试在ASP.NET和C#中使用GridView制作PDF 目前,我有以下代码: // On récupère le n ombre de lignes et de colonne de la GridView int noOfColumns = gvReportingStockComp.Columns.Count; int noOfRows = gvReportingStockComp.Rows.Count; // On fixe les

我正在尝试在ASP.NET和C#中使用GridView制作PDF

目前,我有以下代码:

// On récupère le n ombre de lignes et de colonne de la GridView
        int noOfColumns = gvReportingStockComp.Columns.Count;
        int noOfRows = gvReportingStockComp.Rows.Count;

        // On fixe les informations concernant les tailles de police du document PDF
        float HeaderTextSize = 8;
        float ReportNameSize = 10;
        float ReportTextSize = 8;
        float ApplicationNameSize = 7;

        // --- On crée le document final --- \\
        Document document = null;
        // Le document final sera-t-il en mode paysage ou non
        bool LandScape = true;
        if (LandScape == true)
        {
            // Comme le document est en mode paysage, on execute une rotation sur ces dimensions
            // Les 4 derniers paramètres de la fonction correspondent aux marges du document sur les bords
            document = new Document(PageSize.A4.Rotate(), 0, 0, 15, 5);
        }
        else
        {
            // On spécifie les dimensions du document
            // Les 4 derniers paramètres de la fonction correspondent aux marges du document sur les bords
            document = new Document(PageSize.A4, 0, 0, 15, 5);
        }

        // On créer un PdfTable qui contient le même nombre de colonne que la GridView.
        PdfPTable mainTable = new PdfPTable(noOfColumns);

        // Notre document sera composé de au minimum 4 lignes :
        // 1 : Nom appli + Date
        // 2 : Titre du tableau
        // 3 : Saut de ligne
        // 4 : Headers du tableau
        // X : Lignes du tableau
        mainTable.HeaderRows = 4;

        // On créer un PdfTable de 2 colonnes qui contiendra dans la première le titre de page et
        // dans la seconde une date
        PdfPTable headerTable = new PdfPTable(2);

        // On crée une phrase qui s'affichera dans le coin haut/gauche du document
        Phrase phApplicationName = new Phrase("Trèves", FontFactory.GetFont("Tahoma", ApplicationNameSize, iTextSharp.text.Font.NORMAL));

        // On crée une cellule PDF qui acceptera une phrase comme paramètre.
        PdfPCell clApplicationName = new PdfPCell(phApplicationName);
        // La cellule ne doit pas avoir de bordure
        clApplicationName.Border = PdfPCell.NO_BORDER;
        // On cadre le texte de la cellule à gauche
        clApplicationName.HorizontalAlignment = Element.ALIGN_LEFT;

        // On créer une phrase qui contiendra la date de création du document pour la cadré dans le coin haut/droite du document
        Phrase phDate = new Phrase(DateTime.Now.Date.ToString("dd/MM/yyyy"), FontFactory.GetFont("Tahoma", ApplicationNameSize, iTextSharp.text.Font.NORMAL));

        // On crée une cellule PDF qui acceptera une phrase comme paramètre.
        PdfPCell clDate = new PdfPCell(phDate);
        // On cadre le texte de la cellule à droite
        clDate.HorizontalAlignment = Element.ALIGN_RIGHT;
        // La cellule ne doit pas avoir de bordure
        clDate.Border = PdfPCell.NO_BORDER;

        // On ajoute ces cellules au tableau du document
        headerTable.AddCell(clApplicationName);
        headerTable.AddCell(clDate);
        // Pas de bordure
        headerTable.DefaultCell.Border = PdfPCell.NO_BORDER;

        // On crée une cellule PDF qui acceptera le headerTable et on l'ajoute à cette cellule
        PdfPCell cellHeader = new PdfPCell(headerTable);
        // Pas de bordure
        cellHeader.Border = PdfPCell.NO_BORDER;
        // On peut mettre une couleur de fond
        //cellHeader.BackgroundColor = Color.RED;
        // On indique que cet header va prendre une largeur égale
        // au nombre de colonne du tableau (pour qu'il prenne toute la page)
        cellHeader.Colspan = noOfColumns;
        // On ajoute la cellule au mainTable
        mainTable.AddCell(cellHeader);

        // On créer une autre phrase qui se trouverau au dessus du tableau
        string intituleTableau = lbBtnReportingStockComp.Text;
        Phrase phHeader = new Phrase(intituleTableau, FontFactory.GetFont("Tahoma", ReportNameSize, iTextSharp.text.Font.BOLD));
        PdfPCell clHeader = new PdfPCell(phHeader);
        clHeader.Colspan = noOfColumns;
        clHeader.Border = PdfPCell.NO_BORDER;
        clHeader.HorizontalAlignment = Element.ALIGN_CENTER;
        mainTable.AddCell(clHeader);

        // On créer un phrase qui représentera un saut de ligne
        Phrase phSpace = new Phrase("\n");
        PdfPCell clSpace = new PdfPCell(phSpace);
        clSpace.Border = PdfPCell.NO_BORDER;
        clSpace.Colspan = noOfColumns;
        mainTable.AddCell(clSpace);

        // On génère les noms de colonnes et on les insèrent
        for (int i = 0; i < noOfColumns; i++)
        {
            Phrase ph = null;

            ph = new Phrase(gvReportingStockComp.Columns[i].HeaderText, FontFactory.GetFont("Tahoma", HeaderTextSize, iTextSharp.text.Font.BOLD));

            mainTable.AddCell(ph);
        }

        // On lit les lignes de la GridView et on les insère dans le mainTables
        for (int rowNo = 0; rowNo < noOfRows; rowNo++)
        {
            for (int columnNo = 0; columnNo < noOfColumns; columnNo++)
            {
                if (gvReportingStockComp.Columns[columnNo] is TemplateField)
                {
                    DataBoundLiteralControl lc = gvReportingStockComp.Rows[rowNo].Cells[columnNo].Controls[0] as DataBoundLiteralControl;
                    string s = lc.Text.Trim();
                    Phrase ph = new Phrase(s, FontFactory.GetFont("Tahoma", ReportTextSize, iTextSharp.text.Font.NORMAL));
                    mainTable.AddCell(ph);
                }
                else
                {
                    // Trim() supprime en début et fin de chaîne les espaces blancs
                    string s = gvReportingStockComp.Rows[rowNo].Cells[columnNo].Text.Trim();
                    Phrase ph = new Phrase(s, FontFactory.GetFont("Tahoma", ReportTextSize, iTextSharp.text.Font.NORMAL));
                    mainTable.AddCell(ph);
                }
            }

            // On dit que la ligne est terminé même si toutes les cellules n'ont pas été renseignées
            mainTable.CompleteRow();
        }

        // On prend le document créé et on l'associe au flux de sortie
        PdfWriter.GetInstance(document, Response.OutputStream);

        // On créer un pied de page avec le numéro de page (on met le second paramètre à TRUE pour cela)
        HeaderFooter pdfFooter = new HeaderFooter(new Phrase(), true);
        pdfFooter.Alignment = Element.ALIGN_CENTER;
        pdfFooter.Border = iTextSharp.text.Rectangle.TOP_BORDER;
        pdfFooter.BorderWidth = 1;

        // On associe le pied de page au document
        document.Footer = pdfFooter;

        // Création du document puis fermeture
        document.Open();
        document.Add(mainTable);
        document.Close();

        Response.ContentType = "application/pdf";
        // On informe le nom du document
        Response.AddHeader("content-disposition", "attachment; filename= StockComp_"+date+".pdf");
        Response.End();
//关于网格视图中的路线和柱状图
int noOfColumns=gvReportingStockComp.Columns.Count;
int noOfRows=gvReportingStockComp.Rows.Count;
//关于固定信息的相关信息,请参阅文件PDF
浮头TEXTSIZE=8;
float ReportNameSize=10;
float ReportTextSize=8;
float ApplicationNameSize=7;
//---在crée le文件最终版上--\\
单据=空;
//文件最终sera-t-il en模式付款
布尔景观=真实;
如果(横向==真)
{
//在执行非旋转表面尺寸时,在模式付款时使用Comme le document est
//Les 4 derniers paramètres de la fonction通讯员aux marges du document sur Les bords
document=新文档(PageSize.A4.Rotate(),0,0,15,5);
}
其他的
{
//关于文件的规格
//Les 4 derniers paramètres de la fonction通讯员aux marges du document sur Les bords
文档=新文档(PageSize.A4,0,0,15,5);
}
//关于网格视图中的柱状图名称。
PdfPTable mainTable=新的PdfPTable(noOfColumns);
//Notre document sera composéde au至少4条路线:
//1:名称应用+日期
//2:画面标题
//3:炒木
//4:表格标题
//X:画面线
mainTable.HeaderRows=4;
//关于2号科隆的许可证,请参见第页标题等
//第二次约会
PdfPTable headerTable=新的PdfPTable(2);
//关于crée une短语qui s'affichera dans le coin haut/gauche du document
短语phaapplicationname=新短语(“Trèves”,FontFactory.GetFont(“Tahoma”,ApplicationNameSize,iTextSharp.text.Font.NORMAL));
//在电影《小房间》中,PDF是一个简单的短语。
PdfPCell clApplicationName=新的PdfPCell(phApplicationName);
//这是一个非常有趣的故事
claplicationname.Border=PdfPCell.NO_Border;
//关于高切细胞的文本
clApplicationName.HorizontalAlignment=Element.ALIGN_LEFT;
//关于“文件日期”这一短语,请将文件上的硬币/硬币放在一起
phDate=新短语(DateTime.Now.Date.ToString(“dd/MM/yyyy”)、FontFactory.GetFont(“Tahoma”、ApplicationNameSize、iTextSharp.text.Font.NORMAL));
//在电影《小房间》中,PDF是一个简单的短语。
PdfPCell clDate=新的PdfPCell(phDate);
//关于蜂窝织品的文本
clDate.HorizontalAlignment=Element.ALIGN\u RIGHT;
//这是一个非常有趣的故事
clDate.Border=PdfPCell.NO_Border;
//关于一份文件的图表
headerTable.AddCell(claplicationname);
headerTable.AddCell(clDate);
//波杜尔酒店
headerTable.DefaultCell.Border=PdfPCell.NO_Border;
//关于《小房间》PDF,请接受《小房间》上的标题
PdfPCell cellHeader=新的PdfPCell(headerTable);
//波杜尔酒店
cellHeader.Border=PdfPCell.NO_Border;
//关于我的朋友
//cellHeader.BackgroundColor=Color.RED;
//关于独立性的问题,我想这是一个很大的问题
//表列名称(请参阅第页)
cellHeader.Colspan=noOfColumns;
//在一张桌子上
mainTable.AddCell(cellHeader);
//关于这个短语的意思是:在画面上画出一幅图画
字符串intituleTableau=lbBtnReportingStockComp.Text;
phHeader=新短语(intituleTableau,FontFactory.GetFont(“Tahoma”,ReportNameSize,iTextSharp.text.Font.BOLD));
PdfPCell clHeader=新的PdfPCell(phHeader);
clHeader.Colspan=noOfColumns;
clHeader.Border=PdfPCell.NO_Border;
clHeader.HorizontalAlignment=Element.ALIGN\u CENTER;
mainTable.AddCell(clHeader);
//关于“不结盟”一词的探讨
短语phSpace=新短语(“\n”);
PdfPCell clSpace=新的PdfPCell(phSpace);
clSpace.Border=PdfPCell.NO_Border;
clSpace.Colspan=noOfColumns;
mainTable.AddCell(clSpace);
//论《科隆的名字》等
for(int i=0;i <RowStyle  HorizontalAlign="Center" />
 <AlternatingRowStyle HorizontalAlign="Center" />