C# 如何在pdf文档的所有页面上插入背景图像?

C# 如何在pdf文档的所有页面上插入背景图像?,c#,sharepoint-2010,pdf-generation,itextsharp,C#,Sharepoint 2010,Pdf Generation,Itextsharp,我需要C#中的示例代码,以便在完成的pdf文档的所有页面上插入背景图像。我正在使用iTextSharp库。你可以试试这个 void makePDF() { Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "attachment;filename=test.pdf"); Response.Cache.SetCacheability(HttpCachea

我需要C#中的示例代码,以便在完成的pdf文档的所有页面上插入背景图像。我正在使用iTextSharp库。

你可以试试这个

void makePDF()
{
    Response.ContentType = "application/pdf";

    Response.AddHeader("content-disposition", "attachment;filename=test.pdf");

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    string imageFilePath = Server.MapPath(".") + "/images/test.jpg";

    iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath);

    // Page site and margin left, right, top, bottom is defined
     Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);

    //Resize image depend upon your need
    //For give the size to image
     jpg.ScaleToFit(3000, 770);

    //If you want to choose image as background then,

    jpg.Alignment = iTextSharp.text.Image.UNDERLYING;

    //If you want to give absolute/specified fix position to image.
    jpg.SetAbsolutePosition(7, 69);

    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

    pdfDoc.Open();

    pdfDoc.NewPage();

    Paragraph paragraph = new Paragraph("this is the testing text for demonstrate the image is in background \n\n\n this is the testing text for demonstrate the image is in background");

    pdfDoc.Add(jpg);

    pdfDoc.Add(paragraph);

    pdfDoc.Close();

    Response.Write(pdfDoc);

    Response.End();
 }

我不能用回答。也许我需要连接一些名称空间?我想你应该使用iTextSharp.text添加iTextSharp.text.pdf。我不确定。我想他只是想把它写进一个文件。这个解决方案只会在第一页添加背景图像。把背景添加到每一页怎么样?