wordwrap and image background color issue in PDF

Hi Team,
  • I'm developing a pdf template where i'm not able to implement word wrap i.e after certain limit characters are getting cropped from the document.
  • And also while displaying the logo in the document, it is displayed with black background which originally has white background.
Can you please help me the issue. I have attached the snapshot of both the issue.

I tried word wrap with the below code:

PdfPage page = document.Pages.Add();
//Create PDF graphics for the page.
PdfGraphics graphics = page.Graphics;
PdfStringFormat format = new PdfStringFormat();
//Set the wordwrap
format.WordWrap = PdfWordWrapType.Word;
graphics.DrawString("Last Known UserID/Last Known User: ", fieldFont, PdfBrushes.Black, new PointF(300, 125), format);
graphics.DrawString((lastKnownUserId + " " + lastKnownUser), fieldFont, PdfBrushes.Green, new PointF(510, 125),format);
I want to show last known user and userid in a single line but it's getting cropped.
Regarding Image Background issue:

PdfImage image = PdfImage.FromFile(Server.MapPath("~/Content/images/Logo_Blue_199x43[1].gif"));
//Draw the image
graphics.DrawImage(image, new PointF(350, 0));
The above code is returning me the logo with black background.
Please find the attachment.
Thanks in advance

Attachment: PDF_Issues_f9ea1fd7.rar

3 Replies

SK Sasi Kumar Sekar Syncfusion Team May 10, 2018 06:34 AM UTC

Hi Anil, 
 
Thank you for contacting Syncfusion. 
I'm developing a pdf template where i'm not able to implement word wrap i.e after certain limit characters are getting cropped from the document. 
The text will be cropped when the text will not accommodate in the specified bounds. In this case we used the WordWrap to wrap the text to the next line. The given code snippet specified only the starting point of the text, so its takes single line to draw the text and text was cropped when beyond the page width. Kindly use RectangleF (x,y,width and height),so that the text will be wrap to the next line within the bounds, based on WordWrapType. 
 
graphics.DrawString("Last Known UserID/Last Known User: ", fieldFont, PdfBrushes.Black, new RectangleF(300, 125,100,100), format); 
 
And also while displaying the logo in the document, it is displayed with black background which originally has white background. 
We have drawn available different gif images to PDF document and all the images works as expected. The issue seems to be an image specific. Can you please share the input image file to reproduce the issue in our side and provide you the solution earlier? 
 
 
Please let us know if you need further assistance on this. 
Regards, 
Sasi Kumar S. 



AN Anil May 10, 2018 02:03 PM UTC

Hi Sasi,

Thanks a lot for the quick reply.

I am able to implement word wrap. 

But now after word wrapping, my texts are getting overlapped.

Can you please help me how to avoid that.

I have attached snapshot of the image for which i am getting black background as well as the overlapped text.

Thanks once again.

Attachment: Image_and_Overlap_text_issue_3f91d35b.rar


SK Sasi Kumar Sekar Syncfusion Team May 11, 2018 10:22 AM UTC

Hi Anil, 
 
Thank you for your update. 
 
Image background black color issue. 
We have drawn the attached image in the word document by extracting the image and the image was preserved as expected without background color in output PDF. We have ensured in latest version 16.1451.0.37. Can you please share the image file alone without attached in the word document. Please find the output PDF document below for your reference. 
Output PDF: 
Text overlap issue 
·         The WordWrapType will wrap the text based on the given bounds. The text will be overlap, if the given bounds overlap with the next continuous text bounds. So, make sure the bounds will not overlap with the other text. 
·         You can use PdfTextElement to wrap the text and using PdfLayoutResult will return the text bounds. Using PdfLayoutResult we can avoid overlapping and proceed draw the next continuous text based on the previous text position. 
Please find the KB for paginating the text using PdfTextElement. 
 
 
Kindly let us know if you need further assistance on this. 
 
Regards, 
Sasi Kumar S. 


Loader.
Up arrow icon