2011-10-15 16 views
6

मैं rdlc रिपोर्ट से 2 पीडीएफ डेटा को संयोजित करने का प्रयास करता हूं।पीडीएफ फाइलों के साथ पीडीएफ फाइलों को सम्मिलित करें रिक्त पृष्ठ

समस्या यह है कि परिणाम रिक्त पृष्ठ हैं।

मुझे नहीं पता क्यों, कोई मेरी मदद कर सकता है।

private ActionResult ConcatPdf(byte[] pdfData1, byte[] pdfData2) 
{ 
    MemoryStream ms1 = new MemoryStream(pdfData1); 
    MemoryStream ms2 = new MemoryStream(pdfData2); 

    PdfDocument inputDoc1 = PdfReader.Open(ms1, PdfDocumentOpenMode.Import); 
    PdfDocument inputDoc2 = PdfReader.Open(ms2, PdfDocumentOpenMode.Import); 

    PdfDocument outputDoc = new PdfDocument(); 

    foreach (PdfPage page in inputDoc1.Pages) 
    { 
     outputDoc.AddPage(page); 
    } 

    foreach (PdfPage page in inputDoc2.Pages) 
    { 
     outputDoc.AddPage(page); 
    } 

    MemoryStream outputMs = new MemoryStream(); 
    outputDoc.Save(outputMs); 

    return File(outputMs.ToArray(), "application/pdf"); 
} 

में उत्पन्न इस तरह रिपोर्ट समारोह देखो:

public ActionResult TestPDF(int id) 
{ 
    // Set report path. 
    LocalReport rep = viewer.LocalReport; 
    rep.ReportPath = Server.MapPath("~/Reports/rptExternalTransferIndividual.rdlc"); 
    rep.DataSources.Clear(); 


    // 
    // Set data and parameter to report. 
    // 
    ... 
    ... 

    return ConcatPdf(viewer.LocalReport.Render("PDF"), viewer.LocalReport.Render("PDF")); 
} 

उत्तर

1

हो सकता है कि वहाँ कुछ रिपोर्ट व्यूअर से उत्पन्न पीडीएफ फाइलों के बारे में असामान्य

यहाँ मेरी कोड है। हमें इसे जांचने के लिए नमूना फाइलों की आवश्यकता है।

यह भी देखें:

http://forum.pdfsharp.net/viewtopic.php?f=3&t=1818&p=5174

http://forum.pdfsharp.net/viewtopic.php?f=3&t=1730

+0

इसके लिए धन्यवाद, मुझे रिपोर्ट व्यूअर जेनरेट किए गए पीडीएफ के साथ एक ही समस्या का सामना करना पड़ रहा था और दूसरी लिंक में दी गई जानकारी ने इसे तय किया ... ब्याज से, क्या यह पुस्तकालय के भविष्य के संस्करण में शामिल किया जाएगा? – wheelibin

0

मैं iTextSharp का उपयोग एक ही बात करते हैं।

समान पैरामीटर पास करना -> दर्शक.लोकल रिपोर्ट.रेंडर ("पीडीएफ")। यह अच्छी तरह से काम करता है।

private ActionResult ConcatPdf(List<byte[]> pdfDataList) 
{ 
    MemoryStream outputMS = new MemoryStream(); 
    Document document = new Document(); 
    PdfCopy writer = new PdfCopy(document, outputMS); 
    PdfImportedPage page = null; 

    document.Open(); 

    foreach (byte[] pdfData in pdfDataList) 
    { 
     PdfReader reader = new PdfReader(pdfData); 
     int n = reader.NumberOfPages; 

     for (int i = 1; i <= n; i++) 
     { 
      page = writer.GetImportedPage(reader, i); 
      writer.AddPage(page); 
     } 

     PRAcroForm form = reader.AcroForm; 
     if (form != null) 
      writer.CopyAcroForm(reader); 
    } 

    document.Close(); 

    return File(outputMS.ToArray(), "application/pdf"); 
} 
5

मैं जानता हूँ कि यह पुराना है, लेकिन HumanReadablePDF जोड़ें::

string deviceInfo = "<DeviceInfo>" + 
        " <OutputFormat>PDF</OutputFormat>" + 
        " <PageWidth>29.7cm</PageWidth>" + 
        " <PageHeight>21cm</PageHeight>" + 
        " <MarginTop>0cm</MarginTop>" + 
        " <MarginLeft>0cm</MarginLeft>" + 
        " <MarginRight>0cm</MarginRight>" + 
        " <MarginBottom>0cm</MarginBottom>" + 
        " <HumanReadablePDF>True</HumanReadablePDF>" + 
        "</DeviceInfo>"; 

    byte[] reportBytes = LocalReport.Render(
       "PDF", deviceInfo, out mimeType, out encoding, 
       out extension, 
       out streamids, out warnings); 

फिर PdfSharp को बाइट सरणी लौट

यहाँ मेरी कोड है।

+0

यह मेरे लिए काम किया। धन्यवाद! –

+1

यदि आप सभी आयामों को संशोधित नहीं करना चाहते हैं, तो यह मेरे लिए केवल '<आउटपुटफॉर्मैट> पीडीएफ True" के साथ काम करता है। –

संबंधित मुद्दे