How to merge pdf and and .jpg file in new pdf

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

How to merge pdf and and .jpg file in new pdf

This post was updated on .
There are two files on disk .jpg and .pdf, i need to read both files and add them to new pdf and send to browser so that it can be downloaded.

New pdf file only contains pdf contents not jpeg file image.

               memoryStream myMemoryStream = new MemoryStream();

            //----pdf file--------------

            iTextSharp.text.pdf.PdfCopy writer2 = new iTextSharp.text.pdf.PdfCopy(doc, myMemoryStream);


            iTextSharp.text.pdf.PdfReader reader = new iTextSharp.text.pdf.PdfReader(imagepath + "/30244.pdf");

            for (int i = 1; i <= reader.NumberOfPages; i++) {
                    iTextSharp.text.pdf.PdfImportedPage page = writer2.GetImportedPage(reader, i);

            iTextSharp.text.pdf.PRAcroForm form = reader.AcroForm;
            if (form != null) {

            //-----------------jpeg file-------------------------------------
            MemoryStream myMemoryStream2 = new MemoryStream();
            System.Drawing.Image image = System.Drawing.Image.FromFile(imagepath + "/Vouchers.jpg");
            iTextSharp.text.Document doc2 = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4);
            iTextSharp.text.pdf.PdfWriter.GetInstance(doc2, myMemoryStream2);
            iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(image, System.Drawing.Imaging.ImageFormat.Jpeg);

            byte[] content = myMemoryStream.ToArray;

            Response.ContentType = "application/pdf";
            Response.AppendHeader("Content-Disposition", "attachment; filename=LeftCorner568.pdf");