Apply styles on PDF with k-pdf-export and other classes

0 Answers 55 Views
Grid PDF Viewer
penny
Top achievements
Rank 1
penny asked on 21 Sep 2023, 03:20 PM

Hello Telerik team,

Hey, I am trying to apply styles on the exported PDFs but not globally to all tags.

Suppose I have some `p` elements that should have styles A and some other that should have styles B.

The following will not work.

.k-pdf-export .class-a p {

  border1px dashed rgb(1942323);

}

.k-pdf-export .class-b p {

  border1px dashed #aaa;

}

 

The selectors will not work. Relevant example:

https://stackblitz.com/edit/react-zhmi5y?file=app%2Fstyles.css

So my questions are:

1. Are the other classes removed?

2. How can I achieve what I need?

3. If this is not supported as of now are there any plans to consider supporting it?

 

Thanks!

Plamen
Telerik team
commented on 22 Sep 2023, 06:07 AM

Looking at the styles applied it seems like the first selector is targeting 'p' elements inside elements with class 'another' and that is why it is not working with the current HTML. If we want to color the border of the p with the class we need to apply the styles as below and in this example:

.k-pdf-export p.another {
  border: 1px dashed rgb(194, 23, 23);
  padding: 10px;
}

penny
Top achievements
Rank 1
commented on 22 Sep 2023, 07:31 AM | edited

Thanks for the reply! The thing is that I created this example because I had a similar problem with grid. More specifically I apply a classname on a Grid component whenever there are groups:

 

<Grid classname='k-group-table' .../>


And I have the following CSS rules:

.k-pdf-export .k-group-table colgroup>col:first-child,
.k-group-table colgroup>col:first-child {
    width: 170px !important;
}

 

The rule is applied only on the displayed Grid and not on the exported one. Do you have any ideas?

 

Plamen
Telerik team
commented on 25 Sep 2023, 01:54 PM

Would you please send us a runnable example (in a stackblitz for example) where we could inspect the issue and try to be more helpful with a possible solution?
penny
Top achievements
Rank 1
commented on 26 Sep 2023, 07:44 AM | edited

Yes, here is the runnable example

https://stackblitz.com/edit/react-snmdvg?file=app%2Fstyles.css

 

You can see that while the class is applied on the Grid, it is not applied when the PDF is exported

@plamen  any help would be appreaciated

Plamen
Telerik team
commented on 27 Sep 2023, 02:40 PM

Here is a sample code that allowed me to color the Grid only in the PDF exported version and here is the example:

.k-pdf-export.k-grid {
  background-color: yellow;
  color: red;
}

The case of the Grid export this is how the classes are aligned in the PFD version rendering.

Hope this will help you solve the issue. If you have further questions please don't hesitate to let us know.

No answers yet. Maybe you can help?

Tags
Grid PDF Viewer
Asked by
penny
Top achievements
Rank 1
Share this question
or