How do I re-use the same image payload in several pages without repeating it? - pdf

I'm using tcpdf to generate a report that contains a logo from a svg vector image.
My goal is to efficiently re-use the same image payload over and over in the report, not storing the logo as if it was a different image on each page.
Right now, with the current data, the report generates 32 pages. The file size considerably increases with new pages being added. This seems to be due to the logo being repeated on every page.
I don't have tools to analyze what is inside the pdf but I can see from other reports that are generated by other applications, that the file size of pdfs containing repeated images peaks at 1 page and then on each consecutive page, the size increases very slightly, indicating that the first logo is efficiently re-used.
How can I achieve that using tcpdf?
If in my report, I place the logo only in page 1 and omit it in pages 2 - 32, still outputting all the text data, the file size is greatly reduced, just as in the examples that I mentioned before. This indicates that the svg data is repeated on every page.
From the example 009 in tcpdf's site documentation, I've tried loading the image from file and also tried using a "data stream" (this is encoding the svg in base64 and instead of referencing the image from a file, you use the text-based base64 variable content as a stream that contains the image payload).
I thought that using the data stream would take care of it, but it didn't.
Is there a way to reference the same image over and over in tcpdf?

Related

Decreasing size of PDF when using puppeteer for pdf generation

We are using IDR for converting PDF documents to HTML.
After doing some modifications we are using puppeteer for converting that document back to PDF I am getting files with increased page size (even if I don't do any modification to my HTML).
For ex:- If the original page size is 500kb I am getting a page with 1000kb
The page only contains some text.
Please help me to understand what is the reason behind this and how to solve this.

Shopify Product pictures on our collection pages keep changing sizes

Shopify: Product pictures on our collection pages keep changing sizes
Three gurus have been unable to help with a problem our nonprofit store is having. We would be forever grateful if you can.
Pictures on our collection pages keep changing sizes.
We have this problem on Chrome, Safari, and IE. I am on a PC. A colleague here who had never been on the site also had the same problem on multiple browsers on a PC. I spoke with a guru today, who was on a Mac, and he had the same experience. Yes, I refreshed my cache, and that did not help (as we recognized when people who had never been on the site had the same problem).
We are using a modified version of the Supply theme. I cannot imagine any edits to the theme causing this problem.
Please see this collection page of our store, which is in development:
https://gfh2.myshopify.com/collections/defenders-of-wildlife
(Yes, I know there is no home page. Long story)
Of course, the product pictures should all be the same width. But they are not, and they change from time to time and between browsers.
Sometimes all the pictures are very small, such as you see in this screen grab:
https://cdn.shopify.com/s/files/1/2326/7959/files/small_pics_1.PNG?6100116406257966738
Sometimes just a few of the pictures appear at the very small size, such as you see in this screen grab:
https://cdn.shopify.com/s/files/1/2326/7959/files/small_pics_7.PNG?6100116406257966738
If you click to the product pages, the pictures are all the correct size there.
Sometimes some of the pictures appear somewhat smaller than they should (in the range of 70% to 90%, and at least three such smaller sizes, such as you see here:
https://cdn.shopify.com/s/files/1/2326/7959/files/small_pics_6.PNG?6100116406257966738
Sometimes, if I click a product image on the collection page to go to the product, and then click the Back button to return to the collection page, and do that several times, then the image on the collection page appears at the correct size or at the 70% or 85% size. One time this evening it took three round-trips to do that. Another time it took seven round-trips.
The problem also happens with other collections, such as [Stack Overflow limites how many links I can provide, so just change the collection link provided above to
/first-book
When I first loaded that page, just now, all the pics were small. Please see
https://cdn.shopify.com/s/files/1/2326/7959/files/small_pics_11.PNG?16317572828225077891
I clicked the first one to go to the product page, then Back to the collection page, and made three round trips, and then that one image appeared at the correct size on the collection page. Please see
https://cdn.shopify.com/s/files/1/2326/7959/files/small_pics_10.PNG?16317572828225077891
I looked at another browser (actions above were in Chrome; I looked at IE), and all the pics there remained small. Refreshing the page 10 times did not help.
Went back to Chrome. Clicked the second picture and clicked back, several round trips. Then the pic on the collection page got larger, but the first pic reverted to small.
Thank you very much!
Shopify serves images to your pages, by resizing the image file on the server. The intention is to improve page load times, while insuring correct styling for various screen sizes and layouts. Less image files to produce, as well.
To do this, the Shopify server will need more info than just the file name, but the size information as well.
It uses an {image url filter} to include the size data with the image file name.
This is one of your image urls.
https://cdn.shopify.com/s/files/1/2326/7959/files/small_pics_1.PNG?6100116406257966738
The following is an example of an image url that includes the image size. Note the '720x720' between the image name (boat-shoes) and the image format (.jpeg).
https://cdn.shopify.com/s/files/1/1183/1048/products/boat-shoes_720x720.jpeg?v=1459175177
The help section for image url filters states: 'If you don't include an image size, the filter returns a small (100x100) image.' This may explain your issue. Here is the URL of the help section I've referenced.
https://help.shopify.com/en/themes/liquid/filters/url-filters#size-parameters
(If you're used to graphically sizing an image, and then seeing the image at that size on the page, then this would be understandably counter intuitive.)
There are other possibilities. I would need to see the theme code for a more definitive answer. Contact me if I can help.

PDFBox generated PDF dimensions (Height and Width) getting swapped

Let me give you an overview of my project first. I have a pdf which I need to convert into images(One image for one page) using PDFBox API and write all those images onto a new pdf using PDFBox API itself. Basically, converting a pdf into a pdf, which we refer to as PDF Transcoding.
Now, I have some cases wherein eveyrthing goes fine, i.e. the transcoded pdf exactly matches the original pdf contents, but just 1/10 cases are like, the dimensions of transcoded pdf is getting swapped somehow. For example, original pdf- 8.2 x 11.2
transcoded pdf- 11.2 x 8.2. In short, height is getting swapped with width. I don't know why this API is behaving differently for different files. If anyone could answer the same?
Thanks in advance,
Vaibhav
(Summarizing the results of the dialogue in the comments to the original question)
Each page of a PDF has a rotation property which can indicate a rotation of the otherwise defined page coordinates, confer the PDF specification ISO 32000-1:
Rotate integer (Optional; inheritable) The number of degrees by which the page shall be rotated clockwise when displayed or printed. The value shall be a multiple of 90. Default value: 0.
(Table 30 Entries in a page object on page 78)
E.g., a page by its media box being defined to have an A4 portrait format may still have to be displayed as an A4 landscape page.
In your case one of the used software packages seems to respect this rotation while the other one doesn't.
As you are using PDFBox, you can query the rotation of a PDPage page using
int rotation = page.findRotation();
In essence it returns the value of the Rotate key of the page or (if not found there) its ancestors in the page tree.

PDFBox : Converting to image : Quality loss when converting PDF containing scanned documents

My use case is pretty simple. I need to convert the PDFs to images.I tried using apache pdfbox and i am having some trouble in converting pdfs which contains scanned images. when i convert scanned image the image clarity is lost due to compression/scaling. So i was trying to extract the image data from the PDF and then store it. But the problem is i may get PDF files which will contain images and text in which case i would need to fallback to image conversion mode. The problem is how to differentiate between the pages/documents having only image and the ones with composite data. I was thinking i could use ProcSet defenition for this purpose but looks like it is marked as obsolete and non-reliable according to PDF specifications. Other possibility is to check all the objects linked to that page and see if it contains anything other than images. Please let me know if there is an easier way of doing this
Thanks
If your intention is convert pdf to image, It is better to use ImageMagick for that. If you use ImageMagick, there is a lot options to change the quality of the image. And converting pdf to image is pretty simple using ImageMagick.

Plugin: BuddyPress Activity Plus - How can I call the full size image?

I’m using the BuddyPress Activity Plus plugin and wanted to know if there was a way to call the full size image that was uploaded when viewing the single page of the activity?
I’ve looked at placing a line of code in “activity/entry.php” of the child theme but can’t find anything that will call its full size image, only the thumbnail shows with the link to the full size image to open in a lightbox.
This isn’t what I’m looking for, the full size image needs to be in place of the thumbnail when viewing the single activity page.
Any idea anyone? Sorry if this is the right place for this, just having trouble getting an answer
Many thanks
I'm looking to do a similar thing, not too much luck yet. Also - have you noticed that if you upload multiple images, they stack, rather then laying out side by side?
EDIT:
Found out how to make the images in the stream bigger:
You can set your preferred thumbnail size separately from your default thumbnail size settings, if you wish to do so. You can do that by adding this line to your wp-config.php:
define('BPFB_THUMBNAIL_IMAGE_SIZE', '200x200');
Where "200x200" are width and height (in that order), in pixels.
Finally, be sure to verify your default sizes for embedded media. It's in Settings -> Media -> Embeds -> Maximum embed size