Need help on document processing for styled profile card creation

2 Answers 52 Views
PdfProcessing WordsProcessing
Adrian
Top achievements
Rank 1
Iron
Adrian asked on 05 May 2023, 09:16 AM

Hi all,

 

I need to create some profile cards on a document based on the style template attached here. At the end of the process, the document should be exported in pdf.

I have tried a lot of things with RadWordsProcessing and RadPdfProcessing but I'm not sure I would be able to obtain the exact same result because of style limitations like rounded corners unavailable, for example.

Does anybody have any idea how I could create something the most similar possible? With any Telerik Document Processing tool.

I also tried to make a table (structured as in attached picture) but I didn't succeed to create the table with a colored background or image background (on all the table) and with the profile picture which should be place in a circle shape, ahead the table background. 

As I'm new to Telerik, my knowledge is limited, but I didn't find any information that helps me.  On the contrary, I only found information that make me doubt about the feasibility of this project.

 

Any help would really be appreciated,

Thank you in advance,

Adrian

 

2 Answers, 1 is accepted

Sort by
1
Accepted
Yoan
Telerik team
answered on 09 May 2023, 01:32 PM

Hello Adrian,

In the PdfProcessing library creating and editing the content of a RadFixedPage is possible through the FixedContentEditor, which seems like the most appropriate approach to this case, judging by the requirements. It allows the insertion of Text, Images, Geometrics, Tables, Forms, Widgets, and other elements while also exposing the manipulation of their Text and Graphic Properties. The editor also has a Position property and can move around the page, which allows the fluid insertion of elements. 

The export to PDF at the end can be achieved through the Export method of the PdfFormatProvider of the library. Here is a code snippet that incorporates all that functionality and outputs a PDF file with a similar result to the one in the 'ProfileStyleTemplate.jpg':

RadFixedDocument doc = new RadFixedDocument();
doc.Pages.AddPage();
FixedContentEditor containerEditor = new FixedContentEditor(doc.Pages.First());

//Rectangle
LinearGradient linearGradient = new LinearGradient(new Point(0, 0), new Point(100, 100));
linearGradient.GradientStops.Add(new GradientStop(new RgbColor(0, 255, 128), 0));
linearGradient.GradientStops.Add(new GradientStop(new RgbColor(102, 178, 255), 1));

containerEditor.GraphicProperties.FillColor = linearGradient;

containerEditor.DrawRectangle(new Rect(10, 10, 500, 200));

//Image
containerEditor.Position.Translate(50, 40);
containerEditor.DrawImage(new FileStream(Path.Combine("..\\..\\..\\..\\profileImage.png"), FileMode.Open), new Size(130, 130));

//Text1
containerEditor.GraphicProperties.FillColor = new RgbColor(255, 255, 255);
containerEditor.Position.Translate(220, 60);
containerEditor.TextProperties.FontSize = 25;
containerEditor.TextProperties.Font = FontsRepository.TimesBold;
containerEditor.DrawText("Text1");

//Text2
containerEditor.Position.Translate(220, 120);
containerEditor.TextProperties.Font = FontsRepository.TimesRoman;
containerEditor.DrawText("Text2");

//Export
PdfFormatProvider provider = new PdfFormatProvider();
using (Stream output = File.OpenWrite("..\\..\\..\\..\\output.pdf"))
{
    provider.Export(doc, output);
}

Hope this proves helpful. If you need any further assistance, we are at your disposal.

Regards,
Yoan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Adrian
Top achievements
Rank 1
Iron
answered on 15 May 2023, 08:57 AM

Hi Yoan,

 

Thank you for your answer, it was useful to me.

Am I wrong in assuming that it is (actually) not possible to draw the profile picture in the shape of a circle?

Regards,
Adrian

 

Yoan
Telerik team
commented on 15 May 2023, 01:50 PM

Hello Adrian,

It is possible to draw an image as a circle with the FixedContentEditor. To achieve this you can insert a clipping geometry into a FormSource using the FixedContentEditor.PushClipping method. After this, you can set the FormSource of a block element using the InsertForm method.

Example:

FormSource formSource = new FormSource
{
    Size = new Size(imageSource.Width, imageSource.Width)
};
 
PathGeometry circlePath = this.CreateCirclePath(imageSource.Width / 2);
FixedContentEditor formEditor = new FixedContentEditor(formSource);
 
using (formEditor.PushClipping(circlePath))
{
    formEditor.DrawImage(imageSource);
}
 
Block imageBlock = new Block();
imageBlock.InsertForm(formSource);

Here are the documentation sections describing the mentioned functionalities:

The circle path can be created by adding an ArcSegment geometry:

private PathGeometry CreateCirclePath(double radius)
{
    PathGeometry pathGeometry = new PathGeometry();
 
    PathFigure pathFigure = pathGeometry.Figures.AddPathFigure();
    pathFigure.IsClosed = true;
 
    Point startPoint = new Point(0, radius);
    Point endPoint = new Point(2 * radius, radius);
 
    pathFigure.StartPoint = startPoint;
    pathFigure.Segments.AddArcSegment(endPoint, radius, radius);
    pathFigure.Segments.AddArcSegment(startPoint, radius, radius);
 
    return pathGeometry;
}

Hope this helps.

Regards,

Yoan

Adrian
Top achievements
Rank 1
Iron
commented on 25 May 2023, 07:06 AM

Hi Yoan,

It works fine ! Thank you for your help!

Regards,
Adrian

Tags
PdfProcessing WordsProcessing
Asked by
Adrian
Top achievements
Rank 1
Iron
Answers by
Yoan
Telerik team
Adrian
Top achievements
Rank 1
Iron
Share this question
or