Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.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
Javascript 需要生成PDF文件,并在;3 X 4“;格式_Javascript_C#_Pdf_Pdf Generation_Jspdf - Fatal编程技术网

Javascript 需要生成PDF文件,并在;3 X 4“;格式

Javascript 需要生成PDF文件,并在;3 X 4“;格式,javascript,c#,pdf,pdf-generation,jspdf,Javascript,C#,Pdf,Pdf Generation,Jspdf,是否可以生成“3x4”格式的pdf 我尝试了下面的代码,但是没有生成PDF,我已经从下载了JSPDF.min var doc=new jsPDF(); 变量specialElementHandlers={ “#编辑器”:函数(元素、渲染器){ 返回true; } }; $('#cmd')。单击(函数(){ doc.fromHTML($('#content').html(),15,15{ “宽度”:170, “elementHandlers”:specialElementHandlers });

是否可以生成“3x4”格式的pdf

我尝试了下面的代码,但是没有生成PDF,我已经从下载了JSPDF.min


var doc=new jsPDF();
变量specialElementHandlers={
“#编辑器”:函数(元素、渲染器){
返回true;
}
};
$('#cmd')。单击(函数(){
doc.fromHTML($('#content').html(),15,15{
“宽度”:170,
“elementHandlers”:specialElementHandlers
});
doc.save('sample-file.pdf');
});
html代码

<div id="content">
<h3>Hello, this is a H3 tag</h3>    
<p>a pararaph</p>
</div>
<div id="editor"></div>
<button id="cmd">generate PDF</button>

你好,这是H3标签
标线

生成PDF
这是我在页面中的代码,我无法创建PDF,也无法创建任何生成PDF的方式。我如何才能使其以3X4格式显示


我从这里得到了这段代码的参考,在这里正确地生成了PDF,我缺少了什么?

我使用了iTextSharp并使用了它。下面是我的代码

using iTextSharp.text;
using iTextSharp.text.pdf;
string shippingaddress = "My name is khan <br/>";
shippingaddress += "And I am not a terrorist<br/>";
        using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
        {            
            //Below code defines the PDF generate Size
            Rectangle newRect = new Rectangle(0, 0, 240, Convert.ToSingle(138.6));
            Document document = new Document(newRect,10f,10f,10f,10f);
            Document.Compress = true;
            PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
            document.Open();
            Font boldFont = new Font(Font.FontFamily.HELVETICA, 12,Font.BOLD);
            Paragraph para = new Paragraph("Header", boldFont);
            document.Add(para);
            string text = shippingaddress.Replace("<br/>", "\n");
            Paragraph paragraph = new Paragraph();
            paragraph.SpacingBefore = 2;
            paragraph.SpacingAfter = 2;
            paragraph.Leading = 12;
            paragraph.Alignment = Element.ALIGN_LEFT;
            paragraph.Font = FontFactory.GetFont(FontFactory.HELVETICA, 12f,BaseColor.BLACK);
            paragraph.Add(text);
            document.Add(paragraph);
            document.Close();
            byte[] bytes = memoryStream.ToArray();
            memoryStream.Close();
            Response.Clear();
            Response.ContentType = "application/pdf";
            string pdfName = "Movie Name";
            Response.AddHeader("Content-Disposition", "inline; filename=" + pdfName + ".pdf");    
            Response.ContentType = "application/pdf";
            Response.Buffer = true;   
            Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
            Response.BinaryWrite(bytes);
            Response.End();
            Response.Close();    
        }
使用iTextSharp.text;
使用iTextSharp.text.pdf;
string shippingaddress=“我的名字是khan
”; shippingaddress+=“我不是恐怖分子
”; 使用(System.IO.MemoryStream MemoryStream=new System.IO.MemoryStream()) { //下面的代码定义了PDF生成大小 矩形newRect=新矩形(0,0,240,Convert.ToSingle(138.6)); 文档=新文档(newRect、10f、10f、10f、10f); Document.Compress=true; PdfWriter writer=PdfWriter.GetInstance(文档,内存流); document.Open(); Font boldFont=新字体(Font.FontFamily.HELVETICA,12,Font.BOLD); 段落段落=新段落(“标题”,粗体); 文件.增补(第6段); 字符串文本=发货地址。替换(“
,“\n”); 段落=新段落(); 段落.SpacingBefore=2; 第1.2段间隔时间=2; 前导段=12; 段落对齐=Element.ALIGN_LEFT; 段落.Font=FontFactory.GetFont(FontFactory.HELVETICA,12f,BaseColor.BLACK); 添加(案文)段; 文件.添加(第段); document.Close(); byte[]bytes=memoryStream.ToArray(); memoryStream.Close(); Response.Clear(); Response.ContentType=“application/pdf”; 字符串pdfName=“电影名称”; AddHeader(“内容处置”、“内联;文件名=“+pdfName+”.pdf”); Response.ContentType=“application/pdf”; Response.Buffer=true; Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache); 响应。二进制写入(字节); Response.End(); Response.Close(); }
通过这段代码,我能够创建一个3X4格式的PDF。
Mat这个答案将是完全有帮助的

我曾经使用过iTextSharp,也曾经使用过它。下面是我的代码

using iTextSharp.text;
using iTextSharp.text.pdf;
string shippingaddress = "My name is khan <br/>";
shippingaddress += "And I am not a terrorist<br/>";
        using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
        {            
            //Below code defines the PDF generate Size
            Rectangle newRect = new Rectangle(0, 0, 240, Convert.ToSingle(138.6));
            Document document = new Document(newRect,10f,10f,10f,10f);
            Document.Compress = true;
            PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
            document.Open();
            Font boldFont = new Font(Font.FontFamily.HELVETICA, 12,Font.BOLD);
            Paragraph para = new Paragraph("Header", boldFont);
            document.Add(para);
            string text = shippingaddress.Replace("<br/>", "\n");
            Paragraph paragraph = new Paragraph();
            paragraph.SpacingBefore = 2;
            paragraph.SpacingAfter = 2;
            paragraph.Leading = 12;
            paragraph.Alignment = Element.ALIGN_LEFT;
            paragraph.Font = FontFactory.GetFont(FontFactory.HELVETICA, 12f,BaseColor.BLACK);
            paragraph.Add(text);
            document.Add(paragraph);
            document.Close();
            byte[] bytes = memoryStream.ToArray();
            memoryStream.Close();
            Response.Clear();
            Response.ContentType = "application/pdf";
            string pdfName = "Movie Name";
            Response.AddHeader("Content-Disposition", "inline; filename=" + pdfName + ".pdf");    
            Response.ContentType = "application/pdf";
            Response.Buffer = true;   
            Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
            Response.BinaryWrite(bytes);
            Response.End();
            Response.Close();    
        }
使用iTextSharp.text;
使用iTextSharp.text.pdf;
string shippingaddress=“我的名字是khan
”; shippingaddress+=“我不是恐怖分子
”; 使用(System.IO.MemoryStream MemoryStream=new System.IO.MemoryStream()) { //下面的代码定义了PDF生成大小 矩形newRect=新矩形(0,0,240,Convert.ToSingle(138.6)); 文档=新文档(newRect、10f、10f、10f、10f); Document.Compress=true; PdfWriter writer=PdfWriter.GetInstance(文档,内存流); document.Open(); Font boldFont=新字体(Font.FontFamily.HELVETICA,12,Font.BOLD); 段落段落=新段落(“标题”,粗体); 文件.增补(第6段); 字符串文本=发货地址。替换(“
,“\n”); 段落=新段落(); 段落.SpacingBefore=2; 第1.2段间隔时间=2; 前导段=12; 段落对齐=Element.ALIGN_LEFT; 段落.Font=FontFactory.GetFont(FontFactory.HELVETICA,12f,BaseColor.BLACK); 添加(案文)段; 文件.添加(第段); document.Close(); byte[]bytes=memoryStream.ToArray(); memoryStream.Close(); Response.Clear(); Response.ContentType=“application/pdf”; 字符串pdfName=“电影名称”; AddHeader(“内容处置”、“内联;文件名=“+pdfName+”.pdf”); Response.ContentType=“application/pdf”; Response.Buffer=true; Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache); 响应。二进制写入(字节); Response.End(); Response.Close(); }
通过这段代码,我能够创建一个3X4格式的PDF。 这个答案将是完全有帮助的