2011-02-26 44 views
2
public ActionResult GeneratePdf(int id) 
{ 
    var labelRepository = new LabelRepository(); 
    var label = labelRepository.GetLabel(id); 
    if (String.IsNullOrEmpty(label.PDFLocation)) 
    { 
     var action = Url.Content("~/Label/ViewPdf/" + id); //doc 

     Doc theDoc = new Doc(); 
     string filename = Guid.NewGuid().ToString(); 
     string path = Server.MapPath("~/" + filename + ".pdf"); 

     theDoc.AddImageUrl("action"); 
     theDoc.Save(path); 
     theDoc.Clear(); 

     label.PDFLocation = path; 
     labelRepository.Save(); 

     return base.File(path, "application/pdf"); 
    } 
    else 
    { 
     return base.File(label.PDFLocation, "application/pdf"); 
    } 
} 

这不会添加我的图像网址,所以我的PDF不会打开,所以我可以看到它。任何想法? -我的图片不会添加C#

+1

您使用什么库来生成PDF? – RQDQ 2011-02-26 18:44:49

+0

你是什么意思,它不会添加图片网址? – msarchet 2011-02-26 18:46:18

+0

我正在使用ABCPdf – Samjus 2011-02-26 18:46:43

回答

2

在示例here中,完整的URL正在传递给AddImageUrl()函数,而不是URL的片段,如您的示例所示。

也许您需要致电RouteUrl(),以便您可以获得完整的Url以传递给AddImageUrl()方法?

+0

我会看看这个RouteLink () – Samjus 2011-02-26 18:53:39

+0

@Samjus:看起来像'RouteLink'返回一个锚标记,而不是一个Url。让我看看我能否找到更好的东西。 – 2011-02-26 18:55:21

+0

@Samjus:它就是'RouteUrl'。编辑我的答案。 – 2011-02-26 18:57:54