Comments (5)
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.
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.
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.
That's clever. Thanks!
from craft-pdf-transform.
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)
- Does not work with Amazon S3 HOT 7
- VolumeId given null HOT 5
- ?
- PHP 8.0 compatibility? HOT 6
- Craft v4 support HOT 2
- Works locally but not on my staging server HOT 6
- Craft 3 Error: file_get_contents: Failed to open stream: No such file or directory HOT 10
- Degraded Image quality HOT 3
- Failed to open stream: No such file or directory HOT 3
- new file_get_contents method means pdfs protected by basic auth can't have generated images
- Craft 3: file_get_contents() cannot be empty error - for volumes without public URLs HOT 3
- upload error with asset field HOT 2
- Colours of generated asset are inverted
- need help to install ghostscript HOT 2
- [Feature Request] Ability to specify a subfolder for the generated PDFs
- Update preview image if pdf assets are updated HOT 2
- Fix Composer 2 compatibility HOT 2
- Failed to instantiate component or class "bymayo\pdftransform\assetbundles\pdftransform\PdfTransformAsset". HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from craft-pdf-transform.