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

Just starting out? Need help? Post your questions and find answers here.
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

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

Post 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
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Post 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?
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Post 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:
infratec
Always Here
Always Here
Posts: 7604
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Post 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
infratec
Always Here
Always Here
Posts: 7604
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Post 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
infratec
Always Here
Always Here
Posts: 7604
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Post 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
Last edited by infratec on Fri Jul 31, 2009 8:40 am, edited 6 times in total.
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Thankful

Post by Tomi »

Image
Hello
Thankful infratec, you save me really .
your explanation was very helper to me.
have best time
Image
infratec
Always Here
Always Here
Posts: 7604
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Post by infratec »

Please read the posting before yours,

I edited it while you was reading.

Bernd
infratec
Always Here
Always Here
Posts: 7604
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Post 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
Last edited by infratec on Fri Jul 31, 2009 8:40 am, edited 1 time in total.
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Post 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
infratec
Always Here
Always Here
Posts: 7604
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Post 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
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Post 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
infratec
Always Here
Always Here
Posts: 7604
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Post 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
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Post by Tomi »

very well Bernd
i forget if user cancel the print operation ,its will error occurred
many thanks for all helps
Post Reply