PDFPage vs PDFLoadedPage

Hi All!

I'm trying to implement Layout on a text added to an existing PDF since the text overflows the current margins of the paper.

The problem remains on the fact that the loaded PDF is being signed, and all operations are conducted on PDFLoadedPage, when I get an error &80004002 ("cannot convert Syncfusion.Pdf.Pdfloadedpage to type Syncfusion.PDF.PDFPage").

Basically the code is:


Dim page As PdfPageBase = 
loadedDocument.Pages(loadedDocument.Pages.Count - 1)

Dim Line as Single = 10
Dim W as Single = 500
Dim H as Single = 800​

Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 8)


Dim textElement As PdfTextElement = New PdfTextElement("This is a sample of text that cannot be correctly set into two lines of the page", font)

Dim layoutResult As PdfLayoutResult = textElement.Draw(page, New RectangleF(10, Line, W, H))

So, how to perform an advanced text layout  during the digital-signing of a PDF to fix big text in many lines?

Thanks in advance.


3 Replies

IJ Irfana Jaffer Sadhik Syncfusion Team May 11, 2022 02:28 PM UTC

Hi DavidBS,


We don't have support to draw TextElement with layout text by using PdfLoadedPage instance .Instead, we can able to achieve your requirement of drawing text with layout preserved using DrawString Method of PdfGraphics class.we have attached a sample to draw a text using DrawString Method with the output document for your reference. Please try this in your end and let us know if it satisfies your requirement.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ConsoleSample819857021

Document: https://www.syncfusion.com/downloads/support/directtrac/general/pd/Output-941219662


Please refer to the following link for more information,

https://help.syncfusion.com/file-formats/pdf/working-with-text


Please let us know if you need any further assistance in this.


Regards,

Irfana J.



DA DavidBS May 12, 2022 02:01 PM UTC

Hi Irfana!


Hmmm... I guess I was not clear enough.

My problem is not to set the text in different lines but how to correctly set a big paragraph text into a page without the need to create it in DOC mode and has to convert it after.

Anyway, my point is: why PDFTEXTELEMENT (that makes it!) cannot be utilized with PDfLoadedPage, which is required to sign a document digitally? We cannot add a page with free text and METADATA and sign the paper in a single step.

And, if possible, which will be a way to bypass this limitation?


Regards,

David



IJ Irfana Jaffer Sadhik Syncfusion Team May 13, 2022 01:11 PM UTC

Hi DavidBS,


As we have already said we provide support to draw large text with PdfTextElement but only with PdfPage Instance. For an existing document we should use DrawString Method from page graphics to draw the text with different PdfStringformat constraints. We have attached the code snippet to draw the text element in an existing document. Please try this in your end and let us know if it satisfies your requirement.



PdfLoadedDocument document = new PdfLoadedDocument("../../Data/input.pdf");
PdfPageBase page = document.Pages[document.Pages.Count - 1];


PdfGraphics graphics = page.Graphics;


PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 8);


//Create a new PDF string format instance.
PdfStringFormat format = new PdfStringFormat();
//Set the text alignment.
format.Alignment = PdfTextAlignment.Center;
//Set the line alignment.
format.LineAlignment = PdfVerticalAlignment.Middle;
/Set word wrap type.
format.WordWrap = PdfWordWrapType.Word;
String text = "This is a sample of text that cannot be correctly set into two lines of the page";


graphics.DrawString(text, font, PdfBrushes.Black, new PointF(0, 0),format);


document.Save("../../../Output.pdf");
document.Close();


Please follow the below links for more information:
https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Graphics.PdfGraphicsElement.html


Please let us know if you need any further assistance in this.


Regards,
Irfana J.


Loader.
Up arrow icon