tags:

views:

29

answers:

0

Hi all,

I'm developing the ImageViewer by using WPF as follow:

  • I have a TIFF (multiple pages) binary in database and decoded by TiffBitmapDecoder with Cache option = Default. After decoding I get a list of Frames (pages)

  • Each frame (represent one page of the Tiff file) is used to construct an ImageBrush to set to background of a canvas called ItemCanvas. The ItemCanvas represent for a page and support to add annotation, rotation,... (like XPS Viewer with added features)

  • I have a container canvas to contains all ItemCanvas.

Result: everything works fine on screen

The problem I'm facing is the print function:

  • Print to XPS printer (default shipped by Windows): all pages are printed very fast with other contents (annotaions) but the background of each page always get the first frame of TIFF image.

  • Print to CutePDF: all pages are printed ok with the correct background and annotations. But (I always hate "BUT") I only print less than 40 pages, otherwise I will got the memory leak "Insufficient memory to..."

Here's the code:

PrintDialog printDialog = new PrintDialog();
printDialog.UserPageRangeEnabled = true;
printDialog.PageRangeSelection = PageRangeSelection.UserPages;
printDialog.MinPage = 1;
printDialog.MaxPage = Convert.ToUInt32(_items.Count);
printDialog.PageRange = new PageRange(1, _items.Count);

if (printDialog.ShowDialog() == true)
{
 FixedDocument document = new FixedDocument();

 int from = 0; int to = _items.Count - 1;

 if (printDialog.PageRangeSelection == PageRangeSelection.UserPages)
 {
  from = printDialog.PageRange.PageFrom - 1;
  to = printDialog.PageRange.PageTo - 1;
 }

 for (int i = from; i <= to; i++)
 {
  ItemCanvas item = _items[i];
  FixedPage page = new FixedPage();

  PrintTicket printTicket = new PrintTicket();

  if (item.Width > item.Height)
  {
   printTicket.PageOrientation = PageOrientation.Landscape;
  }
  else
  {
   printTicket.PageOrientation = PageOrientation.Portrait;
  }

  page.PrintTicket = printDialog.PrintQueue.MergeAndValidatePrintTicket(printDialog.PrintTicket, printTicket).ValidatedPrintTicket;

  ItemCanvas clonedItem = CreateItemCanvas(item.Image, item.PageInfo);
  clonedItem.InitializeContent();
  page.Children.Add(clonedItem);
  page.Width = clonedItem.Width;
  page.Height = clonedItem.Height;

  PageContent pageContent = new PageContent();
  ((System.Windows.Markup.IAddChild)pageContent).AddChild(page);
  document.Pages.Add(pageContent);
 }

 printDialog.PrintDocument(document.DocumentPaginator, PrintJobName);
}

the _items is a ItemCanvas collection that refer to canvases are displayed on screen.

One more, my image viewer also have email feature which I convert ItemCanvas to bitmap and save into tiff file for attachment in email. I also got the same issue when print to CutePDF (memory leak)

Thanks so much!

Thanh