iTextSharp get PDF DPI - c#

How can I get the DPI of the PDF that I am reading from my hard drive into iTextSharp?

PDF's do not necessarily use DPI in their definitions. PDF's allow the document creator to define their own user coordinate space which may or may not map to anything similar to Dots Per Inch.

Check this How to calculate the correct image size in out pdf using itextsharp ?
PDF UserUnit shall give the size of default user space units, in multiples of 1 ⁄ 72 inch.
ISO-32000-1 (section 8.3.2.3) tells us
“the default for the size of the unit in default user space (1/72
inch) is approximately the same as a point (pt), a unit widely used in
the printing industry. It is not exactly the same; there is no
universal definition of a point.”
Conceptually, user space is an infinite plane. Only a small portion of this plane corresponds to the imageable area of the output device: a rectangular region defined by the CropBox entry in the page dictionary. The region of default user space that is viewed or printed can be different for each page.
Coordinates in user space (as in any other coordinate space) may be specified as either integers or real numbers, and the unit size in default user space does not constrain positions to any arbitrary grid. The resolution of coordinates in user space is not related in any way to the resolution of pixels in device space.

Related

c#, check area of pdf

I need to enter a text to existing pdf (in top or bottom of the page) in c#.
I need to make sure that I dont overwrite any visible text or image.
Is there any way I could check an area in pdf if it contains text, image, control etc? I understand it will not be 100% accurate
You're going to need a full PDF consumer at the very least, because the only way to find out where the marks are on the page is to parse (and possibly render) the PDF.
There are complications which you haven't covered (possibly they have not occurred to you); what do you consider to be the area of the PDF file ? The MediaBox ? CropBox, TrimBox, ArtBox, BleedBox ? What if the PDF file contains, for example, a rectangular fill with white which covers the page ? What about a /Separation space called /White ? is that white (it generally gets rendered that way on the output) or not ? And yes, this is a widely used ink in the T-shirt printing industry amongst others.
To me the simplest solution would seem to be to use a tool which will give you the BoundingBox of marks on the page. I know the Ghostscript bbox device can do this, I imagine there are other tools which can do so. But note (for Ghostscript at least); if there are any marks in white (whatever the colour space), these are considered as marking the page and will be counted into the bbox.
The same tool ought to be able to give the size of the various Boxes in the PDF file (you'd need the pdf_info.ps program for Ghostscript to get this, currently). You can then quickly calculate which areas are unmarked.
But 'unmarked' isn't the same things as 'white'. If you want to not count areas which are painted in 'white' then the problem becomes greater. You really need to render the content and then look at each image sample in the output to see if its white or not, recording the maxima and minima of the x and y co-ordinates to determine the 'non-white' area of the page.
This is because there are complications like transfer functions, transparency blending, colour management, and image masking, any or all of which might cause an area which is marked with a non-white colour to be rendered white (a transparency SMask for example) or an area marked with white to be rendered non-white (eg a transfer function).
Your question is unclear because you haven't defined whether any of these issues are important to you, and how you want to treat them.

Best Barcode Symbology for my Application

//Please don't close this post due to subjective reasons.
I'm developing a form-filling winform application which generates a PDF file on submitting the information. The PDF file need to contain barcodes encoding some information entered by user. The user prints the PDF file and put signature on it and faxes it back to us. I need suggestions for choosing which barcode symbology to use for this applcation.
The barcode needs to satisfy the following conditions.
1)The barcode need to encode upto 120 characters
Since the barcode need to encode a lot of information, I think 2D Barcode would be better as it can store with much high information density.
2)Only upper case alphabets and numbers need to be encoded
Though most of the 2D barcodes can store more than numbers, there are some 1D barcodes such as code 39 that cannot represent all alphabets.
3)Preferable size of barcode is 1.5 inch height and 8 inch width
This is what is the most challenging requirement. I'm planning to place the barcode below the information such as account id. So it would be good if barcode takes the shape of a rectangle whose information capacity increases with its width. This requirement is suitable for 1D barcodes. Also, since 2D barcodes takes the shape of a square, a lot of space will be wasted on either side of barcode.
4)Error correcting capability
2D barcodes have better error correcting capability. Only some 1D barcodes have error correction with it. This is not an essential requirement.
5)The barcode need to be faxed from one country to another
The barcode is generated on a PDF. The PDF will be printed and then need to be faxed. So, the barcode needs to have high resolution. Otherwise, I fear that the scanner cannot decode data correctly. I'm thinking a resoltion of 200dpi is enough for the barcode image. Is there any problem to fax 2D barcodes as they need to be scanned both horizontally and verically. I have heard like fax have different resolution vertically and horizontally. Does this create any problem when scanning barcodes.
6)Easiness to program in c# to generate barcode
Atlast but not the least, I need to program this barcode generation myselfin c#. So, there should be some free library available for the same. Aspose barcode is a good one. But it is costly.
I have come across the following Barcodes. I have checked the specification of some of these types. But couldn't reach a final decision. I can't turn back once I choose a barcode and start programming.
1D: UPC/EAN/JAN, Code 39, Code 128, Interleaved 2 of 5, Codabar, Code 11, Code 93, NEC 2 of 5, Matrix 2 of 5, Trioptic Code,
Stacked 1D: PDF417, Micro PDF417, Codablock A & F, Composite Codes
2D: Data Matrix, QR Code, Micro QR Code, Aztec Code, Maxicode
I am thinking of using PDF417. Does it have any disadvantages?
I don't know all formats so I can't say which is best.
Some of the 1D barcodes you mention (UPC/EAN) support only a small number of numeric characters. I know Code 128 supports variable length alphanumeric values, so that probably is a good 1D candidate.
Some barcode readers don't support 2D barcodes, this is usually a reason to use 1D.
Of 2D you should see if there is a symbology that does not require the barcode to be a square, because that would limit your maximum size to 1.5 by 1.5 inches.
There are several websites that let you create barcodes as images - perhaps you should just create a PDF containing those and fax them to see what happens.
I don't know of any free libraries to render them with; there are also fonts out there that allow creating 1D barcodes, and you can embed these fonts into your winforms application.
EDIT: 200 dpi on 8x1.5 inches would give you 1600 dots horizontally and 300 dots vertically to work with. A code128 barcode with a bar width of 1 pixel would come out at under 1400 dots.
On the wikipedia page for QR there is an example that takes up to 174 characters that has a size of 57x57 and high error correction. If I'm not mistaking, each dot could be represented by 5x5 pixels in 200dpi.

Image Co-Ordinate System Design

I'm diving into something without sufficient background, but I feel like there may be simple solutions that don't require me to have in depth knowledge of the topic.
What I am trying to do is have an image co-ordinate system. Basically the user will supply an image, like a house plan. They can then click on points in the image and create markers (like google maps). The next time they retrieve the map, all the markers they added before are there and they can add new ones.
I need to identify the points these markers are located on so I can store that information. I also need to be able to create a layer on the image that contains the markers and renders them in the exact locations they were placed.
I imagine the easiest way to do this is to use pixel co-ordinates...the rub here is that the image won't be a fixed size since there is a web application and an IPad application, so the co-ordinate system needs to work as long as the image is in the same size ratio.
The server size is .NET and as mentioned there is an IPad app, so the solution needs to be viable given that tech stack.
Any ideas?
Instead of using pixel coordinates in absolute terms, you can use the 0 to 1 range. The top left corner is (0,0), bottom right is (1,1) and the center of the image is (0.5,0.5). This way not matter what image size (or zoom level) you have, the markers will always be in the same place.
My suggestion is don't try to figure out the correlation between the actual image and the coordinates. The only thing I would do is use the resolution of the image, aka 800x600 and use that for your grid. Then overlay your markers using that grid on the image. The points you'd remember would just be X and Y values and maybe a tag name/id.

How to detect region of least energy in an Image

I want to programmatically place text on an image in an area where there is least "going on". It has been some time since I took Computer-Vision, could someone point me in the right direction. Either with respect to C# or Matlab?
I suggest dividing the image into distinct regions, each the size of the space you need for the text overlay. Calculate some measure of visual "energy", such as standard deviation, and choose the region with the lowest value. You could also slide a window around, looking for an arbitrary space of low energy, but this would be computationally much more expensive.
If you have the image processing toolbox for Matlab, you can run an entropy filter (ENTROPYFILT) on the image, matching the filter size to the size of your text. Then, all you need to do is find the filter-result with the smallest value, and you have the center of where you want to put the text.

Setting image DPI in relation to height/width C#

I'm writing an application to send some images to a third party, and the images must be 200x200 DPI. The image is a Bitmap and is sized at 500 width and 250 height.
The first time I tested the images with the third party, my resolution was incorrect. I merely used image.SetResolution(200,200) to correctly set it to 200x200. This, however, only changed the resolution tag for the image and did not properly, according to my third party technical contact, adjust the image height and width.
Is there a ratio that I can use so that for each X units I increment the resolution, I merely increment the corresponding height or width Y units? I thought that I could just increment resolution without having to increment height or width.
Thank you,
Aaron.
An image stored digitally has no meaningful concept of DPI. DPI comes into play when reproducing an image on a physical device.
You need to adjust the image size with regard to the DPI of the physical device, and the desired size of the output on that device.
For example, if a printer tells you they need an image at 300dpi to fill a space of 4in x 4in then you would provide them a bitmap with a size of 1200x1200 pixels. This image would end up with a physical size of 4in x 4in on a 300dpi output device. On a 600dpi device the same image would have an output size of 2in x 2in.
When dealing with digital images, you usually refer to PPI, which is pixels per inch. DPI is not directly related to digital image resolution.
So, if you look at a image that is 200px by 200px # 200PPI, you will have an image that is 1 inch by 1 inch.

Categories