Two related questions:
I am searching for a way to insert quickly insert images into document. If an image is already loaded into memory can I create a picture based on an image handle, a stream, or some other in-memory device? Woul the format of this image be restricted to BMP and JPEG?
From the Developer Manual: "Developers can now define their own object types that are completely managed outside of the PDF Creator." I don't understand how this works. How do I define my own object type? How is this object type written to the resulting PDF file? Could I define an image object type that handles images that are CCITT compressed?
Thanks,
Charles
Inserting Image Objects
More questions...
If a document has a picture object is there any way I can access the image data? Can I get a handle to the data or save it out separately to another file, etc...?
Hello,
I am not sure if this is what you are refering to but below is a visual basic 6.0 code snippet which illustrates the loading of a picture object in the PDF Creator from an image stream.
' Create picture object in the PDF Creator
Doc1.CreateObject acObjectTypePicture, "Picture1"
Set obj = Doc1.GetObjectByName("Picture1")
With obj
' set picture size
obj.Attribute("Left") = 100
obj.Attribute("Top") = 100
obj.Attribute("Right") = 900
obj.Attribute("Bottom") = 900
' set picture parameters
obj.Attribute("BitmapWidth") = img.Width
obj.Attribute("BitmapHeight") = img.Height
obj.Attribute("BitsPerComponent") = 24 ' assuming data is stored in RGB format
' get image pixels and store them in Creator Picture object
ReDim pixels(img.ARGBData.Count * 3)
For n = 0 To img.ARGBData.Count - 1
pixels(n * 3) = &H80 ' GetBlue(pixel)
pixels(n * 3 + 1) = &H80 ' GetGreen(pixel)
pixels(n * 3 + 2) = &H80 ' GetRed(pixel)
Next n
' Set bitmap data
obj.Attribute("BitmapData") = pixels
' Force image to grayscale as this will produce best results for scanned images
' obj.Attribute("GrayScale") = 1
End With
Hope this helps?
I am not sure if this is what you are refering to but below is a visual basic 6.0 code snippet which illustrates the loading of a picture object in the PDF Creator from an image stream.
' Create picture object in the PDF Creator
Doc1.CreateObject acObjectTypePicture, "Picture1"
Set obj = Doc1.GetObjectByName("Picture1")
With obj
' set picture size
obj.Attribute("Left") = 100
obj.Attribute("Top") = 100
obj.Attribute("Right") = 900
obj.Attribute("Bottom") = 900
' set picture parameters
obj.Attribute("BitmapWidth") = img.Width
obj.Attribute("BitmapHeight") = img.Height
obj.Attribute("BitsPerComponent") = 24 ' assuming data is stored in RGB format
' get image pixels and store them in Creator Picture object
ReDim pixels(img.ARGBData.Count * 3)
For n = 0 To img.ARGBData.Count - 1
pixels(n * 3) = &H80 ' GetBlue(pixel)
pixels(n * 3 + 1) = &H80 ' GetGreen(pixel)
pixels(n * 3 + 2) = &H80 ' GetRed(pixel)
Next n
' Set bitmap data
obj.Attribute("BitmapData") = pixels
' Force image to grayscale as this will produce best results for scanned images
' obj.Attribute("GrayScale") = 1
End With
Hope this helps?
That helps quite a bit
Thanks for the reply. What other undocumented image attributes are available? or is this anywhere they are documented?
Charles
Charles
1 bit images
I've tested the above code and found that it works well, except for 1 bit images. At the end of my post is some sample Delphi code I've been using. It works fine for 24 bit images, but breaks on 1-bit images. I've found that by doubling the size of my pixels array the following code will "work" - it will display the image in an inverted form. However, if I try to save the resulting PDF I get an error.
Hope you can help?
Charles
Sample Delphi Code:
PDF.InitBlank;
ANumBytes:=(ldImg.BitmapBits * ldImg.BitmapWidth * ldImg.BitmapHeight) div 8; // Calculate size (in bytes) of image data
if ((ldImg.BitmapBits * ldImg.BitmapWidth * ldImg.BitmapHeight) mod 8) > 0 then
inc(ANumBytes); // round up for 1 or 4-bit images
SetLength(Pixels, ANumBytes); //Works (until you try to save) if SetLength(Pixels, ANumBytes * 2); is used when working with 1 bit images
ldImg.GetBitmapRow(Pixels, 0, ANumBytes); // Fills Pixels with image data
PDF.CreateObject(acObjectTypePicture , 'Pic10');
with PDF.GetObjectByName('Pic10') do
begin
Attribute['Left'] := 0;
Attribute['Top'] := 0;
Attribute['Right'] := PDF.PageWidth;
Attribute['Bottom'] := PDF.PageLength;
Attribute['BitmapWidth'] := ldImg.BitmapWidth;
Attribute['BitmapHeight'] := ldImg.BitmapHeight;
Attribute['BitsPerComponent'] := ldImg.BitmapBits; //24 for color, 1 for B&W, 8 for grayscale
Attribute['BitmapData'] := Pixels;
end;
PDF.Refresh;
Hope you can help?
Charles
Sample Delphi Code:
PDF.InitBlank;
ANumBytes:=(ldImg.BitmapBits * ldImg.BitmapWidth * ldImg.BitmapHeight) div 8; // Calculate size (in bytes) of image data
if ((ldImg.BitmapBits * ldImg.BitmapWidth * ldImg.BitmapHeight) mod 8) > 0 then
inc(ANumBytes); // round up for 1 or 4-bit images
SetLength(Pixels, ANumBytes); //Works (until you try to save) if SetLength(Pixels, ANumBytes * 2); is used when working with 1 bit images
ldImg.GetBitmapRow(Pixels, 0, ANumBytes); // Fills Pixels with image data
PDF.CreateObject(acObjectTypePicture , 'Pic10');
with PDF.GetObjectByName('Pic10') do
begin
Attribute['Left'] := 0;
Attribute['Top'] := 0;
Attribute['Right'] := PDF.PageWidth;
Attribute['Bottom'] := PDF.PageLength;
Attribute['BitmapWidth'] := ldImg.BitmapWidth;
Attribute['BitmapHeight'] := ldImg.BitmapHeight;
Attribute['BitsPerComponent'] := ldImg.BitmapBits; //24 for color, 1 for B&W, 8 for grayscale
Attribute['BitmapData'] := Pixels;
end;
PDF.Refresh;