3
Answers

Read 2 pages from pdf and create other pdf with 1 page(like bookspread

kavya m

kavya m

2y
688
1

1.copy the whole thing(with images and lines) from first pdf and create second pdf  using hiqpdf.

2.In first pdf it has 1 page view but the second pdf  should have 2 page view.

3.So consider a example pdf contain 8 pages (it have sections A,B,C,D)

so copy A section from first pdf and hardcode the answer for  A section and include it in second pdf  like booklet view two page view

first page divided half it conatins section A question

Next Page  Section A answers in two way view page

Answers (3)
2
Lokesh Varman

Lokesh Varman

285 6.6k 263.7k 2y
// Create a new PDF document
PdfDocument pdfDoc = new PdfDocument();

// Read the first 2 pages of the existing PDF file
PdfDocument existingPdf = new PdfDocument("existing_file.pdf");
PdfPage firstPage = existingPdf.Pages[0];
PdfPage secondPage = existingPdf.Pages[1];

// Add the first page to the new PDF document
pdfDoc.Pages.Add(firstPage);

// Add the second page to the new PDF document, scaled and rotated to fit the page
PdfPage newPage = pdfDoc.AddPage();
PdfPageSize pageSize = newPage.Size;
PdfPageRotation pageRotation = newPage.Rotation;
PdfPageOrientation pageOrientation = newPage.Orientation;

PdfRectangle secondPageRect = new PdfRectangle(0, 0, pageSize.Width / 2, pageSize.Height);
PdfGraphics g = newPage.Graphics;
g.Save();
g.TranslateTransform(pageSize.Width / 2, 0);
g.ScaleTransform(0.5f, 1);
g.RotateTransform(90);
g.DrawImage(secondPage.CreateFormXObject(secondPageRect), secondPageRect);
g.Restore();

// Save the new PDF document
pdfDoc.Save("new_file.pdf");

// Close the new and existing PDF documents
pdfDoc.Close();
existingPdf.Close();
1
Marvin Reid

Marvin Reid

NA 576 149 2y

You can use the PDFFile class to combine the PDF pages and edit the look of the page. Here is some code you can build on:

 PDFFile file = new PDFFile(@"C:\inputfolder\input.pdf");

    for (int i = 1; i <= file.GetPageCount(); i++)
    {
        string destinationFileName = Path.Combine(@"C:\inputfolder", string.Format("Page{0}.pdf", i));
        file.ExtractPages(i, i, destinationFileName);  // extract different pages to pdf
    }

    file.ExtractPages(1, 2, @"C:\outputfolder\output.pdf"); // Copy over pages 1-2 to make the new pdf

https://www.leadtools.com/help/sdk/v22/dh/pdf/pdffile-extractpages.html
https://www.leadtools.com/help/sdk/v22/tutorials/dotnet-winforms-merge-pdf-files-to-single-pdf-file.html

1
kavya m

kavya m

NA 139 23k 2y

Using HIQPDF how to use graphics to create booklet view pdf from existing pdf ?

 

Below code is not working

PdfGraphics g = newPage.Graphics;

g.Save();

g.TranslateTransform(pageSize.Width / 2, 0);

g.ScaleTransform(0.5f, 1); g.RotateTransform(90);

g.DrawImage(secondPage.CreateFormXObject(secondPageRect), secondPageRect);

g.Restore();