How to view the code behind a PDF document in IOS - pdf

I have a PDF page that I've converted into a stream:
CGPDFContentStreamRef contentStream = CGPDFContentStreamCreateWithPage(pdfPage);
How can I view that stream as an NSString? I'd like to see the code that represents the PDF.
Thanks!

It's not as easy as that. A stream can be any binary data, there might be multiple chained compression formats used. See http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf (Page 23ff) for potential formats.
Your best option is CGPDFScanner other than re-implementing a PDF parser/lexer from scratch (We did that in the commercially available PSPDFKit SDK for iOS and Android - it's complicated.)

Related

Convert - GLTF/STL/OBJ file formats to U3D file for PDF page

I am trying to add three.js based 3D objects to a PDF page. It seems there are no direct exporters available to do that. So I am trying to do the below thing,
Convert the gltf/stl/obj files to U3D files
Add the .u3d file to PDF page.
I am trying to do the below process and I am not sure whether this approach is possible. It will be a great help if there is any support available to do any one of the below conversions. Also if you know any other possible approaches, kindly update me!!
Input formats output format
GLTF
OBJ U3D
STL
(any
three.js supported
3D formats)
Thanks.
There are few options available to export the three.js graphics to a PDF ( static content not a dynamic U3D assets)
Static contents
Get the rendered data from the three.js webGL renderer / canvas renderer using toDataURL("image/jpeg"), change the MIME type to JPG/PNG and add the resulting stream as an image to PDF ( this worked for me)
example - https://plnkr.co/edit/Ty8BZaDcflCJH5tH?preview
Like the above approach we can use three.js svgrenderer to export the renderer contents into a SVG data stream, which can be added into the PDF ( textures, mesh may not be 100% reproduced)
The legacy API - "threejs-pdf-renderer" can be used to directly export the three.js animations to a PDF. We don't need any other dependencies to create the PDF. But this is a legacy API which uses legacy three.js version, lot of effort needs to be done to make the API to be compatible with the latest three.js version.
example - https://satheeshks10.github.io/ThreejsPDFGenerator/
Dynamic 3D contents
We can export the three.js animations into a U3D file (no direct support is available as for now), this U3D file can be directly embedded into PDF.
example - https://tetra4d.com/pdf-samples/

How to generate PDF offline with UWP

I'm developing a UWP app for tablet and i need to generate a PDF with data from SQLite. I need to do this completely offline because where I will use the app there is no connection. What could I do?
I'd prefer not to use paid libraries like Syncfusion and XFinium so I'm trying to find an alternative solution.
I tried with iTextSharp but unfortunately I can't find a good documentation to render a complex PDF or to export a Bitmap generated from a Grid Component to a PDF File.
Why not render your data into a webpage displayed with a WebView control? Then you can use any permissive licensed javascript library to generate the PDF.
If it hasn't changed much, then you can only send text back and forth between your WebView and UWP app, but that's workable. Your final PDF result can be read back as a base64 encoded string.
A very quick search found this one that seems easy to use and you can just download the source to put into your app:
https://github.com/MrRio/jsPDF

Is it possible to convert fabricjs svg output to pdf without rasterizing?

We are building a web app where the user can make a design by using fabric.js and at the end he should receive a pdf file with his work.
At first, we tried to use JSPDF because it was prefered to have a cliente-side solution. However by doing pdf.addImage(canvas.toDataURL(),...) we are rasterizing the design.
In second place, we tried server side solution using WKHTMLTOPDF, sending canvas.toSVG(), but there are some issues with fonts and shapes rendering.
The designs are complex as they can have text, shapes, images and svg.
We also tried INKSCAPE (inkscape --without-gui --export-pdf ...), MPDF and MUPDF without good results. IMAGEMAGICK is not a solution has it also rasterize the design.
The main goal is to get a vector pdf, where it's possible to increase size and where the elements of the design are selectable, and if possible that pdf should be ready to print (300 dpi and cmyk)
Yes its possible using TCPDF library.
Please check this ImageSVG api for more information for converting SVG to PDF.
https://tcpdf.org/examples/example_058/
Export the canvas to svg and use pdflib to make the pdf.
You can find an exemple here:https://www.pdflib.com/pdflib-cookbook/graphics/starter-svg/

CGPDFDocument can't draw jpeg2000?

HI,guys.
I'm using this code to draw pdf,but i've compress the pdf's image to jpeg2000.so the cgpdfdocument can't decode the jpeg2000,just show noting but blank.how can i make it to decode the jpeg2000?
thanks.any advice will be gratefull.
CGPDFDocumentRef document;
CGPDFPageRef page;
CGRect box;
document = MyGetPDFDocumentRef (filename); // 1
page = CGPDFDocumentGetPage (document, pageNumber); // 2
CGContextDrawPDFPage (myContext, page); // 3
CGPDFDocumentRelease (document);
This is likely a bug in Apple's CoreGraphics library. Apple's engine definitely does support JPEG 2000, even though the decompression code is very slow, it certainly works.
There's even an open source example that shows how to decompress JPEG 2000 using ImageIO - however that will not help you much other than answering the question on JPEG 2000 compatibility.
I recommend submitting a radar with the faulty PDF to radar.apple.com.
However, don't get your hopes up that this will be fixed anytime soon. Over the years we reported countless rendering issues with the CoreGraphics PDF render engine as we used it in the commercial PSPDFKit SDK v1-v4. With last year's v5 release we finally finished and switched to our own rendering engine that improved on many of the problems that Apple's engine has, especially with more exotic files or compression formats. You're welcome to try our SDK and render engine and please report a bug to us as well if you find a file that renders in Adobe Acrobat but not our SDK - we're really good in terms of compatibility now and trusted by major brands such as Dropbox or IBM.

How to read a pdf file by using HTML5?

I want to create html file by which i could read any PDF file by providing the source of that PDF file. How can i do this by using only html5?
For example i want read a pdf file which is available in C drive so scr="http://virdir/mypdf.pdf".
I want something like this.
You want to use the developing HTML 5 File API. Mozilla has a good explanation, and you can also refer directly to the spec.
Since PDF is a binary format, you will probably want to use FileReader.readAsBinaryString().
Parsing and rendering (e.g. to a canvas) a PDF in JavaScript is possible, but it would be very challenging.
Here is an open source pdf reader written in javascript.
https://github.com/mozilla/pdf.js
There are APIs available to play with. It comes built into Firefox browser and has good support from Mozilla community.