I know we can use the renderAs property to get whole vf pages as a pdf but I don't want that. I want particular tags in my pdf. I need a 'view/print pdf' button which opens the pdf in a new tab. I can use javascript or apex without any restrictions. Here is a little bit of code and screenshots for reference:
<div class="slds-form-element" id="div1">
<div class="slds-grid slds-gutters_small">
<div class="slds-col slds-has-flexi-truncate" role="listitem">
<div class="slds-form-element slds-form-element_edit slds-hint-parent">
<span class="slds-form-element__label"><b>{!$ObjectType['Credit_Applicant__c'].fields['Federal_Tax_ID__c'].Label} :</b></span>
<div class="slds-form-element__control">
<span class="slds-form-element__static slds-border_bottom">{!creditApplicantRecord.Federal_Tax_ID__c}</span>
</div>
</div>
</div>
<div class="slds-col slds-has-flexi-truncate" role="listitem">
<div class="slds-form-element slds-form-element_edit slds-hint-parent">
<span class="slds-form-element__label"><b>{!$ObjectType['Credit_Applicant__c'].fields['DUNS_Number__c'].Label} :</b></span>
<div class="slds-form-element__control">
<span class="slds-form-element__static slds-border_bottom">{!creditApplicantRecord.DUNS_Number__c}</span>
</div>
</div>
</div>
This is the footer with the print button that should open a pdf in a new tab