Page 1 of 1

Tiff Rendering Issue

Posted: Tue Feb 02, 2010 12:39 am
by edatmitchell
We are attempting to use your Raster-XChange product as a drop-in replacement to our current tiff print image drivers. We are trying your product for its ability to install under 64-bit environments.

Our program requires us to produce tiff image files as a rendered copy of a printout that the user would create using our product. We are finding that the pagination is not the same when printing a hardcopy versus the tiff image files generated using Raster-XChange.

Basically we are doing the following:
1. Print a hardcopy of our data using a user selected printer.
2. Initialize Raster-XChange print driver:

Code: Select all

bool TrackerTiffImageDriver::InitializeDriver()
RXC::IPrinterFactoryPtr factory(__uuidof(RXC::PrinterFactory));
m_printer = factory->Printer[_T(""), _T("")];
m_printer->ProtectionKey = _T("XXXX");
m_printer->ProtectionDevCode = _T("XXXXXX");
CString strName = (const char*)m_printer->Name;

m_devMode = m_printer->DevMode;
m_devMode->Format = RXC::format_TIFF;
m_devMode->FormatParameter[_T("Image Type")] = _T("BW:1");
m_devMode->FormatParameter[_T("Compression")] = _T("CCITTFax4");
m_devMode->PostPrintApplication = _T("");

m_devMode->PaperForm = DMPAPER_LETTER;
m_devMode->PaperOrientation = DMORIENT_PORTRAIT;

m_devMode->VertResolution = 300;
m_devMode->HorzResolution = 300;

m_devMode->OutputFileName = (const char*)GetImageFileFullPath();

// Save the settings

return true;
3. Clone the user selected printer’s DEVMODE to the tiff image print driver (passing in the Raster-XChange’s printer name and the DEVMODE of the user's selected printer):

Code: Select all

// This is an alternative to CreateDevMode, and it attempts to "clone" the printer's setup from 
// pDevModeSource.
DEVMODE *PrintImageDriver::CloneDevmodeSettings(const CString &sPrinterDriverName, DEVMODE *pDevModeSource)
   LPDEVMODE pDevModeDest = CreateDevMode(sPrinterDriverName);

   if (!pDevModeDest)
      return NULL; // error already reported in CreateDevMode
   // Make changes to the DevMode which are supported on both source and target
   if (pDevModeDest->dmFields & DM_ORIENTATION && pDevModeSource->dmFields & DM_ORIENTATION)
      pDevModeDest->dmOrientation = pDevModeSource->dmOrientation;
   if (pDevModeDest->dmFields & DM_PAPERSIZE && pDevModeSource->dmFields & DM_PAPERSIZE)
      pDevModeDest->dmPaperSize = pDevModeSource->dmPaperSize;

   if (pDevModeDest->dmFields & DM_PAPERLENGTH && pDevModeSource->dmFields & DM_PAPERLENGTH)
      pDevModeDest->dmPaperLength = pDevModeSource->dmPaperLength;
   if (pDevModeDest->dmFields & DM_PAPERWIDTH && pDevModeSource->dmFields & DM_PAPERWIDTH)
      pDevModeDest->dmPaperWidth = pDevModeSource->dmPaperWidth;
   if (pDevModeDest->dmFields & DM_PRINTQUALITY && pDevModeSource->dmFields & DM_PRINTQUALITY)
      pDevModeDest->dmPrintQuality = pDevModeSource->dmPrintQuality;

   if (pDevModeDest->dmFields & DM_SCALE && pDevModeSource->dmFields & DM_SCALE)
      pDevModeDest->dmScale = pDevModeSource->dmScale;
   if (pDevModeDest->dmFields & DM_COLOR && pDevModeSource->dmFields & DM_COLOR)
      pDevModeDest->dmColor = pDevModeSource->dmColor;
   // Open the printer 
   HANDLE hPrinter = NULL;
   if (!OpenPrinter((PSTR)(PCSTR)sPrinterDriverName, &hPrinter, NULL))
      Error(0,"CloneDevmodeSettings couldn't open printer named %s",(PCSTR)sPrinterDriverName);
      return NULL;

   // Step 3: Merge the new settings with the old.
   // This gives the driver a chance to update any private portions of the DevMode structure.
   LONG lRet = DocumentProperties(NULL,
                                  pDevModeDest,   // Reuse our buffer for output.
                                  pDevModeDest,   // Pass the driver our changes.
                                  DM_IN_BUFFER |  // Commands to Merge our changes and 
                                  DM_OUT_BUFFER); // write the result.
   // Done with the printer
   if (lRet != IDOK)       // if failure, cleanup and return failure
      delete pDevModeDest;
      Error(0,"CloneDevmodeSettings couldn't call DocumentProperties(2) for printer named %s lRet=%d",(PCSTR)sPrinterDriverName,lRet);

   return pDevModeDest; // return the modified DevMode structure
4. Create the tiff image copy by paginating through the data.
5. Compare the hard copy with the tiff image files. Images are not the same. Additionally the tiff images produced become stretched out because the resolution is now 600x300 dpi instead of 300x300 dpi.

Do you have any suggestions on how to proceed? Is what we are attempting not possible using your drivers?

Re: Tiff Rendering Issue

Posted: Tue Feb 02, 2010 11:34 am
by Roman - Tracker Supp
Could you provide your code for
1. CreateDevMode function.
2. actual printing to Raster-XChange.

If possible, a complete working sample that reveals your problem would be appreciated.

Re: Tiff Rendering Issue

Posted: Wed Mar 17, 2010 4:01 pm
by edatmitchell
After a project break, I was able to produce a test app that duplicates the problem. See attached.

Re: Tiff Rendering Issue

Posted: Wed Mar 17, 2010 4:07 pm
by edatmitchell
Somehow my attachment did you go through. Perhaps because there's an .exe in it. I'll try again without it.

Re: Tiff Rendering Issue

Posted: Wed Mar 17, 2010 9:29 pm
by Roman - Tracker Supp
Please wrap your files in a zip (or rar, 7z, etc) archive otherwise your attachment may be refused.

Re: Tiff Rendering Issue

Posted: Wed Mar 17, 2010 10:38 pm
by edatmitchell
Okay. Didn't see the 5mb file limit size error. Trying again.

Re: Tiff Rendering Issue

Posted: Wed Mar 17, 2010 10:43 pm
by Paul - Tracker Supp
thanks for the file edatmitchell,

we got it this time. Roman is done for today but you can expect an answer tomorrow.


Re: Tiff Rendering Issue

Posted: Thu Mar 18, 2010 3:41 pm
by Roman - Tracker Supp
Hi edatmitchell

In PrintImageDriver::Create() function you at first setup Raster-XChange printer default settings (paper size, resolution, image format, and so on) by calling InitializeDriver() and then create DC on this printer specifying another devmode for CreateDC, thus effectively overriding the settings done in InitializeDriver.

If you change PrintImageDriver.cpp (64) to:

Code: Select all

   if(!m_pDC->CreateDC("WINSPOOL", m_sDriverName, NULL, [b]NULL[/b]))
you will get the output image with the page size and resolution specified in InitializeDriver.

Re: Tiff Rendering Issue

Posted: Thu Apr 01, 2010 6:39 pm
by edatmitchell
Hi Roman,

This does not work. Even when the parameter is set to NULL, the output from the tiff image file does not match the output from the default printer (or even the printpreview). What we are trying to accomplish is to create a devmode that duplicates the default printer's output and thus preserve the pagination.

Do you have any other solutions or workarounds?

Re: Tiff Rendering Issue

Posted: Fri Apr 02, 2010 11:34 am
by Roman - Tracker Supp
hi edatmitchell,

The size and resolution of the image created by your test app via Raster-XChange are exactly as specified - Letter @ 300x300 dpi (i.e. 2550x3300 pixels).
The difference in pagination with a hardcopy is because real printers cannot print over the entire physical page area - commonly margins are about 0.25 inch.
Raster-XChange being a virtual printer does not have such limitaitons - its printable area is of the same size as the "physical" page.
Thus you will get different printable area for different printers even for the same page size.
You can verify this yourself - just compare values returned by GetDeviceCaps for HORZRES/VERTRES vs PHYSICALWIDTH/PHYSICALHEIGHT.
You will see that for a real printer *RES is always smaller than corresponding PHYSICAL*.
You should take this into account in your pagination code.

Re: Tiff Rendering Issue

Posted: Thu Apr 08, 2010 7:24 pm
by edatmitchell
Hi Roman,
Yes, I had removed the code that handled the margins to make the sample easier to understand, but the problem still exists. Here’s why:

Assume 8.5” x 11” paper with .5” top and bottom margin. Printable area is now 10”.

For a 600 dpi printer (6000 pixels high) –
Requesting an 11pt font from the GDI gets an 104 pixel per line (font height + leading) resulting in a page with (6000 / 104 =) 57 lines.

For a 300 dpi tiff (3000 pixels high) –
Requesting an 11pt font from the GDI gets an 51 pixel per line (fontheight + leading) resulting in a page with (3000 / 51 =) 58 lines.

This results in our pagination being off. Note: Our pagination routines are rather complex with different font heights, user selectable fonts and separator lines and pagination rules such as “keep-sections-together” that will force whole sections onto new pages if there isn’t room on the current page.

Re: Tiff Rendering Issue

Posted: Fri Apr 09, 2010 9:09 am
by Roman - Tracker Supp
Hi edatmitchell,
Your problem is not specific to Raster-XChange or any other printer. It is a classic rounding error.
See the following artificial example.
Given you have to divide a page of 10" height into 1.25" strips.
There should be exactly 10 / 1.25=8 strips. However operating in pixels we get:

At resolution of 1 dpi:
page height is 10*1=10 px.
strip height is 1.25*1=1.25 = 1 px.
And we get 10/1=10 strips!

At resolution of 3 dpi:
page height is 10*3=30 px.
strip height is 1.25*3=3.75 = 4 px.
And we get 30/4=7.5=7 strips.

Finally at 4 dpi:
page height is 10*4=40 px.
strip height is 1.25*4=5 px.
And we get 40/5=8 strips (exactly as expected).

Re: Tiff Rendering Issue

Posted: Tue Apr 13, 2010 7:02 pm
by edatmitchell
Hi Roman,

I guess I’ve not explained completely what we were trying to accomplish here. We are trying to replace our current tiff/pdf (32-bit only) drivers with your drivers. Our current drivers only allow us to install on 32-bit OS’s and we were hoping to use your drivers to allow us install and work under 64-bit OS’s. However, our current 32-bit drivers allow us to “virtually” copy the setting’s (DPI, etc.) of a user’s printer but still render the tiff/pdf independent of these settings. It enables us to duplicate the output of the physical page that the user printed. I understand that DC created by your drivers are dimensionally bound to the physical context under which they were created. We are hoping that you may have a possible solution or a workaround that may still allow us to use your drivers as well as duplicate our user’s printed document.

Re: Tiff Rendering Issue

Posted: Tue Apr 13, 2010 10:24 pm
by Roman - Tracker Supp
Hi edatmitchell,

Generally mere duplicating public devmode settings does not make the output identical for 2 printers - there are parameters (like margins) that are not under control of devmode (and even cannot be controlled at all).Thus if you are trying to unify your code to work equally with Raster-XChange and the user's printer, mere parametrization with the printer DC will not be sufficient.

We are considering adding a possibility to setup arbitrary margins for Raster-XChange (through the SDK) in the next release.