3

I have project requirements for generating a HTML document upon publishing of a Page and convert the HTML document to PDF file.

The code will do the following:

  1. Load all published pages from the Structure Group tree
  2. Run through all Component Presentations on loaded pages
  3. Get hold of Component from each Component Presentation
  4. Read Component fields building the HTML document
  5. Component fields can have internal Tridion links

This is where I need some directions...

In the templating world, we can use default TBB: Link Resolver. The Link Resolver TBB will output <tcdl> tags that are resolved by Content Delivery API on the application side.

Is there a way to do this from Event System code or something similar?

Do I need a custom Link Resolver that determines published paths of pages after determining link relationship using GetUsingItems() method on Component object?

Thank you for your time!

0

1 Answer 1

2

To resolve your Tridion Component Links on the CM side you're on the right track: use the IdentifiableObject.GetUsingItems(UsingItemsFilter) method on the Component that you're linking to. You'll then need to:

  1. For the Pages returned, figure out which page to link to. If you want to mimic the Dynamic Linking algorithm then you'll need to do proximity logic as described in the SDL Tridion docs (http://docs.sdl.com/LiveContent/content/en-US/SDL%20Tridion%20full%20documentation-v1/GUID-F9F52365-2ABE-4C1E-A50C-3D4CA4F84989). This might be tough/a lot of code. If, though, you only have 1 page your component is on, then this is easy as there is only one choice.
  2. For each Component that uses this Component, do recursion.

As far as how to get a published path of a Page, there is a property called PublishUrl on each Page object. Just make sure the Page is published to the Publication Target of the current publishing Session.

You may want to consider another approach and perhaps move the "HTML Document" generation logic to the Content Delivery side. This would allow you to leverage OOTB features such as Dynamic Linking with REL and OData to pull fully rendered plain HTML documents, which you can further transform into a PDF.

2
  • +1 to the delivery-side approach. Tridion World has the PDF creator extension (courtesy of Hendrik Tredoux) and I've seen iTextSharp work for .NET projects. Delivery-side makes more sense the more "dynamic" the presentation is with content coming from more than just Tridion. Commented Nov 18, 2014 at 21:47
  • I generated the HTML document on the CM server and published it as DCP. I had to write some code to clean up the IMG and A tags in the HTML document to make them friendly to the Link Resolver TBB. On the CD side, I got fully resolved URLs and converted the HTML to PDF on the fly. Mucho gracias! Commented Dec 31, 2014 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.