• Resolved plgupa

    (@plgupa)


    Hi,

    Thanks for creating this great plugin. However, I am facing a issue.

    In my WordPress page I am displaying PDF that is dynamically generated for a user based on user information, giving it some name, example – helloword.pdf. Now when the user changes the information then I display the updated helloworld.pdf again. But the PDF viewer is showing the old verison of helloworld.pdf. I want to show the latest version on PDF.

    Please help how can this be done?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Slava Abakumov

    (@slaffik)

    Hey @plgupa,

    The library we use to render the PDF has some speed-management features, and one of those is caching the file from the same URL. Opening the same URL in a different browser will resolve the issue for you, but I understand that this is not your desired solution.

    Given you circumstances, I think you are doing some custom functionality, so I would recommend you when rendering the PDF (technically, before outputting the page) – modify the shortcode and its url attribute to have a random GET param in the end. This can be achieved with a regext that parses the post_content for the [pdf-embedder url=" and changes the URL value.

    Example:

    [pdf-embedder url="https://example.com/wp-content/uploads/2023/11/helloworld.pdf?t=1708947441"]

    where t is the date when that helloworld.pdf file was modified (check the filemtime() function in PHP).

    This way technically the URL will be always unique to the file modification time and the PDF.js will cache only subsequent access to the same versioned file.

    I hope that helps.

    Thread Starter plgupa

    (@plgupa)

    Yes, this worked. I used [pdf-embedder url=”filename.pdf?t=rand(0,10000)”] to generate unique query string every time.

    Thanks for help.

    • This reply was modified 9 months ago by plgupa.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Old PDF is shown’ is closed to new replies.