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. Image for the cookie policy date

Add text with dynamic length to a PdfLoadedDocument

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?

3 Replies

KK Karthik Krishnaraj Syncfusion Team 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:




GP glenn paulsen 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?

KK Karthik Krishnaraj Syncfusion Team 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:




Live Chat Icon For mobile
Up arrow icon