在内存流中另存为pdf [英] Save as pdf in memorystream

查看:66
本文介绍了在内存流中另存为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用itextsharp将段落保存到内存流中,因为pdf

但是我不工作原因?

i am using itextsharp to save a paragraph in to the memorystream as pdf
but i dont work why?

     private void buttonSkrivUt_Click(object sender, EventArgs e)
        {

            using (MemoryStream ms = new MemoryStream())
            {

                Document document = new Document(PageSize.A4, 25, 25, 30, 30);
;
                PdfWriter writer = PdfWriter.GetInstance(document, ms);

                document.Open();
             
                document.Add(new Paragraph("hej"));

                document.Close();

                writer.Close();
            
             
            }

            
        }





这个仅作品。



>



This works only.

>

                Document document = new Document(PageSize.A4, 25, 25, 30, 30);
;
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("test.pdf", FileMode.Create));
                //PdfWriter writer = PdfWriter.GetInstance(document, ms);

                document.Open();
             
                document.Add(new Paragraph("hej"));

                document.Close();

                writer.Close();

推荐答案

使用MemoryStream时需要返回一些内容。执行此操作的最佳方法是返回一个数组。这样你就得到了字节[]



You need to return something to work with when using MemoryStream. The best way to do this is to return an array. This way you get the byte[]

using (MemoryStream ms = new MemoryStream())
{
    Document document = new Document(PageSize.A4, 25, 25, 30, 30);
    PdfWriter writer = PdfWriter.GetInstance(document, ms);
    document.Open();
    document.Add(new Paragraph("hej"));
    document.Close();
    writer.Close();

    return ms.ToArray();
}





PS我不是故意听起来你不知道区别



PS I did not mean to sound like you did not know the difference


这篇关于在内存流中另存为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆