Page 1 of 1

Set Data in Image and Print in actual size (sample is need)

Posted: Tue Jul 28, 2009 6:44 pm
by Tomi
Hello
I've a worksheet as an image and need set my data into image (Only in memory, no change image putted in hard).
and next, need print the result in actual size.
i have not sample for whatever i needing.
give me a sample please .

Data be number or text, anything. example 1 to 20......

if maybe "Loop" use for set Data in cells.
thank you beforehand.

Attached Image:
http://rapidshare.com/files/261074999/W ... S.rar.html
5Kb

Posted: Wed Jul 29, 2009 6:14 pm
by Tomi
Image

i try this:

Code: Select all

UseTIFFImageDecoder()
LoadImage(29, "C:\WorkSheetXLS.tif");<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Iw = ImageWidth(29) : Ih = ImageHeight(29);

StartDrawing(ImageOutput(29))
  DrawingMode(1);
  For x = 40 To Ih-20 Step 20
    DrawText(100, x, "Test" + Space(10) + "Test" + Space(10) + "Test" + Space(10) + "Test" + Space(10) + "Test")
  Next
StopDrawing()


#Win1=1;



OpenWindow(#Win1, 0, 0, Iw, Ih, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Invisible);
  ImageGadget(100, 0, 0, Iw, Ih, ImageID(29));
  HideWindow(#Win1, 0);
Repeat
  MyEvWin1 = WaitWindowEvent();
  Select MyEvWin1
    Case #WM_CLOSE
       Exit = 1;
  EndSelect
Until Exit = 1;
i need a way for calibration(adjustment text in cell exactly) this, otherwish i must be use textDraw() for put a text in per cell ,that's not Clean.
Oh, have you a pure way?

Posted: Fri Jul 31, 2009 6:52 am
by Tomi
Please right click on pic and save as "C:\WorkSheetXLS.tif"

Image

Code: Select all

UseTIFFImageDecoder()
LoadImage(29, "C:\WorkSheetXLS.tif");<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Iw = ImageWidth(29) : Ih = ImageHeight(29);

StartDrawing(ImageOutput(29))
  DrawingMode(1);
  For x = 40 To Ih-20 Step 20
    If x = 80 : x=x+3 : EndIf
    DrawText(100, x, "Test" + Space(10) + "Test" + Space(10) + "Test" + Space(10) + "Test" + Space(10) + "Test")
  Next
StopDrawing()


#Win1=1;


OpenWindow(#Win1, 0, 0, Iw, Ih, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_Invisible);
  ImageGadget(100, 0, 0, Iw, Ih, ImageID(29));
  HideWindow(#Win1, 0);
Repeat
  MyEvWin1 = WaitWindowEvent();
  Select MyEvWin1
    Case #WM_CLOSE
       Exit = 1;
  EndSelect
Until Exit = 1;

PrintRequester()
  StartPrinting("PureBasic Test")
     StartDrawing(PrinterOutput())
        DrawImage(ImageID(29), 0, 0, Iw, Ih);
     StopDrawing()

  StopPrinting()
End

This code has followed pic result:
Microsoft Office Document Image Writer

Image

and if i load same pic in MS-Word , i will have result with actual size:
Microsoft Office Document Image Writer

Image

if you please ,help me friends. :cry:

Posted: Fri Jul 31, 2009 7:47 am
by infratec
Hi Tomi,

The result is ok.

Why:

Your image has 432 x 508 pixel.
If your printer has a resolution of 600dpi, this results in:

0.72 inch x 0.8467 inch.

If you want a printout as expected (WYSIWIG :lol:), you have to magnify the size of the picture by 8.33..

Explanation:

The computer screen has a defined resolution of 72dpi (should have).
If you want to print this on a 600dpi device you need a magnification by:

600 / 72 = 8.3333....



Code: Select all

StartDrawing(PrinterOutput())
 DrawImage(ImageID(29), 0, 0, Iw * 8.33, Ih * 8.33);
StopDrawing()
Best regards,

Bernd

Posted: Fri Jul 31, 2009 8:11 am
by infratec
Or better (if you need high quality):

use a picture in the right resolution for printing.
This results in better quality, since you need no magnification.


Bernd

Posted: Fri Jul 31, 2009 8:18 am
by infratec
Hi again,

since different printers use different dpi, you have to find out the actual dpi
to calculate the magnification.

For this you can use the functions

PrinterPageWidth()
PrinterPageHeight()

If you use a fixed papersize, DIN A4 for example, than you can calculate the printer dpi with:

PrinterPageHeight() / 11.7


So the factor is:

PrinterPageHeight() / 11.7 / 72

or

PrinterPageHeight() / 842.4

Code: Select all

StartDrawing(PrinterOutput())
 Magnification = PrinterPageHeight() / 842.4
 DrawImage(ImageID(29), 0, 0, Iw * Magnification, Ih * Magnification);
StopDrawing()

Bernd

Thankful

Posted: Fri Jul 31, 2009 8:20 am
by Tomi
Image
Hello
Thankful infratec, you save me really .
your explanation was very helper to me.
have best time
Image

Posted: Fri Jul 31, 2009 8:22 am
by infratec
Please read the posting before yours,

I edited it while you was reading.

Bernd

Posted: Fri Jul 31, 2009 8:35 am
by infratec
And also centered:

Code: Select all

StartDrawing(PrinterOutput())
 Magnification = PrinterPageHeight() / 842.4
 DrawImage(ImageID(29), (PrinterPageWidth() - Iw * Magnification) / 2, (PrinterPageHeight() - Ih * Magnification) / 2, Iw * Magnification, Ih * Magnification);
StopDrawing()
Bernd

Posted: Fri Jul 31, 2009 8:37 am
by Tomi
Ok, i need result in A4 standard paper exactly
i knowledge is poor about printing

when i use:

Code: Select all

DrawImage(ImageID(29), 0, 0, PrinterPageWidth(), PrinterPageHeight() / 11.7 / 72); 
result was very bad, sorry i think i don't understand your meaning as well.

this:

Code: Select all

DrawImage(ImageID(29), 0, 0, PrinterPageWidth()/2.5, PrinterPageHeight() / 1.5); 
has near to actual size
Image

Posted: Fri Jul 31, 2009 8:39 am
by infratec
Hi Tomi,

please read the posts above.
Since we are writing at the same time, our postings overlap.

You need to multiply the factor with the size of the image :!:

Bernd

Posted: Fri Jul 31, 2009 8:43 am
by Tomi
infratec wrote:And also centered:

Code: Select all

StartDrawing(PrinterOutput())
 Magnification = PrinterPageHeight() / 842.4
 DrawImage(ImageID(0), (PrinterPageWidth() - Iw * Magnification) / 2, (PrinterPageHeight() - Ih * Magnification) / 2, Iw * Magnification, Ih * Magnification);
StopDrawing()
Bernd
oh ,on until i typing last post, you solve my problem as well.
Thankful
you have good information about printing.
ImageImageImage

Posted: Fri Jul 31, 2009 8:59 am
by infratec
Hi Tomi,

one last thing:

You need to test the result of StartPrinting().
Else, when someone cancel the printing, you run in trouble.

Code: Select all

If MessageRequester("Worksheet", "Do you want to print it?", #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes

 PrintRequester()
  If StartPrinting("PureBasic Test")
   StartDrawing(PrinterOutput())
   Magnification = PrinterPageHeight() / 842.4
   DrawImage(ImageID(29), (PrinterPageWidth() - Iw * Magnification) / 2, (PrinterPageHeight() - Ih * Magnification) / 2, Iw * Magnification, Ih * Magnification);
   StopDrawing()
   StopPrinting()
  EndIf
 
EndIf
And:

That was my first thing I ever printed out with a own program.

Bernd

Posted: Fri Jul 31, 2009 12:27 pm
by Tomi
very well Bernd
i forget if user cancel the print operation ,its will error occurred
many thanks for all helps