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

Clipping don''t work with DrawMultiText()

Hi,

i have a problem with clipping using DrawMultiText() method:

PdfDocument.LastPage.DrawMultiText(rect.Location, rect.Size, textValue, textFont, clipRect, textState)


The clipping don't work when then "size parameter" (rect.Size) contain a value smaller than the real size of text (textValue) and this don't produce any result: the text is not printed! Why?

For me, if the size passed is smaller than the text real size, the result could be a text clipped and not any result.

How can i clip a text using the DrawMultiText() method if i don't know the length of text?


Anybody can help me?


Thanks,
Stefano


Ps = excuse me for my not perfect english.

22 Replies

SD Sarathi D Syncfusion Team September 8, 2007 01:53 AM UTC

Hi Stefano,

We are currently looking into this issue. I will update you the status of the issue within two business days.

Sorry for the inconvenience caused.

Regards,
Sarathi


SD Sarathi D Syncfusion Team September 11, 2007 01:11 AM UTC

Hi Stefano,

Thank you for the details provided.

I am afraid that i am not able to reproduce the issue that you have mentioned. I have created a sample to test this issue and it works fine. The sample is available in the following link.

http://websamples.syncfusion.com/samples/PDF.Windows/68072/main.htm

Please have a look at the above sample and if still the issue exists, could you please try reproducing it in the above sample or send us the reproducing steps so that we could sort out the cause of the issue
and provide you a solution?

Regards,
Sarathi




SM Stefano Montimoregi September 11, 2007 07:33 AM UTC

Hi Sarathi,

Thank you for your quick answer to my issue.

In the sample that you have created, the text is multi-line and so the text wrap correctly. But my text sample is not a wrap text: the text must be write in a single line.

In the attachment I write 3 code sample:
- The first is your sample code.
- The second is my sample code that don't work and the result is an empty text.
- The third is my aspected sample code (...using DrawText method)

I hope that my sample really show the issue.

Thank you so much.

Regards,
Stefano

Stefano Clipping Sample.zip


SD Sarathi D Syncfusion Team September 11, 2007 11:46 PM UTC

Hi Stefano,

Can you please create a direct trac incident in this regard since this is suspected to be a defect and we can discuss further on this issue.

Please specify the Forum Id in the subject line of the incident.

Regards,
Sarathi


SM Stefano Montimoregi September 12, 2007 07:02 AM UTC

Hi Sarathi,

i can't create a direct trac incident in this regard because i'm not a Syncfusion customer under subscription yet! I'm still working with Syncfusion trial version and, before buy your product, i want to verify all features that I need.

When I create a Pdf file, the text clipping is an essential feature and I can't use your product without it.

I hope you can resolve my problem and than i can proceed with Syncfusion Essential purchase.


Regards,
Stefano


KH Kevin Hector September 19, 2007 01:00 PM UTC

I am interested in this solution. It appears to use PDFDocument rather thasn PdfDocument (note the capitalisation). PDFDocument is in assembly syncfusion.pdf.legacy.base.dll.

Assuming this assembly is indeed legacy code to provide backward compatibility, do Syncfusion recommend the use of legacy implementations in new projects?


SM Stefano Montimoregi September 20, 2007 10:12 AM UTC

Hi Sarathi,

I need a solution for my problem!

I want to resolve my problem using SyncFusion but if you don't answer at this post I can't use SyncFusion and so i must proceed to try other tools (for example aspose).


Anybody of SyncFusion Team can help me???


Regards,
Stefano


MS Mohamed Suhaib Fahad A. Syncfusion Team September 21, 2007 02:23 PM UTC

Hi Stefano,

We regret for the delay in responding you.

We recommend you to use new library for any new development work since it will be actively supported and enhanced. Version 5.2 of Essential PDF is a complete rewrite, so the APIs are not compatible with the previous version of Essential PDF. The new PDF implements a much more flexible api model. However, the old functionalities will be implemented in our new PDF over the next release of ES.

Please download latest version from the following link.

http://www.syncfusion.com/downloads/latestversion/default.aspx

Please refer the sample that clips multiline text using new PDF assemblies and let us know if this helps you.

http://websamples.syncfusion.com/samples/PDF.Windows/F68072_Sep21/main.htm

Also refer resulted PDF in the below location.

http://www.syncfusion.com/Support/user/uploads/PDFClip_11c6a2d0.zip

Kindly let us know if you have any other queries.

Regards,
Fahad


SM Stefano Montimoregi September 24, 2007 09:55 AM UTC

Hi Fahad,


i'm re-writing my code using the new version of Essential Pdf (5.2).

I've a question...how can i set the direction of a text? How can i set the text orientation to 90°?


Regards,
Stefano


MS Mohamed Suhaib Fahad A. Syncfusion Team September 24, 2007 01:31 PM UTC

Hi Stefano,

You can use the RotateTransform method of Graphics object for text direction.

Please refer the below code snippet to do so.
//Add a page
PdfPage page = doc.Pages.Add();

//Create Pdf graphics for the page
PdfGraphics g = page.Graphics;

g.TranslateTransform(100.0f, 100.0f);
//Text Direction
g.RotateTransform(90);
g.DrawString("Text Direction at 90 degre", font, brush, PointF.Empty);

page.Layers.Add();
page.DefaultLayerIndex += 1;
g = page.DefaultLayer.Graphics;

g.TranslateTransform(200, 200);
g.RotateTransform(45);
page.Graphics.DrawString("Text Direction at 45 degree", font, brush, PointF.Empty);

Please download the sample from the below location
http://websamples.syncfusion.com/samples/PDF.Windows/F68072/main.htm

Please let me know if you have any other queries.

Thanks,
Fahad


SM Stefano Montimoregi September 28, 2007 03:29 PM UTC

Hi Fahad!

I have another one question for you...

how can I draw a string that contains the character "€"?

This is my sample code:

Dim pdfText As New PdfTextElement()
pdfText.Font = New PdfTrueTypeFont("Arial", 10)

pdfText.Pen = GetPen(...)
pdfText.Text = "€"

pdfText.Draw(currentPage, rect)


When I call the Draw method it throws this exception:

"Couldn't find information about the character. Unicode is not supported by this font."


How can i resolve my problem?


Thanks


Regards,
Stefano


MS Mohamed Suhaib Fahad A. Syncfusion Team October 2, 2007 06:32 AM UTC

Hi Stefano,

Thanks for the details.

Please do the below font settings to avoid the exception you faced.

[C#]
Font f = new Font("Arial", 12);
PdfTrueTypeFont font = new PdfTrueTypeFont(f, true);
element.Font = new PdfTrueTypeFont(font, 12);

Please refer the sample below and let us know if you have any other queries.

http://websamples.syncfusion.com/samples/PDF.Windows/F68072_Oct2/main.htm

Regards,
Fahad


SM Stefano Montimoregi October 2, 2007 08:11 AM UTC

Hi Fahad,

I have two question for you...

1) I have implemented my code for rotate my string...

but...why the PdfTextElement Draw method don't have a parameter that contains the angle to rotate the text (only the more diffuse...90 ,180 ,270)? Why every single programmer that use Syncfusion must implement the code that manage the text direction? For me this is a future that the Draw method could have...this is only my opinion...you don't think so?

2) I've not resolve my clipping problem! Your sample contains a text that use wordwrap...but wrap is not clipping! The clipping could be as the old DrawString method (see my first attachment..). How can I draw a text in a single line (no more...i don't want the wrap) that is clipped when the rect layout is finished? I attach a sample that show how is impossible draw a text in a single line with a real clipping...



I hope you have a solutin for my problem.


Regards,
Stefano

NewStefanoClipping.zip


MS Mohamed Suhaib Fahad A. Syncfusion Team October 3, 2007 11:27 AM UTC

Hi Stefano,

Thanks for the update and sample. We can do a little bit more tweaking and get the expected result. Please check out the following responses for your query,

1) Layers are used for text rotation

We can avoid layer for text rotation and we can use the following to rotate two strings. We use PdfGraphics and PdfGraphicState to rotate string or any element. Why we are using single graphics state for whole page, to avoid creating more graphics object for to reduce the memory and maintain single state for whole page.

//Save the initial state
PdfGraphicsState state1 = g.Save();
g.TranslateTransform(100.0f, 100.0f);
g.RotateTransform(90);
g.DrawString("Text Direction at 90 degre", font, brush, PointF.Empty);

//Restore old state
g.Restore(state1);

g.TranslateTransform(100, 200);
g.RotateTransform(45);
g.DrawString("Text Direction at 45 degree", font, brush, PointF.Empty);

2) Similarly to clip the text, we can make use of SetClip method of PdfGraphics.

Rectangle rect = new Rectangle(50, 50, 120, 35);
PdfRectangle pdfRect = new PdfRectangle(rect);
g.SetClip(rect);

//Clip simple string
// g.DrawString("Stefano Clipping sample", new PdfStandardFont(PdfFontFamily.Helvetica, 12), PdfBrushes.Black, rect);
pdfRect.Draw(page,0,0);

//Clip large string
element.Draw(g,50,50);

This will allow to clip the data without any wrapping the text.

Also, setting the below statement will avoid text wrapping and clipping. However, it will clip based on the words. and not with character.

format.WordWrap = PdfWordWrapType.None;
element.StringFormat = format;
element.Draw(page, rect2);

Please download the modified sample from the below link
http://websamples.syncfusion.com/samples/PDF.Windows/F68072_3/main.htm

Please let me know if you want any more details.

Regards,
Fahad


SM Stefano Montimoregi October 4, 2007 09:08 AM UTC

Hi Fahad,

Thanks for your quickly reply.

I'm sorry but i've not resolve my problem with your clipping mode. Your sample works fine because the text has spaces ("Stefano clipping sample"); in this case the text is clipped at the correct space. But if the string has not spaces (for example "StefanoClippingSampleWithoutSpaces") the string was not clipped and printed. The clipping could works fine always, with or without spaces. If the string is bigger than the layout rect the result could be the string clipped in the layout rect (both in height and width) not the text clipped at the space!

In the previous SyncFusion runtime (now Syncfusion.pdf.legacy.dll!) the clipping works fine! In the attachment I show you the same pdf created with the new release and with the legacy dll!

Excuse me but this issue is so much important for my company...we want buy and use (if it works!) your product and re-distribute it to 10.000 final users! Now it is not possible.

Thanks


Regards,
Stefano



NewStefanoClipping2.zip


MS Mohamed Suhaib Fahad A. Syncfusion Team October 5, 2007 11:13 AM UTC

Hi Stefano,

Thanks for the update and sample.

We are able to see the issue. Could you please open a new direct – trac incident to Subject line contains the forum id and issue title like below.

Clipping don't work with DrawMultiText() - F68072.

so that we could provide more details regarding the fix?

Thank you for your interests in Syncfusion products.

Regards,
Fahad


MS Mohamed Suhaib Fahad A. Syncfusion Team October 8, 2007 06:34 AM UTC

Hi Stefano,

After thorough analysis of the issue, we found that if the size of the PdfGraphics exceeds the client area, the text won't be visible and this is what happens in the given sample.

Some notes on PdfGraphics and DrawString Method:-

Size property of PdfGraphics returns the size of the canvas. Also, ClientSize property returns a client area of the canvas, which might be smaller. Any output out of the client area won't be visible.
If the coordinates are used for the text output only, it will be printed despite of the graphics boundaries. New lines symbols split the text by lines only. If the bound (RectangleF structure) of the text is set, the text will be layouted to fit the boundaries. If the width of the boundaries is set to 0 or less, the text won't be limited horizontally. If the height of the boundaries is set to 0 or less, the text will be limited by the boundaries of the PdfGraphics.

We regret for delay in providing these information.

Here is the modified sample in new PDF as per your requirement

http://websamples.syncfusion.com/samples/PDF.Windows/F68072_4/main.htm

Here is the generated PDF document
http://www.syncfusion.com/development/uploads/NewSyncFusion_1aca8ab7.pdf

Please let me know if this help you out.

Regards,
Fahad


SM Stefano Montimoregi October 8, 2007 08:57 AM UTC

Hi Fahad,

the sample that you give to me is not complete! Your sample is so simple...in my previous attach, in the code, i wrote that i've just tried to use SetClip but it don't work in all cases...

My sample DrawString has the StringFormat...and if I only set the LineAlignment property to Middle it don't works! Why?

I attach you another one sample...i re-write only the DrawString method to re-show you the error.


Regards,
Stefano

NewPdfClip_2.zip


SM Stefano Montimoregi October 8, 2007 09:05 AM UTC

And also...why if use DrawString() method I have a result and If use element.Draw() method i have another result???

The result could be the same...and I could be able to set clipping using element.Draw() method...

no?


Thanks

Regards,
Stefano


SM Stefano Montimoregi October 8, 2007 09:17 AM UTC

And also....

if I Write this code...

PdfTextElement element = new PdfTextElement();
element.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
element.Text = " TextWithSpacesBeforeAndNext ";

element.Draw(...)

Why the text is trimmed automatically by SynfFusion? I need the spaces...How can I print the text with spaces?


Is there any property to set?

Regards,
Stefano





MS Mohamed Suhaib Fahad A. Syncfusion Team October 9, 2007 12:26 PM UTC

Hi Stefano,

Thanks for the instant updates.

In our new PDF (complete re-write), we are using single graphics object for whole document. But in our old PDF its different. Our new PDF structure is very modular interms of usage, very clear in consuming memory space and lots of internal things that depends on the graphics object.

Here are the details regarding your query,

Query - Why the Middle line alignment is not working in clipping ?

We are not giving the rectangle boundaries in the DrawString method, we are only giving the starting location. So by changing the location we can make the text as center inside the rectangle clip. In both element.Draw() and Pdfgraphics.Drawstring(), the output is same only. Since both are graphics objects.

Here is the sample link:
http://websamples.syncfusion.com/samples/PDF.Windows/F68072_6/main.htm

Please let me know if this helps you out.

Regarding the question clipping with spaces:

We are able to see the issue. Could you please open a new direct – trac incident to Subject line contains the forum id and issue title like below.

Clipping don't work with DrawMultiText() - F68072.

so that we could provide more details regarding this issue?

Please let me know if you have any other queries.

Regards,
Fahad


SM Stefano Montimoregi October 10, 2007 08:50 AM UTC

Hi Fahad,

i have seen your sample...I know that I can set the line alignment to Middle manually changing the location but, for me, this is a base future...so every programmer that use syncfusion must implement the code to have a text printed in the middle...(as the rotation...i must implement my code to set the text at 90°...could be a simple property)...

so...this is only my personal idea...an idea of a Syncfusion's user!

Now i open a direct trac for the issue "text with spaces"...


Thanks for your quickly updates.


Regards,
Stefano

Loader.
Live Chat Icon For mobile
Up arrow icon