WebAPI/WebPrintAPI: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Initial draft)
 
No edit summary
Line 5: Line 5:
This is about implementing a new API for printing on the web. It's a "low level" API that allows web developers to have rich control about printing output.
This is about implementing a new API for printing on the web. It's a "low level" API that allows web developers to have rich control about printing output.


== Proposed API ==
Defining the PrintSetting API as used in PrintDocument.print(printSetting) is out of the scope of this document.
 
== Notes ==


* Use points as metric for printing (72 points per inch)
* Use points as metric for printing (72 points per inch)
* Open Questions
* Open Questions
** Should the developer set the page size or should the page size be set by choosing a printer and then using the printer's paper size setup?
** What is (0,0)? The top left corner of the physical page OR of the page taking into account the print margin?
** What is (0,0)? The top left corner of the physical page OR of the page taking into account the print margin?
** Should there be different color spaces then RGB? How to make them work, as there are no CSS colors defined for CMYK.
** Should there be different color spaces then RGB? How to make them work, as there are no CSS colors defined for CMYK.
** Should the browser display a progress view while the pages are drawn (this doesn't mean the actual printing output progress)?
** Lot more... TBD
** Lot more... TBD


=== Possible values for the 'scale' property (see below) ===
* 'scale': Scales the drawing while keeping the ration to to fit on the print paper size
* 'fit': Scales the drawing while not taking the ration of the printer paper size in account
* 'center': No scaling, just placing the center of the drawing onto the center of the printer paper.
== Example ==


   var pDoc = new PrintDocument(
   var pDoc = new PrintDocument(
                   'documentTitle',  // Title
                   'documentTitle',  // Title
                   'letter',        // Paper size
                   'letter',        // Paper size
                  'scale',          // optional: see notes about "scale"
                   false            // optional: isLandscape?
                   false            // optional: isLandscape?
                  );
                );
 
               
   // ---
   // ---
   // Following things MUST be defined/set by the developer.
   // Following functions MUST be defined by the developer.
   // ---
   // ---
    
    
Line 30: Line 39:
      
      
     // ..
     // ..
 
   
     // The fontCtx is only a very limited subset of the normal print ctx, that
     // The fontCtx is a very limited subset of the normal print ctx, that
     // basically allows to do font-size measurements.
     // is just about doing text measurements.
     fontCtx.font = '...';
     fontCtx.font = '...';
     fontCtx.measureText(...);
     fontCtx.measureText(...);
Line 41: Line 50:
   };
   };
    
    
   // Actually drawing function. Each page is painted individually. This is
   // Actually drawing function. Each page is drawn individually. This is
   // handy for page preview or if the user picks only a subset of the total
   // handy for page preview or if the user picks only a subset of the total
   // pages.
   // pages.
Line 51: Line 60:
       // ...
       // ...
     }
     }
   
      
      
     // Render the page <pageNumber> to the ctx.
     // Render the page <pageNumber> to the ctx.
Line 62: Line 70:
       setTimeout(function() {
       setTimeout(function() {
         // Continue drawing...
         // Continue drawing...
   
       
         // This page is done drawing.
         // This page is done drawing.
         ctx.endPage();
         ctx.endPage();
Line 72: Line 80:
    
    
   // ---
   // ---
   // Other APIs
   // Provided API functions
   // ---
   // ---
   pDoc.getPageSize = function() {
   pDoc.getPageSize = function() {
Line 81: Line 89:
   }
   }
    
    
  pDoc.getUnwriteableMargin = function() {
    return {
      top:    <inch>,
      bottom: <inch>,
      left:  <inch>,
      right:  <inch>
    }
  }
 
  // Was the printing started but is not finished yet?
   pDoc.isPrinting;
   pDoc.isPrinting;
 
  // Are all the pages drawn?
  pDoc.isFinished;
    
    
   // Start the printing progress. This opens the print dialog.
   // Start the printing progress. This opens the print dialog.
   pDoc.print();
  // The passed in `printSetting` is not defined yet and is outside of the scope
  // of this proposal/API.
   pDoc.print(printSetting);
    
    
  // Stops the print process. Once all data is created, there is no way to stop
  // the printing anymore; that means, as soon as `pDoc.isFinished` is true,
  // calling this function has no effect.
   pDoc.abort();
   pDoc.abort();


== Proposed API ==
See the example to get an idea. More details coming soon!


== Implementation ==
== Implementation ==


None.
Some basic investigation in the Gecko codebase. No code written so far.
49

edits

Navigation menu