put border around image

How can I put a border around an image when creating a pdf?

4 Replies

CM Chinnu Muniyappan Syncfusion Team April 30, 2018 08:40 AM UTC

Hi Caleb, 
 
Thank you for contacting Syncfusion support. 
 
We can create borders around the image by drawing the rectangle along with the same bounds of the image. We have created a sample for drawing borders around the image for your reference. Please refer the below code snippet and sample for further details. 
 
             
            //Create a new PDF document. 
            PdfDocument document = new PdfDocument(); 
 
            //Add a new PDF page. 
            PdfPage page = document.Pages.Add(); 
 
            PdfBitmap image = new PdfBitmap("../../Autumn Leaves.jpg"); 
 
            //Bounds of the image. 
            RectangleF bounds = new RectangleF (PointF.Empty, new SizeF(300, 500)); 
 
            //Draw image to PDF page. 
            page.Graphics.DrawImage(image, bounds); 
 
            //Create a new PDF pen. 
            PdfPen borderPen = new PdfPen(new PdfColor(System.Drawing.Color.Red)); 
 
            //Set pen width. 
            borderPen.Width = 2; 
 
            //Draw border around the image. 
            page.Graphics.DrawRectangle(borderPen, bounds); 
 
            //Save the document. 
            document.Save("output.pdf"); 
 
            //Close the document. 
            document.Close(true); 
 
 
 
Please refer the UG link for more details, 
 
 
Please let us know if you have any concern. 
 
Regards, 
Chinnu 



EM Eric Mendiola replied to Chinnu Muniyappan April 24, 2020 07:18 PM UTC

Hi Caleb, 
 
Thank you for contacting Syncfusion support. 
 
We can create borders around the image by drawing the rectangle along with the same bounds of the image. We have created a sample for drawing borders around the image for your reference. Please refer the below code snippet and sample for further details. 
 
             
            //Create a new PDF document. 
            PdfDocument document = new PdfDocument(); 
 
            //Add a new PDF page. 
            PdfPage page = document.Pages.Add(); 
 
            PdfBitmap image = new PdfBitmap("../../Autumn Leaves.jpg"); 
 
            //Bounds of the image. 
            RectangleF bounds = new RectangleF (PointF.Empty, new SizeF(300, 500)); 
 
            //Draw image to PDF page. 
            page.Graphics.DrawImage(image, bounds); 
 
            //Create a new PDF pen. 
            PdfPen borderPen = new PdfPen(new PdfColor(System.Drawing.Color.Red)); 
 
            //Set pen width. 
            borderPen.Width = 2; 
 
            //Draw border around the image. 
            page.Graphics.DrawRectangle(borderPen, bounds); 
 
            //Save the document. 
            document.Save("output.pdf"); 
 
            //Close the document. 
            document.Close(true); 
 
 
 
Please refer the UG link for more details, 
 
 
Please let us know if you have any concern. 
 
Regards, 
Chinnu 


I am using DocIORenderer to convert a word document to pdf and when converting the images they pass with a black border, how can I eliminate this border?

DocIORenderer render = new DocIORenderer();
PdfDocument pdfDocument = render.ConvertToPDF(document);

attached the word and pdf documents of the example

thanks for your attention

Attachment: Plantilla_2_a7373d84.rar


MR Manikandan Ravichandran Syncfusion Team April 27, 2020 09:34 AM UTC

Hi Caleb,

Thank you for your update.

We can reproduce the mentioned issue with “Border preserved for image while converting word document to PDF” at our end. We suspect this could be a defect and We will update you with more details on this on 29th April 2020.

Please let us know if you have any other questions.

Regards,
Manikandan Ravichandran



MR Manikandan Ravichandran Syncfusion Team April 29, 2020 03:04 PM UTC

Hi Caleb,

Thank you for your patience.

We have confirmed that the reported Border preserved for image while converting word document to PDF is a defect and we have logged a defect report. We will include the fix for this issue in 2020 Volume 1 SP1 release which will be available on end of May.

The status of this bug can be tracked through the below link:
https://www.syncfusion.com/feedback/13960/border-preserved-for-image-while-converting-word-document-to-pdf

Note: If you require patch for the reported issue in any of our Essential Studio version (except weekly release version), then kindly let us know the currently installed version, so that we can provide a patch in that version based on our SLA policy.

Please let us know if you have any other questions

Regards,
Manikandan Ravichandran


Loader.
Up arrow icon