Shrink Text in PDF using Ghostscript - ghostscript

Is it possible to shrink the size of text for a PDF Document using Ghostscript?
I've recently posted a question on how to shrink a two page pdf to one page, its close but I think If I can shrink the font a bit it would be perfect. I haven't been able to find anything online suggesting that you can shrink the size of the text... Is it capable of doing this?

Its possible, but it isn't easy and almost certainly won't help you.
You seem to be assuming that text in a PDF file works like it does in (eg) Word. If you change the size of the text then it all shuffles left a bit. In fact this is only partially the case. PDF files are intended to capture a particular layout, so the text description may include absolute positioning on the page, and white space addition/removal between words and glyphs. Changing the point size of the text wouldn't change the absolute positions, nor would it alter the white space which might lead to gaps, or to characters overlapping.
If you use -dPDFFitPage with a specific fixed media size, then you should be able to produce a resized PDF to fit the page you want.

Related

Best image file format for book pages

I wanted to scan Book pages and combine the images to an pdf "ebook" (just for me), but the file sizes get really huge. Even .jpg resulted in an pdf file with 60mb+ in size.
Do you have any idea how I can compress it any further? I.e. which file format I could choose for this specific purpose? (The book contains pictures and written text.)
Thank you for your help.
I tried to save it as .jpg and other file formats like .png, but didnt get small enough for the file to be easy handled, without loosing to much resolution.
Images are expensive things.
Ignoring compression you’re looking at 3bytes per pixel of data.
If you want to keep images you could reduce this by turning your images into greyscale. That reduces it to 1byte per pixel (again ignoring compression).
Or you could turn it into black and white. Which would be 1 but per pixel.
Or, alternatively, you could use OCR to translate your image into actual text which is a much more efficient way of storing books.

images are randomly blurry

I can't figure out why some images get blurry at different browser sizes. Take a look at this sample site:
The menu buttons at the top and the other buttons all shrink a bit when hovered over. Change the browser size a few times and see that some of them are blurry. Some actually get sharper when hovered over, some get blurrier.
I can't figure out how to solve this. They are all compressed the same way, all around the same resolution. Is there a specific size that they need to be to look better when scaled?
You are serving your image files way too large, causing the browser to spend time rescaling them to the size specified in the image tag. This causes the two-pass rendering that you are seeing.
For example, icon_profile2.png has the dimensions 2055x1712.
Resize your images to the desired size in your favorite image editor and use the scaled-down version on the website.

How to measure space between lines of text drawn on screen?

We have an end-user application that allows you to write multiple lines of text into a text box, it persists this information to a text file. Upon the next session that information is retrieved from the file to display the text. The problem is sometimes on the next session the bounds of the text box are cutting of the text so the user is having to manually resize the textbox. I'd like to programmatically figure out if the text box needs to be resized.
GetTextExtentPoint32() seems to work well for measuring the actual drawn width of the line based on the current font selected into the Device Context. However now I'm tackling the need to resize the textbox bounds in the vertical direction. GetTextExtentPoint32() does give me the height, which seems correct, but the total height I get is a bit too small. I believe I need to measure the space between each line, but I'm not quite sure?
Update: It looks like I'm looking for TEXTMETRIC.tmExternalLeading and TEXTMETRIC.tmInternalLeading. What's interesting is for some fonts and sizes, the calculation is spot on and I can fit my text perfectly. But for some fonts and sizes, the calculation is a bit too small, in that case it seems the leading is too small or 0?
As long as I remember you can use GetTextMetrics function and (Metrics.tmAscent + Metrics.tmDescent) should be the value you're looking for

Image format to put inside PDF's to have fast rendering

I would like to know which image format inside PDF's is rendered fastest. I tested mupdf code and I figured out that image decoding takes an important part in rendering time. So I would like to know if there are image formats that would not impact very much on cpu load.
I dont think this is really a question of what is best simply within PDFs, however:
As a general rule, I have always found that pre-rendering the image's size to the actual size you wish to present on screen is the best way to get both size and rendering speed to what you want them to be. Simply dragging an image into a document doesnt bring the pixel count (thus size) down as most document types simply put a display size tag around the full image. This causes the display program to have to real-time resize the image for display. The less the display program has to real-time resize the image the faster it will display.
As for file types:
Bitmaps are generally considered the fastest to display as they (for the most part) are copy and paste the color for each pixel onto the screen pixel. They are generally considered the biggest file. Depending on your images, if they aren't noisy (have a lot of solid runs of the same color) then they can be RLE encoded. I have seen many RLE encoded images that are indeed even smaller than JPEG images, but it is very situational.
JPEGs tend to be the smallest for transfer and also generally display decently quick. As an opinion they are also the lowest quality images (look close, if you started with a perfectly clean image, JPEG compression will add noise to it unless using lossless compression)
PNGs tend to be my favorite. They can be lossless compressed, can be fairly small if using flattened PNGs (i.e. NOT ADOBE FIREWORKS PNGs) and do produce crisp images that render fairly quickly.
So to sum up: I would probably recommend flattened PNGs that have been pre-sized and saved to the size you wish to display on screen.

How did Google images normalize the width of each row?

It's easy to resize images so that they all have the same height while maintaining the aspect ratio, but how did they fit them all on a row such that every row has the same width? Did they crop some of the images or what?
Remember in google images (apart from cropping) -
Spacing between images are not always exactly same.
Height of all images in a row are also not always same.
Using above 2 techniques i.e. tweaking the spaces between images and changing size of image little bit by compromising height you can achieve this. In fact the the justify paragraph option in the text editor also use the spacing technique. They evenly distribute the extra spacing between all word.
You don't always get a good spacing in google image search. See this -
alt text http://dailycoding.com/filesharing/Google_image_search.jpg
they actually figure it out through an algorithm to put images next to eachother so with the padding and everything they end up being the same width then they cache that page for the keyword you searched for!
I found a very interesting article while looking for the same thing. If you look at google images you can see not all of the rows have the same height. but all the images in a row have the same height. So what you want to do is calculate the right height you need for the row so the images will fit (the images stretch if they get higher or lower). This article will possible help
http://blog.vjeux.com/2012/image/image-layout-algorithm-google-plus.html

Resources