需要生成 PDF 并且是“3 X 4”格式

Need to generate PDF and that in "3 X 4" format

是否可以生成“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 中格式?

OI 已从 http://jsfiddle.net/5ud8jkvf/11511/ 获得此代码的参考,并且在此处正确生成了 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();    
        }

通过这段代码,我能够创建 3X4 格式的 PDF。 垫这个答案将帮助满