Use full image size for page - pdf

can I design (for ex: 300x400 px) card in html and convert it to same size pdf using wkhtmltopdf?
I have html like:
<html><head></head><body><div style="width:364px; height:562px">
<img src="http://172.26.1.236/UserImage/jpeg.jpg" alt="my image" width="364px" height="562px"></div></body></html>
my code is:
var pi = new ProcessStartInfo(#"C:\Program Files\wkhtmltopdf\wkhtmltopdf.exe");
pi.CreateNoWindow = true;
pi.UseShellExecute = false;
pi.WorkingDirectory = #"c:\wkhtmltopdf\";
pi.Arguments = "--page-width 364pt --page-height 562pt --dpi 300 C:\\Users\\Admin\\Desktop\\Test.html C:\\Users\\Admin\\Desktop\\Test.pdf";
I want image should cover full page. how to achieve this?

Related

How to get multiple images from a multipage pdf in typoscript?

Using an Images element I can add a PDF and have it render as a JPG. However it only does the first page. Is there any way to output each page as JPG files?
I am using the layout field to change how the images are rendered by typoscript. Can I split the pdf somehow?
eg.
# Image Layouts
temp.image < tt_content.image.20
tt_content.image.20 >
tt_content.image.20 = CASE
tt_content.image.20 {
key.field = layout
default < temp.image
101 < temp.image
101 {
??
}
}
As described here on TypoScript Reference you can use frame option to define the page:
10 = IMAGE
10.file = fileadmin/some.pdf
10.frame = 0
20 = < .10
20.frame = 1
etc.
But as I know there is no automatic mode to loop and detect if the frame exist in the pdf.

How to optimize the size of instagram images in a stream

I want to optimize the size of the images sent by the Instagram feed of a module on my prestashop shop.
How can I request images in smaller sizes, like 134x134px or 150x150px ...
My origin picture is :
https://scontent-cdt1-1.cdninstagram.com/vp/2c273bea214e232de2a2d6ded00cfd57/5D306C5B/t51.2885-15/sh0.08/e35/c135.0.809.809/s640x640/52890210_803725976651019_6529311483719815543_n.jpg?_nc_ht=scontent-cdt1-1.cdninstagram.com
But i will just, this picture is resized in HTML or CSS from 640x640 to 135x135.
Serving a scaled image could save 91.4KiB (95% reduction).
The imagecopyresampled() PHP function is perfect for this task, here is an example:
<?php
$filename = './test-instagram-orig.jpg';
$dest_filename = './test-instagram-resized.jpg';
$new_width = 150;
$new_height = 150;
$my_instagram_image = file_put_contents($filename, file_get_contents('https://scontent-sjc3-1.cdninstagram.com/vp/9844eb2fd4f4012141feef47d2eb97b2/5D389B06/t51.2885-15/sh0.08/e35/s640x640/10249289_1618492008409419_392402572_n.jpg?_nc_ht=scontent-sjc3-1.cdninstagram.com'));
list($width, $height) = getimagesize($filename);
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p, $dest_filename, 100);
imagedestroy($image_p);
echo '<img src="'.$filename.'" alt="" /> <img src="'.$dest_filename.'" alt="" />';
Voila! Of course you should integrate the following code into your module and make the appropriate changes.

Googlesheet > Script > PDF > Drive ---> exclude script buttons

I did a script to save my spreadsheet into a pdf in My Drive but... the PDF includes the script-bound buttons.
How can I prevent that?
Thanks!
(the text editor has a problem, my intro is missing)
enter image description here
This works:
var images = sheet.getImages();
var img = images[0];
img["delete"](); // this one
I just repeat it for each image like this:
var i4 = x[3];
i4.remove();
var i3 = x[2];
i3.remove();
var i1 = x[0];
i1.remove();

How to add Code128 Barcode image to existing pdf using pdfbox(1.8.12) with barcode4j library?

I am trying to generate the barcode from barcode4j library(code128bean, other barcode beans) and try to add to the existing pdf. The barcode image is getting created locally using the below code.
//Create the barcode bean
Code128Bean code128Bean = new Code128Bean();
final int dpi = 150;
code128Bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar
//width exactly one pixel
//bean.setCodeset(2);
code128Bean.doQuietZone(false);
//Open output file
File outputFile = new File("D:/barcode4jcod128.png"); //I dont want to create it
OutputStream code128Stream = new FileOutputStream(outputFile);
try {
//Set up the canvas provider for monochrome PNG output
BitmapCanvasProvider canvas1 = new BitmapCanvasProvider(
code128Stream, "image/x-png", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);
//Generate the barcode
code128Bean.generateBarcode(canvas1, "123456");
//Signal end of generation
canvas1.finish();
} finally {
code128Stream.close();
}
My problem is I don't want to create an image and save it locally in filesystem and then add it as image to pdf. I just want to create dynamically i mean just create the barcode image dynamically and add it to the pdf.
How do I set the pagesize (like PDPage.PAGE_SIZE_A4) to the existing PDPages which I retrieved from catalog.getAllPages() method, like (List<PDPage> pages = catalog.getAllPages();)
Can somebody help on this?
Thank you so much for your help Tilman. Here is what i did
public static BufferedImage geBufferedImageForCode128Bean(String barcodeString) {
Code128Bean code128Bean = new Code128Bean();
final int dpi = 150;
code128Bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar
code128Bean.doQuietZone(false);
BitmapCanvasProvider canvas1 = new BitmapCanvasProvider(
dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0
);
//Generate the barcode
code128Bean.generateBarcode(canvas1, barcodeString);
return canvas1.getBufferedImage();
}
// main code
PDDocument finalDoc = new PDDocument();
BufferedImage bufferedImage = geBufferedImageForCode128Bean("12345");
PDXObjectImage pdImage = new PDPixelMap(doc, bufferedImage);
PDPageContentStream contentStream = new PDPageContentStream(
finalDoc, pdPage, true, true, true
);
contentStream.drawXObject(pdImage, 100, 600, 50, 20);
contentStream.close();
finalDoc.addPage(pdPage);
finalDoc.save(new File("D:/Test75.pdf"));
The barcode is getting created the but it is created in vertical manner. i would like to see in horizontal manner. Thanks again for your help.
1) add an image to an existing page while keeping the content:
BitmapCanvasProvider canvas1 = new BitmapCanvasProvider(
dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0
);
code128Bean.generateBarcode(canvas1, "123456");
canvas1.finish();
BufferedImage bim = canvas1.getBufferedImage();
PDXObjectImage img = new PDPixelMap(doc, bim);
PDPageContentStream contents = new PDPageContentStream(doc, page, true, true, true);
contents.drawXObject(img, 100, 600, bim.getWidth(), bim.getHeight());
contents.close();
2) set the media box to A4 on an existing page:
page.setMediaBox(PDPage.PAGE_SIZE_A4);

Imagick - get a thumbnail for each page of a PDF file

I'm trying to get some information from pdf-files that i uploaded via move_uploaded_file().
I need thumbnails of each page to do some color analysis. further i need the width and height of each page in an actual unit of distance (not pixel).
is there a way to do the conversion from pdf to image in imagick not imagemagick. just because I'm using the imagick instace for the color analysis.
now this works for a single image file but not for a multipage pdf.
what to do know...?
/* Read the image */
$im = new Imagick($file);
/* Thumbnail the image */
$im->thumbnailImage(null, 200);
/* Overwrite it */
file_put_contents($file, $im);
/* Gather Info */
$width = $im->getImageWidth();
$height = $im->getImageHeight();
$ratio = $width / $height;
/* Calculate gray */
$pixel_count = 0;
$sum_gray = 0;
for ($row=0;$row<$height;$row++) {
for ($col=0;$col<$width;$col++) {
$pixel = $im->getImagePixelColor($col, $row);
$rgb = $pixel->getColor();
$this_gray = .299*$rgb['r'] + .587*$rgb['g'] + .114*$rgb['b'];
$sum_gray += $this_gray;
$pixel_count++;
}
}
$gray = (1-($sum_gray / $pixel_count) / 256)*100;
and if anybody knows how to get the height and width information, plaes let me know.
thanks for the help!