From e2ce1501ee964876528daa5d53e95dd50a36cf03 Mon Sep 17 00:00:00 2001 From: Steven Spungin Date: Mon, 24 Nov 2014 10:01:54 -0500 Subject: [PATCH] Added support for zoom factor in links Moved stray method into plugin scope Use page object reference instead of pageNumber for destination. (wider compatibility) --- jspdf.plugin.annotations.js | 78 +++++++++++++++++++++++++++++++------ test/test_annotation.html | 24 ++++++++++++ 2 files changed, 90 insertions(+), 12 deletions(-) diff --git a/jspdf.plugin.annotations.js b/jspdf.plugin.annotations.js index 603c84f04..7a681c7b4 100644 --- a/jspdf.plugin.annotations.js +++ b/jspdf.plugin.annotations.js @@ -13,7 +13,10 @@ * This plugin current supports
*
  • Goto Page (set pageNumber in options) *
  • Goto URL (set url in options) - * + *

    + * The destination magnification factor can also be specified when goto is a page number or a named destination. (see documentation below) + * (set magFactor in options). XYZ is the default. + *

    *

    * Options In PDF spec Not Implemented Yet *

  • link border @@ -25,13 +28,22 @@ *

    */ -function notEmpty(obj) { - if (typeof obj != 'undefined') { - if (obj != '') { - return true; - } - } -} +/* + Destination Magnification Factors + See PDF 1.3 Page 386 for meanings and options + + [supported] + XYZ (options; left top zoom) + Fit (no options) + FitH (options: top) + FitV (options: left) + + [not supported] + FitR + FitB + FitBH + FitBV + */ (function(jsPDFAPI) { 'use strict'; @@ -45,6 +57,14 @@ function notEmpty(obj) { f2 : function(number) { return number.toFixed(2); + }, + + notEmpty : function(obj) { + if (typeof obj != 'undefined') { + if (obj != '') { + return true; + } + } } }; @@ -64,7 +84,7 @@ function notEmpty(obj) { for (var a = 0; a < pageAnnos.length; a++) { var anno = pageAnnos[a]; if (anno.type === 'link') { - if (notEmpty(anno.options.url) || notEmpty(anno.options.pageNumber)) { + if (annotationPlugin.notEmpty(anno.options.url) || annotationPlugin.notEmpty(anno.options.pageNumber)) { found = true; break; } @@ -78,17 +98,50 @@ function notEmpty(obj) { var f2 = this.annotationPlugin.f2; for (var a = 0; a < pageAnnos.length; a++) { var anno = pageAnnos[a]; + var k = this.internal.scaleFactor; var pageHeight = this.internal.pageSize.height; + //var pageHeight = this.internal.pageSize.height * this.internal.scaleFactor; var rect = "/Rect [" + f2(anno.x * k) + " " + f2((pageHeight - anno.y) * k) + " " + f2(anno.x + anno.w * k) + " " + f2(pageHeight - (anno.y + anno.h) * k) + "] "; + + var line = ''; if (anno.options.url) { - this.internal.write('<> >>') + line = '<>'; } else if (anno.options.pageNumber) { // first page is 0 - this.internal.write('<>') + var pageObjId = anno.options.pageNumber * 2 + 1; + line = '< +

    + Chrome default PDF reader currently does not support magFactor links, although links still work after manualy changing magFactor. +
    + Firefox has a bug displaying annotations after the magFactor changes, but links do work. +
    + To test magFactor links [...] without bugs, use Adobe Reader or compatible application. +