【问题标题】:Image to be loaded into pdf file created from Sharepoint Server Images Folder要加载到从 Sharepoint 服务器图像文件夹创建的 pdf 文件中的图像
【发布时间】:2011-11-17 20:36:30
【问题描述】:

我正在使用 ItextSharp 库通过单击我的 SharePoint 站点的按钮生成 pdf 文件。我想在 pdf 上使用徽标,其图像位于 Sharepoint 的图像文件夹中。我做不到。

谁能帮帮我。

下面是我正在使用的代码,它从 window32 获取我不想要的实例。

 protected void button1_OnClick(object sender, EventArgs e)
  {
      Font Arial = FontFactory.GetFont("Arial", 12, BaseColor.GREEN);
      Font Verdana = FontFactory.GetFont("Verdana", 16, Font.BOLDITALIC, new BaseColor(125, 88, 15));
      string imagepath = SPContext.Current.Web + "/_layouts/Images/Image1.png";
      using (var ms = new MemoryStream())
      {
          using (var document = new Document(PageSize.A4,50,50,15,15))
          {
              PdfWriter.GetInstance(document, ms); 
              document.Open();
              Paragraph img = new Paragraph();
              Image jpg = Image.GetInstance(imagepath); --- Getting an error here stating "Could not find a part of the path 'c:\windows\system32\inetsrv\CustomSystem\_layouts\Images\Image1.png'"
              img.Add(jpg );
          }
       }
      }

请帮忙!

【问题讨论】:

    标签: asp.net sharepoint itextsharp itext


    【解决方案1】:

    我对 SharePoint 开发不太熟悉,但您的问题在于这一行:

    string imagepath = SPContext.Current.Web + "/_layouts/Images/Image1.png";
    

    此字符串必须是绝对路径路径,例如c:\www\sites\image.png,而不是现在的相对路径。我可以告诉它的相对关系,因为当您要求 ASP.Net 为您获取某些东西但您没有指定它在 %WINDOWS% 中查找的路径时。

    我不知道您如何使用SPContext.Current.Web,但根据调用.ToString() 的文档,它会返回网站的标题,如果您将它与像您一样的字符串连接起来会发生什么。我的猜测是您不需要它,但可能是错误的。

    如果layouts 文件夹是您正在处理的文件所在文件夹的子文件夹,那么您应该能够使用Server.MapPath 来获取绝对路径:

    string imagepath = Server.MapPath("_layouts/Images/Image1.png");
    

    【讨论】:

    • 感谢您的回复,我通过使用字符串 imagepath = Page.Server.MapPath("/_layouts/Images/ImageFolder/Image1.gif" ) ;
    【解决方案2】:

    我在我的共享点网站上做过这样的事情

    string url = "http://fspl-dsktp-038:8000/Style%20Library/FSPL/CorporateLogo.png";
    
    //iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(Server.MapPath("images") + "//images/FSPL LOGO.png");
    
    iTextSharp.text.Image logo =iTextSharp.text.Image.GetInstance(url); 
    logo.ScaleAbsolute(90, 90);
    Imagecell.AddElement(logo);
    gvTable.AddCell(Imagecell);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-27
      • 2016-03-10
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2012-07-28
      • 2012-08-24
      • 1970-01-01
      相关资源
      最近更新 更多