Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Jul 20, 2016 6:55 am

Hello

I want to insert an existing PDF (A4) into another PDF (a4), but i want to resize the PDF bevor.

I thank you in advance for the help

GHWels
 
Posts: 90
Joined: Sun Nov 23, 2014 7:22 pm

Wed Jul 20, 2016 8:10 am

Dear GHWels,

Thanks for your inquiry.
Here is sample code for your reference:
Code: Select all
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(FilePath + "sample1.pdf");           
            PdfDocument newPdf = new PdfDocument();           
            foreach (PdfPageBase page in doc.Pages)
            {
                //Create a new PDF page with Page size =A4 and PDFMargins at 0.
                PdfPageBase newPage = newPdf.Pages.Add(PdfPageSize.A4, new PdfMargins(0));
                PdfTextLayout loLayout = new PdfTextLayout();
                loLayout.Layout = PdfLayoutType.OnePage;

                //Copy the contents of page into the new PDF page at the PointF(0,0)
                page.CreateTemplate().Draw(newPage, new PointF(0, 0), loLayout);
            }
            //save the resized PDF to stream
            MemoryStream s = new MemoryStream();
            newPdf.SaveToStream(s);
           
            //open another PDF
            FileStream s1 = File.OpenRead(FilePath + "sample2.pdf");
            Stream[] streams = { s1, s };
            //merge documents by stream
            PdfDocumentBase resultPdf = PdfDocument.MergeFiles(streams);
            resultPdf.Save("8145.pdf", FileFormat.PDF);

Hope this can help you. If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Jul 21, 2016 6:07 am

Thank you. It works fine

GHWels
 
Posts: 90
Joined: Sun Nov 23, 2014 7:22 pm

Thu Jul 21, 2016 6:21 am

Dear GHWels,

Thanks for your feedback.
Welcome to write to us again for further question. We are here for help.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.PDF