You need to sign in to do that
Don't have an account?
SK SGS
generating the Pdf with styles and markups in Lightning
Hi All,
I am generating the pdf for Account object using lightning components .In that i want to use some styles and markups with all the fields of selected record in detailed page.As of now i am unable to get the all the fields and styles.components code is working fine and generate the pdf.
But unable to get all the fields in pdf form.how to get the all the fields with styles,markups like visualforce pages in LEX..how to use the standard/custom styles in LEX.any one can please provide the solution for this,i am new to the LEX.
my components are
Apex class
public class TextVFPDFController {
public Account acc{get;set;}
public TextVFPDFController(){
Id accId = apexpages.currentpage().getparameters().get('id');
acc = [select Id,Name,Type,Rating,Phone from Account where id=: accId];
}
}
VF Page
<apex:page controller="TextVFPDFController" renderAs="PDF">
<apex:includeLightning rendered="true" />
</apex:page>
Component.cmp
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="TestAppController">
<lightning:button variant = "brand" label = "Generate Pdf" onclick = "{!c.savePDF}" />
</aura:component>
Client-side controller.js
({
savePDF : function(component, event, helper) {
var action = component.get("c.savePDFAccount");
action.setParams({recordId : component.get("v.recordId")});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
alert('Attachment saved successfully');
console.log('pdf created successfully');
$A.get('e.force:refreshView').fire();
window.location.reload();
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
}
}
else {
console.log("Unknown error");
}
});
$A.enqueueAction(action);
}
})
Server-side controller.cls
public class TestAppController {
@auraEnabled
public static void savePDFAccount(Id recordId){
PageReference pdfPage = new PageReference('/apex/TextVFPDF');
pdfPage.getParameters().put('Id',recordId);
Blob pdfContent = pdfPage.getContent();
Attachment attach1= new Attachment();
attach1.ParentId = recordId;
//attach1.ParentId = parentId;
attach1.Name ='Test Attachment for PDF';
attach1.Body = pdfContent;
attach1.contentType = 'application/pdf';
insert attach1;
}
}
Thanks in advance
sgs
I am generating the pdf for Account object using lightning components .In that i want to use some styles and markups with all the fields of selected record in detailed page.As of now i am unable to get the all the fields and styles.components code is working fine and generate the pdf.
But unable to get all the fields in pdf form.how to get the all the fields with styles,markups like visualforce pages in LEX..how to use the standard/custom styles in LEX.any one can please provide the solution for this,i am new to the LEX.
my components are
Apex class
public class TextVFPDFController {
public Account acc{get;set;}
public TextVFPDFController(){
Id accId = apexpages.currentpage().getparameters().get('id');
acc = [select Id,Name,Type,Rating,Phone from Account where id=: accId];
}
}
VF Page
<apex:page controller="TextVFPDFController" renderAs="PDF">
<apex:includeLightning rendered="true" />
</apex:page>
Component.cmp
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="TestAppController">
<lightning:button variant = "brand" label = "Generate Pdf" onclick = "{!c.savePDF}" />
</aura:component>
Client-side controller.js
({
savePDF : function(component, event, helper) {
var action = component.get("c.savePDFAccount");
action.setParams({recordId : component.get("v.recordId")});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
alert('Attachment saved successfully');
console.log('pdf created successfully');
$A.get('e.force:refreshView').fire();
window.location.reload();
}
else if (state === "ERROR") {
var errors = response.getError();
if (errors) {
if (errors[0] && errors[0].message) {
console.log("Error message: " +
errors[0].message);
}
}
}
else {
console.log("Unknown error");
}
});
$A.enqueueAction(action);
}
})
Server-side controller.cls
public class TestAppController {
@auraEnabled
public static void savePDFAccount(Id recordId){
PageReference pdfPage = new PageReference('/apex/TextVFPDF');
pdfPage.getParameters().put('Id',recordId);
Blob pdfContent = pdfPage.getContent();
Attachment attach1= new Attachment();
attach1.ParentId = recordId;
//attach1.ParentId = parentId;
attach1.Name ='Test Attachment for PDF';
attach1.Body = pdfContent;
attach1.contentType = 'application/pdf';
insert attach1;
}
}
Thanks in advance
sgs
for this which one i used either vf or LEX.