Giter Club home page Giter Club logo

Comments (12)

TakeshiOkamoto avatar TakeshiOkamoto commented on July 30, 2024

Hi, hoihoi000a

I can English understand, only 3-year-old level.

[Precondition]
PDF Designer's core was created in 2003.
So, Basically it corresponds to PDF 1.2 - 1.4.

[Method 1]
Set the data to be passed to TPDFAnalyst.LoadFromStream to Uint8Array.

[Method 2]
Save the data using HTML5 IndexedDB, then read with Uint8Array.

from pdfdesigner.

TakeshiOkamoto avatar TakeshiOkamoto commented on July 30, 2024

if can't do it, sorry

from pdfdesigner.

hoihoi000a avatar hoihoi000a commented on July 30, 2024

hello TakeshiOkamoto,
Thanks for your support ! your library is amazing!! 👍
i simply the demo code below, it worked

function onChangeFile(event,index) {
    var reader = new FileReader();
    var file = event.target.files;
    reader.onload = function (event) {
        var `Stream` = new Uint8Array(reader.result);
        Analysts[index] = new TPDFAnalyst();
        try {
            Analysts[index].LoadFromStream(Stream);
        } catch (e) {
            Analysts[index] = null;
        }
    }
    reader.readAsArrayBuffer(file[0]);
}

//-----------------------------------------------------------------
//and i try to send file to unit8Array(),but still not working
// have been looking for ans all day, do you have any idea?
// sorry for bother you with small question
//-----------------------------------------------------------------

function loadXMLDoc() {
    xmlhttp=new XMLHttpRequest();
    xmlhttp.open("GET","a.pdf",true);
    xmlhttp.onload = function (event) {
        var arraybuffer = xmlhttp.response;
        var Stream = new Uint8Array(arraybuffer);
        Analysts[index] = new TPDFAnalyst();
        try {
            Analysts[index].LoadFromStream(Stream);
        } catch (e) {
            Analysts[index] = null;
        }
    }
    reader.readAsArrayBuffer(file[0]);
}

from pdfdesigner.

TakeshiOkamoto avatar TakeshiOkamoto commented on July 30, 2024

I understood the cause.
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data

I will post the code again after formatting the code.

from pdfdesigner.

TakeshiOkamoto avatar TakeshiOkamoto commented on July 30, 2024

Early story,

xmlhttp.responseType = "arraybuffer";

It seems that it was missing.


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="pdf-designer.js"></script> 
<script> 
 
  function createXmlHttpRequest(){
 
    if(window.XMLHttpRequest){      
    
      return new XMLHttpRequest();     
      
    }else if(window.ActiveXObject){
      
      try {
          return new ActiveXObject("MSXML2.XMLHTTP.6.0"); 
      } catch (e) {
        try {
           return new ActiveXObject("MSXML2.XMLHTTP.3.0");
        } catch (e2) {
          try {
              return new ActiveXObject("MSXML2.XMLHTTP");
          } catch (e3) {
             return null
          }
        }
      }
      
    }else {
        return null
    }
  }
  
  function sendHttpRequest(){ 
        
      var xmlhttp = createXmlHttpRequest();
      
      xmlhttp.onreadystatechange = function() { 
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
            XmlHttpCallback(xmlhttp);
        }
      }       

      xmlhttp.open('GET', 'test.pdf', true);
            
      // here is important
      xmlhttp.responseType = "arraybuffer";
      

      xmlhttp.send(null);     
  }
  
  function XmlHttpCallback(xmlhttp){
      var result = document.getElementById("result");
      
      var Analysts = new TPDFAnalyst();
      var Stream = new Uint8Array(xmlhttp.response);
      try {
         Analysts.LoadFromStream(Stream);
      }catch (e){
        alert(e);
      }
      
      console.log(Analysts);
      result.innerHTML="PDF" + Analysts.Version + " PageCount : " + Analysts.PageCount;
  } 
</script>
</head>
<body>
 
  <div id="result"></div>
  <br />
  <input type="button" value="  run  " onclick="sendHttpRequest();" />
  
</body>
</html>

It should be okay with this.

... Translated by google translation.

from pdfdesigner.

hoihoi000a avatar hoihoi000a commented on July 30, 2024

どうもありがとう (translated by goolge)
thank you so much,TakeshiOkamoto
you help me a lot, i appreciate that 👍
ill do the research about your code and that links
thank you again :)
if that work i will copy my code to the comment

from pdfdesigner.

hoihoi000a avatar hoihoi000a commented on July 30, 2024

i cant even leaving a comment, so weird
seems website problem
the code can't be read by the website

i might do it few days later
var fileArray = <?php echo json_encode($fileArray); ?>; var arrlength = <?php echo $arrlength ;?>; var Analysts = new Array(); for(var i = 0 ; i<arrlength;i++){ sendHttpRequest(fileArray[i],i) }

from pdfdesigner.

TakeshiOkamoto avatar TakeshiOkamoto commented on July 30, 2024

Probably because there is an HTML tag.

[All code]
4 single-byte spaces or tabs at the beginning of the line

And posting is good, after previewing.

I think that is good.


[Tag test]

<html>
</html>

[Example]
CRLF ... new line
SP ... space

CRLF
SPSPSPSP<html>
SPSPSPSP</html>

from pdfdesigner.

hoihoi000a avatar hoihoi000a commented on July 30, 2024

According to TakeshiOkamoto's code
I try to reuse that way get file with php then do the merge with js
I find the problem , the code mark doesn't work , unless 3 times of code mark.
Because i do a lot research for 2 weeks, and finally get the answer, and thanks to TakeshiOkamoto's help
Here is a simple sample for other learner.(I think it's working right away)


Precondition 1. u need "pdf-designer.js" from TakeshiOkamoto's code.
Precondition 2. change the filearray's file address from server.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
  <div id="errmsg"></div>
  <br />
  <input type="button" value=" combinePDF " onclick="combinePDF()" />
  <?php
    $fileArray = array("http://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf","http://mozilla.github.io/pdf.js/web/compressed.tracemonkey-pldi-09.pdf");
    $arrlength = count($fileArray);
    echo $arrlength;
  ?>
</body>
</html>

<script src="pdf-designer.js"></script> 
<script> 
  var fileArray = <?php echo json_encode($fileArray); ?>;
  var arrlength = <?php echo $arrlength ;?>;
  var Analysts  = new Array();
  for(var i = 0 ; i<arrlength;i++){
      sendHttpRequest(fileArray[i],i)
    }
 
  function createXmlHttpRequest(){

    if(window.XMLHttpRequest){      
    
      return new XMLHttpRequest();     
      
    }else if(window.ActiveXObject){
      
      try {
          return new ActiveXObject("MSXML2.XMLHTTP.6.0"); 
      } catch (e) {
        try {
           return new ActiveXObject("MSXML2.XMLHTTP.3.0");
        } catch (e2) {
          try {
              return new ActiveXObject("MSXML2.XMLHTTP");
          } catch (e3) {
             return null
          }
        }
      }
      
    }else {
        return null
    }
  }

  function sendHttpRequest(filepath,index){ 
      var xmlhttp = createXmlHttpRequest();
      xmlhttp.open('GET', filepath, true);      
      xmlhttp.responseType = "arraybuffer";// here is important
      xmlhttp.send(null); 

      xmlhttp.onreadystatechange = function() { 
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
            Analysts[index] = new TPDFAnalyst();
            var Stream = new Uint8Array(xmlhttp.response);
            try {
              Analysts[index].LoadFromStream(Stream);
            }catch (e){
              alert(e);
            }   
        }
      }      
  }
  
  function combinePDF() {        
      var PDFCombine = new TPDFCombine();
    if (Analysts[0] != null && Analysts[1] != null) {
        try {
          
            // PDF_GetDateTime_Now() return the current date and time.
            PDFCombine.SaveToFile(PDF_GetDateTime_Now() + '.pdf', Analysts);
            
        } catch (e) {
            Analysts[0] = null;
            Analysts[1] = null;
            
            document.getElementById("errmsg").innerHTML = 
              'failed in the convert of the PDF file.';
        }
    } else {
        document.getElementById("errmsg").innerHTML =
          'Two PDF files, please select.';
    }
  }
</script>

from pdfdesigner.

TakeshiOkamoto avatar TakeshiOkamoto commented on July 30, 2024

Thanks!

from pdfdesigner.

hoihoi000a avatar hoihoi000a commented on July 30, 2024

Do i need to closed this issue?
i am new citizen, not quite understand how this website going,sorry @@

from pdfdesigner.

TakeshiOkamoto avatar TakeshiOkamoto commented on July 30, 2024

It is OK to closed this "issue".

from pdfdesigner.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.