{"id":203,"date":"2023-06-01T14:06:20","date_gmt":"2023-06-01T06:06:20","guid":{"rendered":""},"modified":"2025-01-02T17:06:35","modified_gmt":"2025-01-02T09:06:35","slug":"article-slug-281","status":"publish","type":"post","link":"https:\/\/support.fuxinsoft.cn\/?p=203","title":{"rendered":"\u5982\u4f55\u4eceTIFF\u8f6c\u6362\u6210PDF\uff1f"},"content":{"rendered":"<p>Foxit PDF SDK for Web <span style=\"font-family: \u7b49\u7ebf;\">\u4e0d\u652f\u6301\u76f4\u63a5\u901a\u8fc7<\/span> UI <span style=\"font-family: \u7b49\u7ebf;\">\u5c06<\/span> tiff <span style=\"font-family: \u7b49\u7ebf;\">\u56fe\u50cf\u8f6c\u6362\u4e3a<\/span> PDF<span style=\"font-family: \u7b49\u7ebf;\">\uff0c\u4f46\u6709\u4e00\u79cd\u65b9\u6cd5\u53ef\u4ee5\u8c03\u7528<\/span>API<span style=\"font-family: \u7b49\u7ebf;\">\u3002\u4f8b\u5982\uff1a\u60a8\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528<\/span> PDFPage::addImage <span style=\"font-family: \u7b49\u7ebf;\">\u5c06<\/span> tiff <span style=\"font-family: \u7b49\u7ebf;\">\u56fe\u50cf\u63d2\u5165\u5230\u65b0\u7684<\/span> PDF <span style=\"font-family: \u7b49\u7ebf;\">\u4e2d\uff0c\u4f46\u8fd9\u53ea\u4f1a\u63d2\u5165\u56fe\u50cf\u7684\u7b2c\u4e00\u4e2a<\/span> iframe<span style=\"font-family: \u7b49\u7ebf;\">\u3002<\/span> <span style=\"font-family: \u7b49\u7ebf;\">\u5982\u679c\u8981\u63d2\u5165\u6240\u6709\u7684<\/span>iframe<span style=\"font-family: \u7b49\u7ebf;\">\uff0c\u5219\u9700\u8981\u83b7\u53d6\u6bcf\u4e2a<\/span>iframe<span style=\"font-family: \u7b49\u7ebf;\">\uff0c\u7136\u540e\u5c06\u5176\u4e00\u4e00\u63d2\u5165\u5230<\/span>PDF<span style=\"font-family: \u7b49\u7ebf;\">\u4e2d\u3002<\/span> <span style=\"font-family: \u7b49\u7ebf;\">\u9996\u5148\uff0c\u60a8\u9700\u8981\u5c06<\/span> tiff.js <span style=\"font-family: \u7b49\u7ebf;\">\u5305\u5b89\u88c5\u5230\u60a8\u7684\u9879\u76ee\u4e2d\uff0c\u7136\u540e\u5c06\u5176\u5bfc\u5165\u5230\u60a8\u7684\u9879\u76ee\u4e2d\u3002<\/span> <span style=\"font-family: \u7b49\u7ebf;\">\u4ee5\u4e0b\u662f\u793a\u4f8b\u4ee3\u7801\uff1a<\/span><\/p>\n<p>async function covertTiff2pdf(url){<\/p>\n<p>&nbsp;&nbsp;&nbsp; \/\/get the buffer of tiff file<\/p>\n<p>&nbsp;&nbsp;&nbsp; var imageResp = await fetch(url);<\/p>\n<p>&nbsp;&nbsp;&nbsp; var arrayBuffer = await imageResp.arrayBuffer();<\/p>\n<p>&nbsp;&nbsp;&nbsp; var image = new Tiff({ buffer: arrayBuffer });<\/p>\n<p>&nbsp;&nbsp;&nbsp; \/\/get the iframe counts<\/p>\n<p>&nbsp;&nbsp;&nbsp; var imageCount = image.countDirectory();<\/p>\n<p>&nbsp;&nbsp;&nbsp; var pdfViewer = await pdfui.getPDFViewer();<\/p>\n<p>&nbsp;&nbsp;&nbsp; \/\/create a new PDF document<\/p>\n<p>&nbsp;&nbsp;&nbsp; var pdfdoc = await pdfViewer.createNewDoc(&quot;newpdf.pdf&quot;,&quot;websdk&quot;,{height:image.height(), width:image.width()})<\/p>\n<p>&nbsp;&nbsp;&nbsp; var page1 = await pdfdoc.getPageByIndex(0);<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/insert the first iframe to first page<\/p>\n<p>&nbsp;&nbsp;&nbsp; page1.addImage(arrayBuffer,{left:0,right:image.width(), top: image.height(), bottom: 0});<\/p>\n<p>&nbsp;&nbsp;&nbsp; \/\/insert the rest of iframe to PDF<\/p>\n<p>&nbsp;&nbsp;&nbsp; if(imageCount&gt;1){<\/p>\n<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;for(i=1;i&lt;imageCount;i++){<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/insert a new PDF page to document<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var newPage = await pdfdoc.insertPage(i,image.width(),image.height());<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/get the next iframe<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image.setDirectory(i);<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var tifImage = await image.toDataURL(&quot;image\/png&quot;);<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var tifImageResp = await fetch(tifImage );<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var tifImageArrayBuffer = await tifImageResp.arrayBuffer();<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/insert current iframe to current page<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; await newPage.addImage(tifImageArrayBuffer,{left:0,right:image.width(), top: image.height(), bottom: 0});&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/p>\n<p>&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Foxit PDF SDK for Web \u4e0d\u652f\u6301\u76f4\u63a5\u901a\u8fc7 UI \u5c06 tiff \u56fe\u50cf\u8f6c\u6362\u4e3a PDF\uff0c\u4f46\u6709\u4e00\u79cd\u65b9 [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[67],"tags":[],"class_list":["post-203","post","type-post","status-publish","format-standard","hentry","category-websdk"],"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","_links":{"self":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=203"}],"version-history":[{"count":1,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/203\/revisions"}],"predecessor-version":[{"id":3970,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=\/wp\/v2\/posts\/203\/revisions\/3970"}],"wp:attachment":[{"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/support.fuxinsoft.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}