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 .
  • 相关阅读:
    阿里云安装Mono 发生错误解决方法
    在Entity Framework 中执行Tsql语句
    WinRT app guide
    开源稳定的消息队列 RabbitMQ
    Catpic: OpenSocial Container on .NET
    MSDTC 故障排除
    HTML5 canvas图形库RGraph
    《我的WCF之旅》博文系列汇总
    TSQL Enhancement in SQL Server 2005[下篇]
    谈谈基于SQL Server 的Exception Handling[上篇]
  • 原文地址:https://www.cnblogs.com/lovebanyi/p/1202586.html
Copyright © 2011-2022 走看看