gpt4 book ai didi

html - 在页面中嵌入 PDF 字节流的问题

转载 作者:太空宇宙 更新时间:2023-11-04 14:32:14 26 4
gpt4 key购买 nike

我正在服务器上生成内存中的 PDF,并希望将结果作为字节流发送,以便在网页上显示为 PDF。我似乎没有按顺序排列所有内容,因为没有一个主要浏览器可以正确显示 PDF。我试过嵌入、对象和 iframe 标签,但无法正常工作。

这是从 IE 页面复制的嵌入版本:

<embed width="100%" height="100%" src="data:application/pdf,%PDF-1.4%ÓôÌá1 0 obj<</CreationDate(D:20151030142159-07'00')/Title(Created with PDFsharp)/Creator(PDFsharp 1.32.3057-g (www.pdfsharp.net))/Producer(PDFsharp 1.32.3057-g (www.pdfsharp.net))>>endobj2 0 obj<</Type/Catalog/Pages 3 0 R>>endobj3 0 obj<</Type/Pages/Count 1/Kids[4 0 R]>>endobj4 0 obj<</Type/Page/MediaBox[0 0 612 792]/Parent 3 0 R/Contents 5 0 R/Resources<</ProcSet [/PDF/Text/ImageB/ImageC/ImageI]/ExtGState<</GS0 6 0 R>>/Font<</F0 8 0 R>>>>/Group<</CS/DeviceRGB/S/Transparency/I false/K false>>>>endobj5 0 obj<</Length 98/Filter/FlateDecode>>streamx+ä2T0�B]eni¤ d(Tqr9pé»(¤sé»ÅÓ¸L,ôÌÍML ôÌ,BR4>endobj7 0 obj<</Type/FontDescriptor/Ascent 891/CapHeight 662/Descent -216/Flags 32/FontBBox[-547 -307 1401 1032]/ItalicAngle -16.333/StemV 0/XHeight 439/FontName/TimesNewRoman,BoldItalic>>endobj8 0 obj<</Type/Font/Subtype/TrueType/BaseFont/TimesNewRoman,BoldItalic/Encoding/WinAnsiEncoding/FontDescriptor 7 0 R/FirstChar 0/LastChar 255/Widths[777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 777 250 389 555 500 500 833 777 277 333 333 500 569 250 333 250 277 500 500 500 500 500 500 500 500 500 500 333 333 569 569 569 500 832 666 666 666 722 666 666 722 777 389 500 666 610 889 722 722 610 722 666 556 610 722 666 889 666 610 610 333 277 333 569 500 333 500 500 443 500 443 333 500 556 277 277 500 277 777 556 500 500 500 389 389 277 556 443 666 500 443 389 348 220 348 569 777 500 777 333 500 500 1000 500 500 333 1000 556 333 943 777 610 777 777 333 333 500 500 350 500 1000 333 1000 389 333 722 777 389 610 250 389 500 500 500 500 220 500 333 747 266 500 605 333 747 500 399 548 299 299 333 576 500 250 333 299 299 500 750 750 750 500 666 666 666 666 666 666 943 666 666 666 666 666 389 389 389 389 722 722 722 722 722 722 722 569 722 722 722 722 722 610 610 500 500 500 500 500 500 500 722 443 443 443 443 443 277 277 277 277 500 556 500 500 500 500 500 548 500 556 556 556 556 443 500 443]>>endobjxref0 90000000000 65535 f 0000000015 00000 n 0000000210 00000 n 0000000258 00000 n 0000000313 00000 n 0000000568 00000 n 0000000736 00000 n 0000000779 00000 n 0000000981 00000 n trailer<</ID[<24C49FD36FB7C74593CB248B32E8A112><24C49FD36FB7C74593CB248B32E8A112>]/Info 1 0 R/Root 2 0 R/Size 9>>startxref2178%%EOF" type="application/pdf" />

本文档仅包含“Hello, World!”并在 C# 中使用 File.ReadAllBytes(...) 直接从实际的 PDF 文件中吸取。

最佳答案

您错过了一步。嵌入的 PDF 需要进行编码。

以下内容来自类似的小型 PDF。我通过将 PDF 上传到站点 http://www.motobit.com/util/base64-decoder-encoder.asp 将其编码为 base 64 .

然后我将 base64 结果粘贴到我的嵌入元素中,如下所示:

<embed width="100%" height="100%" src="data:application/pdf;base64,JVBERi0xLjMKJaWx6woxIDAgb2JqCjw8IC9UeXBlIC9DYXRhbG9nIC9QYWdlcyAyIDAgUiA+Pgpl
bmRvYmoKMiAwIG9iago8PCAvVHlwZSAvUGFnZXMgL0NvdW50IDEgL0tpZHMgWyAzIDAgUiBdIC9S
ZXNvdXJjZXMgPDwgL1BhdHRlcm4gPDwgL1B0MSA1IDAgUiA+PiAvUHJvY3NldCBbIC9QREYgL1Rl
eHQgXSA+PiA+P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UGF0
dGVybiAvQkJveCBbIDAgMCAxMDAgMTAwIF0gL01hdHJpeCBbIDAuNCAwIDAgMC40IDAgMCBdIC9Q
YWludFR5cGUgMSAvUGF0dGVyblR5cGUgMSAvUmVzb3VyY2VzIDw8IC9Gb250IDw8IC9GMSA2IDAg
UiA+PiA+PiAvVGlsaW5nVHlwZSAyIC9YU3RlcCAxMDAgL1lTdGVwIDEwMCAvTGVuZ3RoIDE4MyA+
PgpzdHJlYW0KCnEKQlQKL0YxIDEgVGYKNjQgMCAwIDY0IDcuMTc3MSAyLjQ0MTQgVG0KMCBUYwow
IFR3CjEgMCAwIHJnCihcMjUzKSBUagowLjc0NzggLTAuMDA3IFRECjAgMSAwIHJnCihcMjUyKSBU
agotMC43MzIzIDAuNzgxMyBURAowIDAgMSByZwooXDI1MSkgVGoKMC42OTEzIDAuMDA3IFRECjAg
MCAwIHJnCihcMjUwKSBUagpFVApRCmVuZHN0cmVhbQplbmRvYmoKNiAwIG9iago8PCAvVHlwZSAv
Rm9udCAvU3VidHlwZSAvVHlwZTEgL0Jhc2VGb250IC9aYXBmRGluZ2JhdHMgPj4KZW5kb2JqCnhy
ZWYKMCA3CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDAxNCAwMDAwMCBuIAowMDAwMDAwMDYz
IDAwMDAwIG4gCjAwMDAwMDAxODkgMDAwMDAgbiAKMDAwMDAwMDI3OCAwMDAwMCBuIAowMDAwMDAw
OTQ4IDAwMDAwIG4gCjAwMDAwMDEzNTAgMDAwMDAgbiAKdHJhaWxlcgo8PCAvUm9vdCAxIDAgUiAv
U2l6ZSA3ID4+CnN0YXJ0eHJlZgoxNDIzCiUlRU9G"/>

如果将以上内容保存为 html,然后使用浏览器打开它,您应该会看到以下单页 PDF。

embedded PDF

我建议尝试使用类似的过程将您的 PDF 编码为 base 64 并按上述方式嵌入。

关于html - 在页面中嵌入 PDF 字节流的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33455918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com