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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Add text with dynamic length to a PdfLoadedDocument

Thread ID:





118554 Mar 18,2015 01:38 PM UTC Mar 24,2015 02:06 PM UTC ASP.NET Web Forms (Classic) 3
Tags: PDF
glenn paulsen
Asked On March 18, 2015 01:38 PM UTC

We have a program that reads an existing PDF from disc. That PDF tempalte contains text and form elements and converts it to a PDF/A document. We draw some text to the position where the form elements are positioned and then we delete the form elements. Then we do a PdfDocument.Merge(destPdfADoc, sourcePdfLoadedDoc) to merge the the PDF template with a PDF/A document. And that works great! The problem occurs when the text has dynamic length and it won’t fit into the available area.

  1. Is it possible to detect when the content does not fit the available area?
  2. Is there a nice solution to extend the number of pages (or similar) to fit the content?

Karthik Krishnaraj [Syncfusion]
Replied On March 19, 2015 03:04 PM UTC

Hi Glenn,

Thank you for using syncfusion products,

It is possible to “Extend the number of pages to fit the content”, for this you need to set PdfLayout type as Paginate, this will extend the pages until your content is fit. I have attached a simple sample regarding this in the below link, please check it.

Sample link:


For your another query about “Need to detect when the content doesn’t fit available area”, I have attached a simple sample, here we can get the bounds of the text after drawn in the page by using PdfTextElement class. By comparing the bounds of the text with page bounds we can able to detect whether the content will be fit into it. Can you please check with this and let me know if these helps.

Sample Link:




glenn paulsen
Replied On March 23, 2015 03:05 PM UTC

Thank you for your response.
I manage to fit the content now, but I get an InvalidCastException ("Unable to cast the object of type 'Syncfusion.Pdf.PdfPage' to type 'Syncfusion.Pdf.PdfLoadedPage’.") when trying to do a PdfDocument.Merge(destLoadedDocument, sourceLoadedDocument). The newly added page to the sourceLoadedDocument gets the type PdfPage while the other pages has the type PdfLoadedPage.

Is there a way to merge/append/insert pages from the sourceLoadedDocument to the destLoadedDocument when one of the pages is of type PdfPage while the rest of the pages is of type PdfLoadedDocument?

Karthik Krishnaraj [Syncfusion]
Replied On March 24, 2015 02:06 PM UTC

Hi Glenn,

Thank you for your patience,

Yes, It is possible to Merge “sourceLoadedDocument to the destLoadedDocument”, I have attached a simple sample regarding this, can you please check with this and let us know if these helps.

And for your query regarding “Exception occurs while trying to Merge Loaded documents”, can you please provide us the code snippet which causes the exception, this will help us to provide better solution.

Sample Link:





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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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