We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Merge two PDF in one

Hello Everyone,

I have one doubt that i am merging two pdf where one is system generated pdf using aspose dll which contains some dynamic data from my system and another my saved pdf document now i want to attached both and save as single pdf.

but the the data comes little croped in second pdf

here i am attaching image of my final out put pdf
my code is like :

Aspose.Pdf.License pdfLic = new Aspose.Pdf.License();
pdfLic.SetLicense(HttpContext.Current.Server.MapPath("~/bin/Aspose.Pdf.lic"));

    Document pdfDocument = new Document();
    Aspose.Pdf.Page page = pdfDocument.Pages.Add();
    page.SetPageSize(PageSize.A4.Width, PageSize.A4.Height);
    pdfDocument.ProcessParagraphs();

    //page margin to reduce white space from left and right side
    page.PageInfo.Margin.Left = 20f;
    page.PageInfo.Margin.Right = 20f;

    HtmlFragment htmlfragment;

    //Header HTML LTHE Logo & Client Logo and Test Sheet name
    string HeaderHTML = @"<table style='width:100%'>
                                <tr>
                                    <td>
                                    <table width='100%' border='1px solid #000' cellspacing='0' style='font-size: 16px;'>
                                        <tr>
                                            <td style='border-right: 1px solid #000; text-align:center; width:25%'><img style='width: 100%;' src='" + HttpContext.Current.Server.MapPath("~/images/Offshore_Logo/Aramco.png") + @"'/></td>
                                            <td style='text-align: center; width:50%'>SAIC - A -2007 <br/> Saudi Aramco Instrumentation Completion <br/> </td>
                                            <td style='border-left: 1px solid #000; text-align:right; width:25%'><img style='width: 100%;' src='" + HttpContext.Current.Server.MapPath("~/images/Offshore_Logo/LTHEEMASLogo.png") + @"'/></td>
                                        </tr>
                                    </table>
                                    <table style='float:right'>
                                        <tr>
                                            <td style='font-weight:bold'>
                                                Revision No:
                                            </td>
                                            <td>
                                                " + revisionNo + @"
                                            </td>
                                        </tr>
                                    </table> 
                                    </td>
                                </tr>
                                </table>";

if (!string.IsNullOrEmpty(HeaderHTML.ToString()))
{
htmlfragment = new HtmlFragment(HeaderHTML.ToString());
htmlfragment.Margin.Bottom = 20f;
page.Paragraphs.Add(htmlfragment);
}

pdfDocument.ProcessParagraphs();

    // Open second document
    Document pdfDocument1 = new Document(HttpContext.Current.Server.MapPath(PDF_FilePath));

pdfDocument.Pages.Add(pdfDocument1.Pages);

    //Download pdf Code

    MemoryStream stream = new MemoryStream();
    string Path = HttpContext.Current.Server.MapPath("~/Commissioning/Documents/List/Hasbah/PDF/TEMP/Test.pdf");
    pdfDocument.Save(stream);
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.ClearHeaders();
    HttpContext.Current.Response.ClearContent();
    HttpContext.Current.Response.Charset = "UTF-8";
    HttpContext.Current.Response.AddHeader("Content-Length", stream.Length.ToString());
    HttpContext.Current.Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", "Test_TestSheet.pdf"));
    HttpContext.Current.Response.ContentType = "application/pdf";
    HttpContext.Current.Response.BinaryWrite(stream.ToArray());
    HttpContext.Current.Response.Flush();
    HttpContext.Current.Response.End();

    return string.Empty;

Test_TestSheet (15).pdf (215.0 KB)

@Vivek5thquarter,

We have tested your scenario with the latest version 18.2 of Aspose.PDF for .NET API. This is the output PDF: Output.pdf (274.7 KB). Kindly highlight the problematic area with the help of a snapshot.

Hello Imran,

Thank you for reply.

In your “OUTPUT” file you can check from the third page which is actually my another PDF that need to be merge with first one,

In Third page, the contents are going touch to the right side of the page. where i need to set margin for that so it looks better

here i am attaching my second PDF that need to be merge where it looks good but after merging the contents are cutting down

SAIC-A-2007.pdf (136.4 KB)

@Vivek5thquarter,

We managed to replicate the problem of misaligned content of the second PDF. It has been logged under the ticket ID PDFNET-44276 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

Hello Imran,

Thank you for replying.

waiting for positive reply…

@Vivek5thquarter,

We send notifications to the clients regarding their each resolved ticket ID. We will let you know once it is fixed.