如何在HTML / Blade中显示PDF代码(不是文件)

发布于 2025-01-18 14:36:18 字数 1500 浏览 0 评论 0原文

我正在使用 SendCloud 的 API 进行客户运输,该过程的一部分是标签生成。但是,当我尝试生成标签时,它会输出如下所示的 pdf 代码:

%PDF-1.3 1 0 obj << /Type /Pages /Count 1 /Kids [ 3 0 R ] >> endobj 2 0 obj << /Producer (PyPDF2) >> endobj 3 0 obj << /Type /Page /Parent 1 0 R /Resources 5 0 R /Contents 8 0 R /MediaBox [ 0 0 419.53 297.64 ] /Rotate 90 >> endobj 4 0 obj << /Type /Catalog /Pages 1 0 R >> endobj 5 0 obj << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] /Font << /F1 6 0 R /F2 7 0 R >> /XObject << >> >> endobj 6 0 obj << /Type /Font /BaseFont /Helvetica /Subtype /Type1 /Encoding /WinAnsiEncoding >> endobj 7 0 obj << /Type /Font /BaseFont /Helvetica-Bold /Subtype /Type1 /Encoding /WinAnsiEncoding >> endobj 8 0 obj << /Length 332 >> stream 2 J 0.57 w BT /F1 8.00 Tf ET BT 12.76 274.83 Td (Customer, 20 Address, 3500 Hasselt) Tj ET BT /F1 10.00 Tf ET BT 175.75 175.58 Td (BE Customer Test) Tj ET BT 175.75 162.83 Td (Gaarveldstraat 106) Tj ET BT /F2 10.00 Tf ET BT 175.75 150.07 Td (3500 HASSELT) Tj ET BT /F1 10.00 Tf ET BT 175.75 137.31 Td (Belgium / Belgique) Tj ET endstream endobj xref 0 9 0000000000 65535 f 0000000009 00000 n 0000000068 00000 n 0000000108 00000 n 0000000231 00000 n 0000000280 00000 n 0000000396 00000 n 0000000493 00000 n 0000000595 00000 n trailer << /Size 9 /Root 4 0 R /Info 2 0 R >> startxref 978 %%EOF

有人知道如何使用 html/blade 将其作为可打印图像在网页上显示吗?

I'm using SendCloud's API for my customer's shipping, and part of the process is label generation. However, when I try to generate a label, it spits out pdf code that looks like this:

%PDF-1.3 1 0 obj << /Type /Pages /Count 1 /Kids [ 3 0 R ] >> endobj 2 0 obj << /Producer (PyPDF2) >> endobj 3 0 obj << /Type /Page /Parent 1 0 R /Resources 5 0 R /Contents 8 0 R /MediaBox [ 0 0 419.53 297.64 ] /Rotate 90 >> endobj 4 0 obj << /Type /Catalog /Pages 1 0 R >> endobj 5 0 obj << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] /Font << /F1 6 0 R /F2 7 0 R >> /XObject << >> >> endobj 6 0 obj << /Type /Font /BaseFont /Helvetica /Subtype /Type1 /Encoding /WinAnsiEncoding >> endobj 7 0 obj << /Type /Font /BaseFont /Helvetica-Bold /Subtype /Type1 /Encoding /WinAnsiEncoding >> endobj 8 0 obj << /Length 332 >> stream 2 J 0.57 w BT /F1 8.00 Tf ET BT 12.76 274.83 Td (Customer, 20 Address, 3500 Hasselt) Tj ET BT /F1 10.00 Tf ET BT 175.75 175.58 Td (BE Customer Test) Tj ET BT 175.75 162.83 Td (Gaarveldstraat 106) Tj ET BT /F2 10.00 Tf ET BT 175.75 150.07 Td (3500 HASSELT) Tj ET BT /F1 10.00 Tf ET BT 175.75 137.31 Td (Belgium / Belgique) Tj ET endstream endobj xref 0 9 0000000000 65535 f 0000000009 00000 n 0000000068 00000 n 0000000108 00000 n 0000000231 00000 n 0000000280 00000 n 0000000396 00000 n 0000000493 00000 n 0000000595 00000 n trailer << /Size 9 /Root 4 0 R /Info 2 0 R >> startxref 978 %%EOF

Does anybody know how to display this on a webpage as a printable image with html/ blade?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁许谁一生繁华 2025-01-25 14:36:18

传入是带有旋转的PDF,因此不会像标签打印那样显示其正确的显示方式。

因此,您的第一步是使用pdftopng -Rot 270 shipplesh.pdf Label,您可以从XPDF或Poppler(其他库),ON上使用pdftopng -Rot 270 shigper.pdf标签,图像更简单,图像更简单。 Windows要么只是一个EXE文件,但是在其他平台上,您可能需要使用支持文件来酿造。

如果将传入的pdf /旋转90 row to /rotate 00可以使用命令pdftotext -layout运输提取文本。 pdf label-001.txt从上面的库中插入&lt; pre&gt;代码部分&lt;/pre&gt;

<!DOCTYPE html>
<html>
<body>

<h1>Shipping</h1>

<pre>
Customer, 20 Address, 3500 Hasselt

                                                 BE Customer Test
                                                 Gaarveldstraat 106
                                                 3500 HASSELT
                                                 Belgium / Belgique
</pre>

</body>
</html>

库还具有可执行选项的pdftohtml这是PDF上方的原始默认值

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
.txt { white-space:nowrap; }
#f0 { font-family:sans-serif; font-weight:normal; font-style:normal; }
#f1 { font-family:sans-serif; font-weight:normal; font-style:normal; }
#f2 { font-family:sans-serif; font-weight:bold; font-style:normal; }
</style>
</head>
<body>
<div class="txt" style="position:absolute; left:12px; top:17px;"><span id="f1" style="font-size:8px;vertical-align:baseline;color:rgba(0,0,0,1);">Customer, 20 Address, 3500 Hasselt</span></div>
<div class="txt" style="position:absolute; left:175px; top:114px;"><span id="f1" style="font-size:10px;vertical-align:baseline;color:rgba(0,0,0,1);">BE Customer Test</span></div>
<div class="txt" style="position:absolute; left:175px; top:127px;"><span id="f1" style="font-size:10px;vertical-align:baseline;color:rgba(0,0,0,1);">Gaarveldstraat 106</span></div>
<div class="txt" style="position:absolute; left:175px; top:140px;"><span id="f2" style="font-size:10px;vertical-align:baseline;color:rgba(0,0,0,1);">3500 HASSELT</span></div>
<div class="txt" style="position:absolute; left:175px; top:153px;"><span id="f1" style="font-size:10px;vertical-align:baseline;color:rgba(0,0,0,1);">Belgium / Belgique</span></div>
</body>
</html>

而且,如果将传入的PDF转换为Base64,则可以使用可能不会在此处显示的iframe。

<body>Label<br>
<iframe width=480 height=320 src="data:application/pdf;base64,JVBERi0xLjMKJcK1wrYKCjEgMCBvYmoKPDwvVHlwZS9QYWdlcy9Db3VudCAxL0tpZHNbMy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oycr+wWsHPyk/t0vv7trUI3SR7+PdN0YKO9XoNY1VnxzETEWOxSJ92X4/TjjQKZW5kc3RyZWFtCmVuZG9iagoKeHJlZgowIDkKMDAwMDAwMDAwMCA2NTUzNiBmIAowMDAwMDAwMDE2IDAwMDAwIG4gCjAwMDAwMDAwNjggMDAwMDAgbiAKMDAwMDAwMDEwNiAwMDAwMCBuIAowMDAwMDAwMjE4IDAwMDAwIG4gCjAwMDAwMDAyNjQgMDAwMDAgbiAKMDAwMDAwMDM2NCAwMDAwMCBuIAowMDAwMDAwNDUzIDAwMDAwIG4gCjAwMDAwMDA1NDcgMDAwMDAgbiAKCnRyYWlsZXIKPDwvU2l6ZSA5L0luZm8gMiAwIFIvUm9vdCA0IDAgUj4+CnN0YXJ0eHJlZgo5MDAKJSVFT0YK"></iframe></body>

The incoming is a PDF with rotation so will not be the correct way up for display as its intended for label printing.

Thus your first step is to convert into a rotated image or text, image is simpler by using pdftopng -rot 270 shipping.pdf label which you can use from xpdf or poppler (other libraries are available), on windows either can be just a single exe file, but on other platforms you may need to brew with supporting files.

enter image description here

If you change incoming pdf /rotate 90 to /Rotate 00 you can extract the text using the command pdftotext -layout shipping.pdf label-001.txt from the above libraries and insert that into a <pre> code section </pre>.

<!DOCTYPE html>
<html>
<body>

<h1>Shipping</h1>

<pre>
Customer, 20 Address, 3500 Hasselt

                                                 BE Customer Test
                                                 Gaarveldstraat 106
                                                 3500 HASSELT
                                                 Belgium / Belgique
</pre>

</body>
</html>

and the libraries also have pdftohtml with executable options this is raw default from above pdf

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
.txt { white-space:nowrap; }
#f0 { font-family:sans-serif; font-weight:normal; font-style:normal; }
#f1 { font-family:sans-serif; font-weight:normal; font-style:normal; }
#f2 { font-family:sans-serif; font-weight:bold; font-style:normal; }
</style>
</head>
<body>
<div class="txt" style="position:absolute; left:12px; top:17px;"><span id="f1" style="font-size:8px;vertical-align:baseline;color:rgba(0,0,0,1);">Customer, 20 Address, 3500 Hasselt</span></div>
<div class="txt" style="position:absolute; left:175px; top:114px;"><span id="f1" style="font-size:10px;vertical-align:baseline;color:rgba(0,0,0,1);">BE Customer Test</span></div>
<div class="txt" style="position:absolute; left:175px; top:127px;"><span id="f1" style="font-size:10px;vertical-align:baseline;color:rgba(0,0,0,1);">Gaarveldstraat 106</span></div>
<div class="txt" style="position:absolute; left:175px; top:140px;"><span id="f2" style="font-size:10px;vertical-align:baseline;color:rgba(0,0,0,1);">3500 HASSELT</span></div>
<div class="txt" style="position:absolute; left:175px; top:153px;"><span id="f1" style="font-size:10px;vertical-align:baseline;color:rgba(0,0,0,1);">Belgium / Belgique</span></div>
</body>
</html>

and if you convert the incoming pdf to base64 you could use an iFrame which probably wont show here.

<body>Label<br>
<iframe width=480 height=320 src="data:application/pdf;base64,JVBERi0xLjMKJcK1wrYKCjEgMCBvYmoKPDwvVHlwZS9QYWdlcy9Db3VudCAxL0tpZHNbMyAwIFJdPj4KZW5kb2JqCgoyIDAgb2JqCjw8L1Byb2R1Y2VyKFB5UERGMik+PgplbmRvYmoKCjMgMCBvYmoKPDwvVHlwZS9QYWdlL1BhcmVudCAxIDAgUi9SZXNvdXJjZXMgNSAwIFIvQ29udGVudHMgOCAwIFIvTWVkaWFCb3hbMCAwIDQxOS41MyAyOTcuNjRdL1JvdGF0ZSAwPj4KZW5kb2JqCgo0IDAgb2JqCjw8L1R5cGUvQ2F0YWxvZy9QYWdlcyAxIDAgUj4+CmVuZG9iagoKNSAwIG9iago8PC9Qcm9jU2V0Wy9QREYvVGV4dC9JbWFnZUIvSW1hZ2VDL0ltYWdlSV0vRm9udDw8L0YxIDYgMCBSL0YyIDcgMCBSPj4vWE9iamVjdDw8Pj4+PgplbmRvYmoKCjYgMCBvYmoKPDwvVHlwZS9Gb250L0Jhc2VGb250L0hlbHZldGljYS9TdWJ0eXBlL1R5cGUxL0VuY29kaW5nL1dpbkFuc2lFbmNvZGluZz4+CmVuZG9iagoKNyAwIG9iago8PC9UeXBlL0ZvbnQvQmFzZUZvbnQvSGVsdmV0aWNhLUJvbGQvU3VidHlwZS9UeXBlMS9FbmNvZGluZy9XaW5BbnNpRW5jb2Rpbmc+PgplbmRvYmoKCjggMCBvYmoKPDwvTGVuZ3RoIDI4NC9GaWx0ZXIvRmxhdGVEZWNvZGU+PgpzdHJlYW0KeJyNkW1LwzAUhf/K+TJQGG2aNE0LY7BJ5wuCsOYPRJpKR1+wSVX89abdOl1FMF9yeZJ7zrkJHkA8LvCOrYS/CxB7hEAWSOVAAuqJCFSEXswgc1zd9Ma2te6WoASbPO+0MUsw7prulDG6steQh1P3oBeQS0HBPcHHjcej4jbFJAqpzc/+6XJEJ/tbpbo3XeXGdkpZJx5d2NG/7LjDYlQ4Rt1kWfoo/xeVCY8Fx6i6ein7Gj7G6rXXk4Juhkha1UPVPh/w0ekCBAnIeSHinHEU3+h0iuaMoniOAvILURdnjmIyRyyJ5ihM2BzxhJ+Re9Oycr+wWsHPyk/t0vv7trUI3SR7+PdN0YKO9XoNY1VnxzETEWOxSJ92X4/TjjQKZW5kc3RyZWFtCmVuZG9iagoKeHJlZgowIDkKMDAwMDAwMDAwMCA2NTUzNiBmIAowMDAwMDAwMDE2IDAwMDAwIG4gCjAwMDAwMDAwNjggMDAwMDAgbiAKMDAwMDAwMDEwNiAwMDAwMCBuIAowMDAwMDAwMjE4IDAwMDAwIG4gCjAwMDAwMDAyNjQgMDAwMDAgbiAKMDAwMDAwMDM2NCAwMDAwMCBuIAowMDAwMDAwNDUzIDAwMDAwIG4gCjAwMDAwMDA1NDcgMDAwMDAgbiAKCnRyYWlsZXIKPDwvU2l6ZSA5L0luZm8gMiAwIFIvUm9vdCA0IDAgUj4+CnN0YXJ0eHJlZgo5MDAKJSVFT0YK"></iframe></body>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文