2017-09-13 7 views
-2

C# 및 PDFSharp를 사용하여 PDF로 내보내기 기능을 작업 중입니다. 이 오류가 무엇입니까 :값은 null 일 수 없습니다. 매개 변수 이름 : PDFSharp의 elementId

Value cannot be null. 
Parameter name: elementId 

오류이 줄에 : PdfDocument document = PdfGenerator.GeneratePdf(htmlcontenttbl.ToString(), PdfSharp.PageSize.A4, 30);

다음은 전체 방법 : 당신이 빈 앵커 태그가있는 경우

public bool ExportPdf(string htmlcontenttbl) 
    { 
     Response.ClearContent(); 
     Response.ClearHeaders(); 

     Response.Buffer = true; 
     Response.ContentType = "application/octet-stream"; 
     Response.AddHeader("Content-Disposition", "attachment;filename=Myfile.pdf"); 
     //Response.AddHeader("Content-Disposition", "inline;filename=file.pdf"); 
     //Response.AppendHeader("Content-Disposition", "attachment; filename=Myfile.pdf"); 
     Response.Charset = ""; 
     StringWriter sw = new StringWriter(); 
     HtmlTextWriter htw = new HtmlTextWriter(sw); 

     PdfDocument document = PdfGenerator.GeneratePdf(htmlcontenttbl.ToString(), PdfSharp.PageSize.A4, 30); 
     var config = new PdfGenerateConfig(); 
     config.PageOrientation = PageOrientation.Landscape; 
     config.PageSize = PageSize.A4; 
     config.MarginBottom = 30; 
     config.MarginTop = 30; 
     //PdfDocument document = PdfGenerator.GeneratePdf(htmlcontenttbl, config); 

     byte[] bytes = null; 
     using (MemoryStream stream = new MemoryStream()) 
     { 
      document.Save(stream, true); 
      bytes = stream.ToArray(); 
     } 

     //var path1 = Server.MapPath("~/Images/" + DateTime.Now.TimeOfDay.Ticks + "result.pdf"); 
     //System.IO.File.WriteAllBytes(path1, bytes); 
     //Response.TransmitFile(path1, 0, bytes.Length); 
     //Response.OutputStream.Write(bytes, 0, bytes.Length); 

     Response.BinaryWrite(bytes); 
     Response.Flush(); 
     Response.End(); 

     return true; 
    } 
+3

스택 추적을 볼 수 있습니까? –

+2

스택 트레이스가 실제로 도움이됩니다. elementId라는 매개 변수가 없습니다. –

+0

'ScrollToElement'만이이 예외를 던지는 그 프로젝트의 유일한 장소입니다 : https://github.com/ArthurHub/HTML-Renderer/search?utf8=%E2%9C%93&q=elementId&type= 그러나 그것이 어디서 왔는지 전혀 모르겠습니다. 매개 변수가 'null'이거나 ** 비어있는 이유는 무엇입니까? –

답변

0

그 예외가 발생할 수 있습니다.

궁극적으로 here에서 생성 될 가능성이 큽니다.

빈 앵커 태그를 제거해야합니다.