Quantcast
Channel: GoJS - Northwoods Software
Viewing all articles
Browse latest Browse all 6969

Its possible make a diagram image as in pdf , i tryed this manner but not showing the image and pdf was format error

$
0
0

@Richard wrote:

generateImages (width:any, height:any) {
console.log(width)
console.log(height)

  // sanitize input
  width = parseInt(width);
  height = parseInt(height);
  if (isNaN(width)) width = 100;
  if (isNaN(height)) height = 100;
  // Give a minimum size of 50x50
  width = Math.max(width, 50);
  height = Math.max(height, 50);
  var imgDiv = document.getElementById('myImages');
  console.log(imgDiv)
  imgDiv.innerHTML = ''; // clear out the old images, if any
  var db = this.myDiagram.documentBounds.copy();
  var boundswidth = db.width;
  var boundsheight = db.height;
  var imgWidth = width;
  var imgHeight = height;
  var p = db.position.copy();
  //making images
  for (var i = 0; i< boundsheight; i += imgHeight) {
    var img:any
    for (var j = 0; j < boundswidth; j += imgWidth) {
       img= this.myDiagram.makeImage({
        scale: 1,
          type: "image/jpeg",
          background: "AntiqueWhite",
        position: new go.Point(p.x + j, p.y + i),
        size: new go.Size(imgWidth, imgHeight)
      });
      // Append the new HTMLImageElement to the #myImages div
     img.className = 'images';
      imgDiv.appendChild(img);
     imgDiv.appendChild(document.createElement('br'));
    }
              this.saveAsFile(img);
  }
}

destroyClickedElement(event:any){
document.body.removeChild(event.target);
}
saveAsFile(val:any)
{
var pdf_image = val
var textToSaveAsBlob = new Blob([pdf_image], {type:"image/jpeg"});
var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
// var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value;

var downloadLink = document.createElement("a");
downloadLink.download = "richard";
downloadLink.innerHTML = "Download File";
downloadLink.href = textToSaveAsURL;
downloadLink.onclick = this.destroyClickedElement;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();

}

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6969