zoukankan      html  css  js  c++  java
  • From Single PDF template Make a series PDF

    Some Times we need make a series PDF from an single PDF template

    from above two article we know how to make an single pdf. and how to add page to new pdf.



    From some other actile of internet we may be get  writer.CopyAcroForm(reader)
    but i find just the last PDF(copy from the single pdf) have these values.
    other fields are empty

    Ok How to do it.
    MemoryStream stream = new MemoryStream();
                Document doc 
    = new Document();
                PdfCopy writer 
    = new PdfCopy(doc, stream);
                doc.Open();


                
    string path;
                path 
    = HttpContext.Current.Server.MapPath("~/templae.pdf");
                
    string sessionID = HttpContext.Current.Session.LCID.ToString();
                
    string path2 = HttpContext.Current.Server.MapPath("~/PDFTemplate/Temp" + sessionID + ".pdf");
                PdfImportedPage page;


                
    for (int i = 0; i < list.Count; i++)
                
    {

                    
    //MemoryStream itemStream = new MemoryStream();
                    FileStream itemStream = new FileStream(path2, FileMode.Create);
                    PdfReader reader 
    = new PdfReader(path);
                    
    int kk = reader.NumberOfPages;
                    PdfStamper stamper 
    = new PdfStamper(reader, itemStream);
                    AcroFields af 
    = stamper.AcroFields;

                    af.SetField(
    "CurrentDate", DateTime.Now.ToString());
                  
                    af.RenameField(
    "CurrentDate""CurrentDate_" + i);
                              stamper.Close();

                   
                    PdfReader pf 
    = new PdfReader(path2);

                    page 
    =  writer.GetImportedPage(pf, 1);
                    writer.AddPage(page);
                    page 
    = writer.GetImportedPage(pf, 2);
                    writer.AddPage(page);

                    pf.Close();

                  
                }

                File.Delete(path2); 
    /// delete the temp file
                doc.Close();
                
    return stream;


    as you see i am use filestream. i can't use MemoryStream. some error was occur.

    lovebanyi lookcode.net 风云

    如何去合并一个含有多个acroform数据的pdf
    How to merge more AcroForm .
  • 相关阅读:
    4g内存装64位WIN7好还是32位好(遇到问题,百度后解除疑惑)
    Windows Phone 7.5 “Mango”消息泄露 支持HTML5和Silverlight
    Tiobe发布2010年12月开发语言排名
    Adobe:Flash 10.2将全面提升性能
    ADO.NET Entity Framework使用实体数据
    使用GPU.NET针对GPU编程
    ADO.NET Entity Framework入门(实体框架)
    完美程序员的10种品质
    ADO.NET Entity Framework(实体框架)
    不适合当一名开发人员的10种迹象
  • 原文地址:https://www.cnblogs.com/lovebanyi/p/1202586.html
Copyright © 2011-2022 走看看