Pages

Search This Blog

Friday, May 13, 2016

An Example of Converting PDF grid to a BMP file


Yesterday I posted a blog about converting a grid pattern into a bitmap, for use with, e.g., SuperbaKnit software. Today I am going to go through the same thing with examples, using a file that I made up.

To use this tutorial you will need:

  • A computer with Adobe Acrobat Reader and GIMP installed. I work on a Windows machine, so Mac users may need to do some translation. Having said that, both free software packages are available on Macs as well.
  • This PDF file with the patterns in it.

The pdf file has two pages with two different types of grids. The first page has dots; the second has filled squares. Each grid square represents one stitch, and is made up of many pixels wide and tall; we want to produce a bit map file with one pixel per stitch.

Here is a step-by-step process:

Open the file in Adobe Acrobat Reader.
Let's start with Pattern 1. From the menu, we choose Edit > Take a Snapshot
Using the mouse, drag and drop a rectangle around the grid you want to convert (Figure 1). For this example, I've selected a larger section of the page, so you can see the cropping later.
Figure 1. Screen shot of PDF in Adobe Acrobat Reader, showing the SnapShot region in blue

Now the image that you have selected (the part in blue) is saved in the computer Clipboard, and you can use it in other programs.

Open GIMP.
From the menu, choose File > Create > From Clipboard
You should see a copy of the part of the PDF that you just selected now in GIMP. (Figure 2)


Figure 2. Screenshot showing image now in GIMP


CROP THE IMAGE
We want to crop the image to only show the grid.
From the menu, select Tools > Transform Tools > Crop
Your cursor will now look like a little scalpel, with a cross-hair pattern. Line the cross-hair up with the corner of the grid, and select the part of the image you want to keep. When you let go, you can see where the cropped area is, and you can adjust it if you like. When you are satisfied, press ENTER, and the cropped region will be left.

Figure 3. Selection of the grid within GIMP, ready to crop

Now the greyed-out regions in Figure 3 are removed, leaving only the grid (Figure 4).


Figure 4. Screenshot showing the cropped area selected.

The next step is to change the way that the image is stored. By default, the image will be in a colour (RGB) format, with many, many colours. We want to end up with a black and white image, with only two colours (black and white). 
From the menu choose Image > Mode > Indexed
A box will pop up. Choose the line that says "Use black and white (1-bit) palette", in the middle of the box, then click on the CONVERT button at the bottom.

The changes will be comparatively minor: the edges of the circles in the image may look a bit less smooth, and you may notice some irregularities in the lines.

In the next step, we will be shrinking the image down. In my case, the image is 362 x 224. Counting the squares in the grid, we want a 12 x 8 bitmap file.

From the menu, choose Image > Scale Image. For Width, type in 12, then hit tab. In my case, I get a value for Height of 7. This isn't going to give us the right pattern. 

To the right of the boxes for Width and Height there is something that looks like a chain link. When the chain is closed, Width and Height are changed proportionately. If you click on that, it will open, allowing you to choose values that are not scaled in exactly the same way.

With the chain open, I can type in 12 for width and 8 for height. When I click on Scale, the image is rescaled to be 12 pixels wide by 8 pixels high. 

Figure 5. Image Scaling box in GIMP. Click to open the chain to the right of  Width / Height,
then type in the sizes you need.


Typing + will zoom in so you can see the new file. Each black or white square is actually a single pixel.

Figure 6. The new re-scaled file is 12 pixels wide and 8 pixels high. You will need to zoom in to see it.


Finally, we need to save the file as a BMP file, which involves Exporting it. 
From the menu, choose File > Export > 

Figure 7. Export menu, to save the file as a BMP file. You need to pick a Folder, give the file a name, and choose a file type.


Now you have completed the conversion, and your BMP file is ready to bring into SuperbaKnit.





So, this is how you can take a graphed chart such as the one above here and turn it into a bitmap file with one pixel per square, as on the right.











You can do the same thing for the other two patterns on page 1 of this PDF. 








Thursday, May 12, 2016

How to take an image of a grid from a PDF and convert it into a bitmap using free software


I recently intalled the SuperbaKnit interface on my Superba S-48. The SuperbaKnit software can work with bitmap files. I've figured out how to take an image of a grid with a pattern in it and convert it into a bitmap file.

I am working in Windows XP, using Adobe Reader XI and GIMP 2.8.16

Here is a step by step guide:

1. Download and install the free software.
Adobe Acrobat Reader from www.adobe.com
GIMP from gimp.org

2. Open the PDF in Adobe Reader. Find the grid in the PDF that you want to copy.

3. From the menu, choose Edit > Take a SnapShot

4. Using your mouse, draw a rectangle around the grid you want. When you let the mouse button go, a snapshot of the selected region is copied into the clipboard.

5. Open GIMP. From the menu, choose File > Create > From Clipboard

6. You should have a new file open with the selected area from the PDF in it.

7. CROP the image so that only the grid is visible.
From the menu, choose Tools > Transform Tools > Crop
Place your mouse at one corner of the grid, click and drag to select the entire grid. Let go. You can adjust the crop lines by moving to the centre of any of the lines and dragging.
When you are satisfied with the region you have selected to crop, hit ENTER, and the image will be cropped.

** Sometimes the original image needs to be rotated so that it is square on the page. From the menu, choose Layers > Transform > Arbitrary Rotation
I find that usually my rotations have been between 0.1 and 0.5 degrees, but play around until you have the grid as close to vertical as you can manage.
You probably need to crop again after you have rotated.

8. Now set the Mode of the image to be black and white.
From the menu, choose Image > Mode > Indexed  and choose "use black-and-white palette (1 bit)"
Click Convert.
Now your image is a bitmap, with each pixel either white or black

9. Finally, scale your image so that there is one pixel per grid cell.
From the menu, choose Image > Scale Image
Type in the grid dimension in width, and when you move out of that cell, height will be set. Check that the height matches the number of cells in your grid.
I have found that sometimes I get the right numbers if I set height.
If you still don't have the right size, go back and crop the image a bit more.

10. Now that you have a bitmap that corresponds to the grid, you need to save it.
From the menu, choose File > Export
At the top of the screen, you can set the Folder where the image will be placed, and the name of the file.
At the bottom left, there is a plus sign next to "Select File Type". Click the +, and scroll down to Windows BMP image. Click the Export button.

Now you have a bitmap that corresponds to the grid image in your pdf file.

I hope these instructions help.