How can we crop a page to size of content

Hi,

We are trying to crop / minimize /fit pages in a pdf to size of the content on the page without any margins.

The pages are mostly a4 but should be shrinked to something like 30mm x 15mm - however varying from pdf to pdf. Also the content is not always aligned.

Please advise.

Best regards,

5 Replies

GK Gowthamraj Kumar Syncfusion Team November 13, 2020 01:40 PM UTC

Hi Johannes, 

Thank you for using Syncfusion products. 

We can able to create a PDF page based on the content size in a PDF document by using PDF library. We have to measure the size of the text content and set the resultant size to size and set the margin as zero to all the PDF pages of the PDF document using the PageSettings property. We have attached the sample and document for your reference. Kindly please try the sample in your end and let us know the result. 


Please refer to this below links for more information, 

If still you are facing an issue, kindly provide more details such as complete code snippet, output document, product version and modified sample to check the issue in our end. So, that it will be helpful for us to analyze and assist you further on this.   

Regards, 
Gowthamraj K 



MR MrHessellund November 15, 2020 07:48 AM UTC

Hi,

Thank you for the suggestion.

What I need is to crop/fit the content of an existing pdf.

With attached sample, I need an resulting pdf with page size of exact the content cropping all whitespace.

Thank you.

Best regards,


Attachment: result2.pdf_cac65bd4.zip


GK Gowthamraj Kumar Syncfusion Team November 16, 2020 12:04 PM UTC

  
Hi Johannes,  

Thank you for your update.  

We can able to create a PDF page based on the content size without white spaces in a PDF document by using PDF library. We have set the page height to the page settings of the PdfTemplate and it generates a PDF document properly. We have attached the sample and document for your reference. Kindly please try the sample in your end and let us know the result.  


Please refer to this below links for more information,  

If still you are facing an issue, kindly provide more details such as complete code snippet, output document, product version and modified sample to check the issue in our end. So, that it will be helpful for us to analyze and assist you further on this.    

Regards,  
Gowthamraj K 



MR MrHessellund November 16, 2020 12:24 PM UTC

Hi,

Thank you for the suggestion.

However, the sample uses a fixed height.

How can I analyse the width and height of the content in the loadeddocument ?

I need a dynamic cropping of the loadeddocuments which may differ from time to time in both height and width.

Best regards,


GK Gowthamraj Kumar Syncfusion Team November 17, 2020 01:58 PM UTC

Hi Johannes, 
 
We do not have support to detect the white space region and crop it from the PDF document. As a workaround, we can able to achieve your requirement with the help of another library's EMGU CV to identify the page content and create a new PDF document from the detected page content area. Kindly please try the sample and let us know the result.   
  
The sample illustrates the following steps,   
      1.     We need to convert each page into the bitmap image.   
      2.     Find the image content area by using the EMGU CV library.   
      3.     Created a template using the required image content size and drawn it with the required location.   
      4.     Create a new PDF document and draw all templates into the PDF document.   
 
Please find the sample from below link, 
 
Please try the above sample in your end let us know the result.     
  
Regards, 
Gowthamraj K 


Loader.
Up arrow icon