4

I have a number of published PDFs on the file system which I am required to update and save again on the File System itself.

So far I am able to update the PDF by creating a temp file. The original published PDF has to be replaced by the temp file, which is not possible as Tridion is preventing deletion of the published PDF.

How can I unpublish the PDF, and then replace it with the temp file?

Is it possible to unpublish a PDF from the file system at all?

This is the code I am using to replace old file and delete temp file. It is working fine in a local environment, but in Tridion it is not able to delete or make any changes to the published original PDF.

    private void GetFileNames(string PDfpath, string filter)
    {
        string FullFilePath = string.Empty;
        string[] files = Directory.GetFiles(PDfpath, filter);
        for (int i = 0; i < files.Length; i++)
        {
            files[i] = Path.GetFileName(files[i]);
            if (files[i] == "temp.pdf")
            {
                FullFilePath = PDfpath + "\\" + files[i];
                File.Copy(PDfpath + "\\" + "temp.pdf", PDfpath + "\\" + "old.pdf", true);
                File.Delete(FullFilePath);
            }
        }
    }

Please advise..

  • 1
    What are you really trying to do? You are interacting with File System with a standard C# code, and you want to remove it from the File System? What do you mean by "but in Tridion it is not able to delete or make any changes to the published original PDF." Where is the Core Service in picture? Are these PDFs managed in the Tridion and published to the File System through Tridion Publishing Process? Do you want to update these PDF in content or want to replace the set of PDFs with new PDF files? Clarify? – Pankaj Gaur May 8 '13 at 9:33
  • As others have commented, this approach looks problematic. You really need to share with us what you are trying to achieve. – Dominic Cronin May 8 '13 at 11:14
  • Pankaj Gaur , Dominic Cronin - Yes these PDFs are managed in Tridion and published to File System through Tridion Publishing Process. I am required to update the existing PDF with a code the user enters, which had been published from tridion. In trying to update the PDF, a temp file is created which I would like to copy to the original and delete the temp from file system. The temp file can be deleted from file system but changes to the original published file, like copying the temp to the original is not being allowed in Tridion.I havent used core services as I am not very well aware of them. – tkarmaka May 8 '13 at 13:19
  • You should change the PDF in Tridion, then republish. – Nuno Linhares May 8 '13 at 15:56
  • The requirement is such that it is not possible to change it in Tridion. As per code entered by user, the PDF has certain ACRO Fields that are filled with the code ,at the click of a button in the UI. So, is there any way to unpublish the old PDF? Otherwise it is not possible to copy the temp PDF in the old one. – tkarmaka May 9 '13 at 5:47
7

The usual process for handling PDFs in Tridion is:

  1. Create a new Multimedia component, based on the schema you use for PDFs in your environment

  2. Save and close the new component

  3. Publish the PDF to the file system by either:

    • Publishing the new Component directly (and having a dynamic Component Template associated with the schema its based on)
    • Adding the Component to a page either directly, or as a Component link field of a component that is already on a page.

Whichever method you use there will be some template logic that handles the publishing.

Every time the PDF is published Tridion maintains a reference count in the Broker database.

When the PDF gets unpublished the reference count is reduced, and once it hits zero the PDF will be removed from the file system.

So, to remove the PDF from the file system you just need to make sure all instances of it are unpublished. Is it used on more than one page perhaps? Try doing a 'Where used' on the component to track this down.

However, it looks like you don't want to delete the PDF - just update it?

Once you've updated your PDF in the CMS (in your multimedia component), you just need to re-publish the PDF using whatever publish mechanism you used in the first place.

This will then overwrite the existing PDF on the file system.

It looks like you are using the Core Service to work with your PDFs? If the above doesn't help you please share your code, and more specific details of the problems you are having.

Update (Code sample added to question)

From the code provided in your updated question, there's no reference to the Core Service, it seems you are trying to interact directly with the PDFs on the file system?

This is not how Tridion works. As explained above you need to manage your Components in the Content Manager, and then use the Tridion publishing process to create, update and remove the PDFs from the file system.

If you need to script this process you can use the Core Service to create PDFs in the CMS, and then Publish them to file system.

It appears you might be missing some of the foundations of working with Tridion - thats not something that can be covered in full here. I'd recommend engaging with a Tridion partner to cover some of this with you. In addition to that, there's a lot that would help you here: http://sdllivecontent.sdl.com/ (login required)


| improve this answer | |
3

I would suggest the following approach which should be inline with the Tridion architecture:

Assuming the Code with which you have to update the PDF is being entered in some application by the end user

  1. Once you get this code through the application, create an interface to the Tridion Core Service - which is a WCF based service - invok-able from .NET as well as from Java based application and can be used to interact with the Tridion Content Manager
  2. Use the Tridion core service to utilize this code, and update (or create) the required PDFs with this code in the Tridion Content Manager
  3. Now re-publish these PDFs from Tridion Content Manager - You can choose to publish them manually or you can automate it through Core Service itself. Your existing PDFs will be overridden by the updated ones

I hope this help. If my understanding is wrong about your requirement, kindly update the question accordingly and I would be happy to update my answer.

| improve this answer | |
  • Thanks, but is there any way to unpublish the old PDF? – tkarmaka May 9 '13 at 5:48
  • That depends how did you published those PDFs; if they have been published by publishing their respective multimedia components then you can choose to un-publish them directly from the CME or even by using the Core Service code. – Pankaj Gaur May 9 '13 at 7:37
  • Actually , I am required to unpublish them through code, not directly from the CMS. But, not sure how to go about it. – tkarmaka May 9 '13 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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