是否可以按“3 X 4”形式生成pdf?
我已尝试过如下代码,但未生成PDF,我从here下载了JSPDF.min
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/jspdf.min.js"></script>
<script>
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
$('#cmd').click(function () {
doc.fromHTML($('#content').html(), 15, 15, {
'width': 170,
'elementHandlers': specialElementHandlers
});
doc.save('sample-file.pdf');
});
</script>
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>
这是我的页面中的代码,我无法创建PDF 以及如何生成PDF如何以 3X4格式显示?< / p>
OI已从http://jsfiddle.net/5ud8jkvf/11511/获得此代码的引用,此处PDF正确生成,我缺少什么?
答案 0 :(得分:0)
我曾使用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();
}
通过此代码,我能够使用3X4格式创建PDF。 Mat这个答案将是完整的帮助