Git Product home page Git Product logo

Comments (5)

Christopholus avatar Christopholus commented on September 22, 2024 3

We had a similar issue with the getUrl returning the same error.

Our team came up with a solution that works well, albeit a bit of a hacky one:

We took PDFTransform's returned URL, trimmed out the folder and ran a craft query to locate the created image asset. We're then able to reference this asset like we would any other, and lean on Craft's excellent transforming abilities to do the rest.

Our solution is below, hope it helps!

        {% set resourceThumb = craft.pdfTransform.url(download) %}
        {% set cleanedURL = resourceThumb | trim('/images/resource_thumbs/') %}
        {% set thumbAsset = craft.assets().filename('*'~cleanedURL~'*').one()  %}
        {% if thumbAsset|length %}
            <img src="{{ thumbAsset.getUrl('resourceThumb') }}" alt="" />
        {% endif %}

from craft-pdf-transform.

bymayo avatar bymayo commented on September 22, 2024 1

Sure!

{# Get the PDF #}
{% set pdf = entry.pdf.one() %}

{# Convert PDF to Image #}
{% set pdfImage = craft.pdfTransform.url(pdf) %}

{# Set Transform #}
{% set pdfImageTransform = {
    mode: 'crop',
    width: 800,
    height: 600
} %}

{# Output Transformed PDF Image #}
<img src="{{ pdfImage.getUrl(pdfImageTransform) }}" alt="PDF">

I personally would do this with Imager X plugin though, as you have more control over the caching of the files etc. As I would 100% recommend images are cached if they are transformed.

Potentially do some error checking e.g. {% if pdfImage|length %} to make sure the image exists before you try and transform it also.

from craft-pdf-transform.

zenbug avatar zenbug commented on September 22, 2024 1

When I try this code, I get the error "Impossible to invoke a method ("getUrl") on a string variable."

This seems to make sense to me, because the plugin outputs a URL already, right? So I can't use ".getUrl" on something that's already a URL.

Or am I misunderstanding something? Are you able to make that code work ?

from craft-pdf-transform.

zenbug avatar zenbug commented on September 22, 2024

That's clever. Thanks!

from craft-pdf-transform.

bymayo avatar bymayo commented on September 22, 2024

You shouldn't need to do this now as of 1.0.8 (Craft 3) and 2.0.1 (Craft 4) as it will now output the Asset, not just the URL if you use the new render() method:

{% set pdfFile = entry.pdfFile.one() %}

{% set pdfToImage = craft.pdfTransform.render(pdfFile) %}

{% set pdfTransform =  pdfToImage.one().getUrl('resourceThumb') %} 

{% if pdfTransform|length %}
         <img src="{{ pdfTransform.getUrl('resourceThumb') }}" alt="{{ pdfToImage.one().title }}" />
{% endif %}

from craft-pdf-transform.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.