f



Converting a BMP image to PDF

Hi,
    I have written a jpeg to pdf conversion code in C. It is working
fine. Now i am trying for bmp images. bmp images are stored in bottom
up manner for which i wrote a function and inverted the image data.
Then i changed the RGB to BGR. Now the problem is the image is
displaying in PDF but it has tilted towards the right side.it is
displaying as if it was skewed for 30-45 degrees angle.
     Please let me know what should i do to make the image display in a
correct manner. Without applying my inverting function and RGB to BGR
function also the image is displayed in inverted and red and blue
colors are changed. But the image is displayed as rotated towards the
right side( tilted towards the right side).
here is the code for the pdf file.

I have used BMP file directly i have not used any compression. There
fore i have not mentioned any Filter.

%PDF-1.4
%=E2=E3=CF=D3
1 0 obj
<<
/Pages 2 0 R
/Type /Catalog
>>
endobj
2 0 obj
<<
/Count 1
/Kids [ 3 0 R ]
/Type /Pages
>>
endobj
3 0 obj
<<
/Contents [ 5 0 R ]
/Type /Page
/Parent 2 0 R
/MediaBox [ 0 0 723 535 ]
/CropBox [ 0 0 723 535 ]
/Resources 4 0 R
>>
endobj
4 0 obj
<<
/ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ]
/XObject <<
/Im1 6 0 R
>>
>>
endobj
5 0 obj
<<
/Length 31
>>
stream
q
723 0 0 535 0 0 cm
/Im1 Do
Q

endstream
endobj
6 0 obj
<<
/Type /XObject
/Subtype /Image
/Name /Im1
/Width 723
/Height 535
/ColorSpace /DeviceRGB
/BitsPerComponent 8
/Length 1162074
>>stream
BMZ=BB.....6...(...=D3..........$=BB.......
..=2E.
..=2E.
..=2E.( The whole BMP image including the BITMAPFILEHEADER,
BITMAPINFOHEADER)
endstream
endobj
xref
0 7
0000000000 65535 f
0000000015 00000 n
0000000064 00000 n
0000000123 00000 n
0000000258 00000 n
0000000353 00000 n
0000000434 00000 n
trailer
<<
/Size 7
/Root 1 0 R
/ID[<5181383ede94727bcb32ac27ded71c68><5181383ede94727bcb32ac27ded71c68>]>>
startxref
1162670
%%EOF

Please review the code and suggest solution for the tilting. Should i
use the image data without the headers in the stream?
Please suggest ur views.
Thanks and Regards
Kiran Hiremath

0
5/21/2005 1:08:29 PM
comp.text.pdf 5600 articles. 0 followers. ramon (1518) is leader. Post Follow

10 Replies
786 Views

Similar Articles

[PageSpeed] 44

kiranhiremath@gmail.com wrote:

>Hi,
>    I have written a jpeg to pdf conversion code in C. It is working
>fine. Now i am trying for bmp images. bmp images are stored in bottom
>up manner for which i wrote a function and inverted the image data.
>Then i changed the RGB to BGR. Now the problem is the image is
>displaying in PDF but it has tilted towards the right side.it is
>displaying as if it was skewed for 30-45 degrees angle.

Sounds as if you have done MOST of the things needed to do to convert
BMP pixels into the form PDF expects, but did you observe the scan
line boundary conditions?  BMP will sometimes add extra bytes at the
end of a scan line, PDF never will.
----------------------------------------
Aandi Inston  quite@dial.pipex.com http://www.quite.com
Please support usenet! Post replies and follow-ups, don't e-mail them.

0
quite
5/21/2005 3:34:50 PM
kiranhiremath@gmail.com wrote:

>Please review the code and suggest solution for the tilting. Should i
>use the image data without the headers in the stream?

Absolutely. If the PDF Reference doesn't mention something, you
generally have to assume it isn't allowed. Raw pixel data only. Also,
count the pixel bytes and make sure it matches what you expect, as a
double check and to prevent making a bad PDF.

Don't forget to either forbid or correctly processed BMP files with 16
and 256 colors, which map into an Indexed color space.
----------------------------------------
Aandi Inston  quite@dial.pipex.com http://www.quite.com
Please support usenet! Post replies and follow-ups, don't e-mail them.

0
quite
5/21/2005 3:36:45 PM
kiranhiremath@gmail.com wrote:
> Hi,
>     I have written a jpeg to pdf conversion code in C. It is working
> fine. Now i am trying for bmp images. bmp images are stored in bottom
> up manner for which i wrote a function and inverted the image data.
> Then i changed the RGB to BGR. Now the problem is the image is
> displaying in PDF but it has tilted towards the right side.it is
> displaying as if it was skewed for 30-45 degrees angle.
>      Please let me know what should i do to make the image display in a
> correct manner. Without applying my inverting function and RGB to BGR
> function also the image is displayed in inverted and red and blue
> colors are changed. But the image is displayed as rotated towards the
> right side( tilted towards the right side).
> here is the code for the pdf file.
> 
> I have used BMP file directly i have not used any compression. There
> fore i have not mentioned any Filter.
 >
> [PDF snipped]
> 
> Please review the code and suggest solution for the tilting. Should i
> use the image data without the headers in the stream?
> Please suggest ur views.

There's sam2p which does all that and more. It's software written in C++ 
with a GPL license.

http://www.inf.bme.hu/~pts/sam2p/

Ralf
0
Ralf
5/21/2005 5:36:25 PM
kiranhiremath@gmail.com wrote:

>    I have written a jpeg to pdf conversion code in C. It is working
>fine. Now i am trying for bmp images. bmp images are stored in bottom
>up manner for which i wrote a function and inverted the image data.

By the way, it is probably less work to set the image mirrored on the
page top to bottom than to invert top and bottom.
----------------------------------------
Aandi Inston  quite@dial.pipex.com http://www.quite.com
Please support usenet! Post replies and follow-ups, don't e-mail them.

0
quite
5/21/2005 9:28:29 PM
Thank You for the replies,
   I want to know that, Do i need to remove the padded bytes in the bmp
image or should i add the extra bytes. Tell me how to solve the extra
padding problem please.

Thanks and Regards
Kiran Hiremath

0
kiranhiremath
5/23/2005 5:26:38 AM
kiranhiremath@gmail.com wrote:
> Thank You for the replies,
>    I want to know that, Do i need to remove the padded bytes in the bmp
> image or should i add the extra bytes. Tell me how to solve the extra
> padding problem please.

Can you read Perl? If so, I can post code that will answer your 
questions, or that you can copy and use. It extracts the pixel data from 
a 24 bit BMP and re-writes into a form usable within a PDF file.

I also have a second script that will RLE encode that data that the 
first script outputs.
0
Scott
5/23/2005 6:40:14 AM
Thank You for replies,
i have solved the problem of extra padding bits.
  Thank You for the replies.

Now i am trying to use same code for bmp image of 256 colors. But the
acrobat reader is giving an error : A drawing error has occured. Please
let me know what change do i need to do in the image data which is 256
colors and do i need to change the colorspace from DeviceRGB to
something else.

Thanks and Regards
Kiran Hiremath

0
kiranhiremath
5/23/2005 11:11:35 AM
I got the BMP to PDF conversion for 24 bit bmp images. Now i am trying
for 256 colors and 16 colors. But i am getting the error : " A Drawing
error has occurred ". and a blank page is displayed.
 Here is a part of my code.
The image is saved in 16 colors format of size 400 * 300.
**********************************************************
5 0 obj
<<
/Length 31
>>
stream
q
400 0 0 300 0 0 cm
/Im1 Do
Q

endstream
endobj
6 0 obj
<<
/Type /XObject
/Subtype /Image
/Name /Im1
/Width 400
/Height 300
/ColorSpace /DeviceRGB
/BitsPerComponent 4
/Length 60000
>>stream
=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF....
..=2E.
..=2E.( Raw Image Data)
endstream
endobj

I am getting the error " " A Drawing error has occurred ". and a blank
page is displayed.
Please tell me a solution for my problem
if i make the ColorSpace as DeviceGray then a grayscale image is
displayed. How to get the color image.
Thanks and regards
kiran hiremath

0
kiranhiremath
5/23/2005 1:50:06 PM
kiranhiremath@gmail.com wrote:

>   I want to know that, Do i need to remove the padded bytes in the bmp
>image or should i add the extra bytes. 

Yes, you must remove any extra bytes IF they are there. Compare the
specficications.

A good way to check is to make sure you have exactly the number of
bytes that the PDF file will need.
----------------------------------------
Aandi Inston  quite@dial.pipex.com http://www.quite.com
Please support usenet! Post replies and follow-ups, don't e-mail them.

0
quite
5/24/2005 7:03:57 AM
kiranhiremath@gmail.com wrote:

>Thank You for replies,
>i have solved the problem of extra padding bits.
>  Thank You for the replies.
>
>Now i am trying to use same code for bmp image of 256 colors. But the
>acrobat reader is giving an error : A drawing error has occured. Please
>let me know what change do i need to do in the image data which is 256
>colors and do i need to change the colorspace from DeviceRGB to
>something else.

You have to extract the color map from the BMP, and use that to create
an indexed color space in the PDF. As with the pixel data, compare the
exact format required between a BMP color map and PDF color map. You
might need to deal with padding, byte reordering - I can't remember
the BMP format in enough detail.
----------------------------------------
Aandi Inston  quite@dial.pipex.com http://www.quite.com
Please support usenet! Post replies and follow-ups, don't e-mail them.

0
quite
5/24/2005 7:05:50 AM
Reply: