We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Resize pages in order to fit on A4 when printing

Thread ID:

Created:

Updated:

Platform:

Replies:

128438 Jan 21,2017 05:04 PM UTC Jan 23,2017 12:26 PM UTC Windows Forms 1
loading
Tags: PDF
Jesper Andersen
Asked On January 21, 2017 05:04 PM UTC

Hi,

I am making an application that is merging pages from different existing PDF documents and afterwards saving to a new PDF document, which is silent printed.

My problem is that some of the merged pages isn't A4 format. I want to either resize when creating the new PDF, or resize when the new PDF is printed.
Can you please help with any solution on this?

Code used for merging pages into new PDF:
PdfDocument PdfToPrint = new PdfDocument();
PdfToPrint.PageSettings.Size = PdfPageSize.A4;

PdfLoadedDocument LoadedPdf = new PdfLoadedDocument(Filepath);
PdfToPrint.ImportPageRange(LoadedPdf, FromPage - 1, ToPage - 1);

PdfToPrint.Save("Generated files/" + Itemnumber + ".pdf");

Code used for printing the new PDF:
PdfDocumentView viewer = new PdfDocumentView();
viewer.Load("Generated files/" + filename + ".pdf");

PrintDialog dialog = new PrintDialog();
dialog.Document = viewer.PrintDocument;

dialog.Document.Print();

viewer.Dispose();

Sasi Kumar Sekar [Syncfusion]
Replied On January 23, 2017 12:26 PM UTC

Hi Jesper, 

Thank you for contacting Syncfusion support, 

We can achieve your requirements by adding the all PDF documents into the single PDF document in A4 size using the PdfTemplate. We have created the simple sample for your requirement. Please find the code snippet and sample for your reference. 

Cod snippet: 
//Gets the file directory 
  String[] inputDocuments = Directory.GetFiles("../../Data/"); 
 
//Creates a new instance. 
  PdfDocument document = new PdfDocument(); 
 
  document.PageSettings.Size = PdfPageSize.A4; 
  document.PageSettings.Margins.All = 0; 
 
//Optimizes memory while merging PDF documents. 
  document.EnableMemoryOptimization = true; 
 
//Iterates input PDF documents. 
  foreach (string inputDocument in inputDocuments) 
   { 
     //Loads PDF document in order to merge. 
     PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputDocument); 
     loadedDocument.EnableMemoryOptimization = true; 
 
    //Merges loaded document contents to the parent PDF document.  
    for (int i = 0; i < loadedDocument.Pages.Count; i++) 
      { 
         PdfPage page = document.Pages.Add(); 
         PdfGraphics g = page.Graphics; 
         PdfPageBase lpage = loadedDocument.Pages[i]; 
         PdfTemplate template = lpage.CreateTemplate(); 
         g.DrawPdfTemplate(template, System.Drawing.PointF.Empty, g.Size); 
      }                
               
       //Closes the document. 
       loadedDocument.Close(true) 
 
   } 
   //Saves and closes the document. 
   document.Save("Output.pdf"); 
   document.Close(true);        

Sample link: 

Please let us know if you need further assistance. 

Regards, 
Sasi Kumar S. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;