Skip to content

Instantly share code, notes, and snippets.

@YoannArasLab
Created June 15, 2018 10:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YoannArasLab/f426a70affca0bfe0508abaa8f0c1656 to your computer and use it in GitHub Desktop.
Save YoannArasLab/f426a70affca0bfe0508abaa8f0c1656 to your computer and use it in GitHub Desktop.
Print Aras Report In PDF
Innovator inn = this.getInnovator();
// Current User
String userId = inn.getUserID();
Item user = inn.getItemById("User", userId);
String creator = user.getProperty ("first_name", "") + " " + user.getProperty ("last_name", "");
// Item properties
String id = this.getProperty("id");
String item_number = this.getProperty("item_number");
String major_rev = this.getProperty("major_rev");
// Paths
String xslPath = "C:/Apps/Aras/Innovator/Innovator/Reports/";
String tmpPath = "C:/tmp/";
String PrinceExec = "C:/Apps/Prince/engine/bin/prince.exe";
// PDF FileName
String fileName = "BOM " + item_number + " Rev." + major_rev + " Released";
// AML construct
String aml = @"<AML>
<Item type='Part' action='get' select='item_number,name,state,major_rev,_source' id='" + id + "'>";
aml += @" <Relationships>
<Item type='Part Document' select='related_id(item_number,name,state,major_rev)'>
<related_id>
<Item type='Document' select='item_number,name,state,major_rev'/>
</related_id>
</Item>
<Item type='Part BOM' select='sort_order,quantity,related_id(item_number,name,state,major_rev,_source)'>
<related_id>
<Item type='Part' select='item_number,name,state,major_rev,_source'>
<Relationships>
<Item type='Part AML' select='state,related_id(item_number,name,manufacturer)'>
<related_id>
<Item type='Manufacturer Part' select='item_number,name,manufacturer'/>
</related_id>
</Item>
</Relationships>
</Item>
</related_id>
</Item>
<Item type='Part AML' select='state,related_id(item_number,name,manufacturer)'>
<related_id>
<Item type='Manufacturer Part' select='item_number,name,manufacturer'/>
</related_id>
</Item>
</Relationships>
</Item>
</AML>";
// AML Generation
Item bomItems = inn.applyAML(aml);
// Add creator in AML
Item UserRelationship = bomItems.createRelationship("creator", "add");
UserRelationship.setProperty("username", creator);
// Apply StyleSheet to AML
String xslFileLocation = xslPath+"EBS_BOM_Released.xslt";
String styleSheet = bomItems.applyStylesheet(xslFileLocation,"url");
// AML-HTML transformation
System.IO.File.WriteAllText(@tmpPath+fileName+".html", styleSheet);
// HTML-PDF transformation
Prince prn = new Prince(PrinceExec);
prn.AddStyleSheet(xslPath+"EBS_BOM_Released.css");
prn.Convert(tmpPath+fileName+".html", tmpPath+fileName+".pdf");
// Add PDF file to ARAS vault
Item newFile = inn.newItem("File", "add");
newFile.setProperty("filename", fileName+".pdf");
newFile.attachPhysicalFile(tmpPath+fileName+".pdf");
// Checkout item - no version
this.setAction("edit");
this.setAttribute("version", "0");
// Set Item-PDF File Relationship
Item relationship = this.createRelationship("Part File", "add");
relationship.setRelatedItem(newFile);
relationship.setProperty("_auto_comment", "Automatic Generated File");
// Apply & Done !
return this.apply();
@mshninwuttyi
Copy link

I really want to use your code.
But I got this error , when I use this code to generate xslt report as PDF file by installing Prince 15 version.
Do we need something to configure for using Prince? (eg: dll or namespace)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment