PDF file stored as BLOB, view in a webpage perl - perl

I have a code that handles displaying a blob from a local Oracle database. I store both JPG and PDF files as blob. I could view the JPG file, but not the PDF. I have checked these
$self->content_type('image/jpg')
to
$self->content_type('application/pdf').
And the Blob does have data. I checked the length and it has "184546".
All I get when I click the link for the pdf file is a blank page with the title GETIMAGPAGE(application/pdf).
Any help or pointers would be greatly appreciated.
Also, How can we have the content_type to enable two different mime_types? For example in my case both image as well as pdf, depending on what we get?

File::MMagic can recognize the type of data using magic numbers.
use File::MMagic;
$magic = File::MMagic->new;
$self->content($blob);
$self->content_type($magic->checktype_contents($blob));
If you don't want to require a native/plugin PDF reader, perhaps FlexPaper might fit your needs.

Related

keep/copy XMP with libexif

I try to add a thumbnail to a JPEG picture using libexif.
For now I'm borrowing the code from exif (the command line tool that is shipped by the libexif team).
However I noticed the XMP tags get deleted from the metadata. There is an old bugreport here.
I tried to see how to achieve this anyway with libexif but I don't really understand how to get the XMP from input file and put it in the output file. I just want to copy all XMP data, I don't need to extract anything of it.
I saw there is a TAG EXIF_TAG_XML_PACKET in exif_tag.h but couldn't figure out how to read/write this tag.
A related solution is in this SO answer but it looks complicated. I'm not familiar coding in C.
Is it actually possible to keep all XMP when using only libexif API? Have things changed in recent years on that? How would you write this in code?
Thanks
I believe it should be somewhat straightforward. XMP fields are described in the ISO/Adobe standard. Regular Kotlin/Java/Android file I/O and some string manipulation should be all that is required.
I would start out by becoming intimately familiar with ISO 16684-1:2019. Then, write a method for your jpeg file class that grabs all the XMP fields. Store those fields in a temp file (to prevent difficult to recover data loss in the event of your code or libexif crashing). Hand the file off to libexif. Generate the thumbnail. Finally, when that's done you can restore the XMP fields. If the thumbnail is stored in an XMP field as well (and it sounds like it is), it may be easier to concatenate that field with the other ones which were already grabbed, updating the temp file so that it contains EVERY XMP field, before adding all of the XMP fields back to the jpeg.
Unfortunately, I do not currently have the time to read a 50 page ISO standard, synthesize the information, and then write the code to implement the solution. Here's a link to the standard at least, to get you started.
https://www.iso.org/obp/ui/#iso:std:iso:16684:-1:ed-2:v1:en

Additional PDF Attachment in E-Mail (ABAP)

I'm currently trying to send the results of a selection via E-Mail, more precisely as an attachment. My goal is to create a XML-File (which works so far) and a PDF, both fed from the internal table in which the selected data is held. The internal table is declared with a custom type. My current code for sending the E-Mail with the XML attachment looks like following:
lr_send_request = cl_bcs=>create_persistent( ).
lr_document = cl_document_bcs=>create_document( i_type = 'HTM'
i_text = lt_text
i_subject = lv_subject ).
* ----- converting data of internal table so it is suitable for XML
...
* -----
lr_document->add_attachment( i_attachment_type = 'BIN'
i_attachment_subject = 'output.xml'
i_attachment_size = xml_size
i_attachment_language = sy-langu
i_att_content_hex = xml_content ).
lr_send_request->set_document( lr_document ).
On the web I was only able to find how to convert spooljob (whatever that is :/) into PDF. With functions like that I may be able to solve my problem but then I can't attach the XML anymore.
How can I convert the data of the internal table into a PDF file to attach it to the E-Mail in the same way I do with the XML?
There are multiple way to create PDF:
Create report with Smartform and get output in PDF format. Sample code
If your system has adobe form license create with adobe form.
Use zcl_pdf class for creating native pdf file.
Using CONVERT_ABAPSPOOLJOB_2_PDF FM for getting printer spool as pdf (thanks #Sandra Rossi).
If your PDF is simple (not include complex table, vertical text, images, etc) use third option, otherwise try first or second.

How to load an SVG and a referenced PNG from a REST service at the same time?

I'm trying to create a web service in PHP that can deliver an SVG with reference to a PNG raster image. Both the data for the SVG as well as the binary PNG image come from a MySQL database on the server.
Option A: Encode the PNG data in base-64 and embed it directly in the SVG, such as:
<image xlink:href="data:image/png;base64,..."/>
Concerns: 30% heavier load than loading it as pure binary and noticeable delay when loading it with Postman (or is this just because of Postman).
Option B: Call the PNG data as binary and save it as a file on the file system, then call the SVG file, which would then reference the physical PNG file.
Concerns: Involvement of the file system (which implies I need to start managing physical files, expiration dates etc).
Is there perhaps another way that an SVG can reference the binary data on the fly without it having to be on the file system?
To accomplish something similar (in my case sending data for SVGs with additional data about each file as binary files, which are much smaller than sending xml, text, or json) - I use CBOR. In my case, I compress the SVG using LZString compression first, and add this along with additional data attributes to a JSON object. Then I convert the JSON object to CBOR. I think CBOR can handle your base 64 data without any need for conversion - more information about it is here: cbor.io
I found a PHP library for CBOR here: https://github.com/2tvenom/CBOREncode
This may not be the way to go at all for you, but I thought I'd throw it out there just in case.

ObjectScript file create from stream

how can I create file (PDF file for example) from binary stream I have stored in global? I have stream stored in caché global and I need to create and save the file created by the stream using ObjectScript.
Thanks :)
It is not so easy. There is only one official way to create pdf in Cache, and it is ZEN reports. With ZEN reports you could create not only pdf, also possible to make html, xlsx. ZEN Reports used Apache FOP for generating it, any other ways also possible, but you should do it only by yourself.
Or maybe I misunderstood you, and you mean that your binary stream already contains PDF, and you just want to save it to some file. If so, you just have to copy your globalstream to filestream, with code like this:
set fs=##class(%Stream.FileBinary).%New()
set fs.Filename="c:\temp.pdf"
set tSC=fs.CopyFrom(yourStream)
set tSC=fs.%Save()

How to preserve XMP metadata in Objective C?

I need my photo-editor app to preserve unknown metadata entries that were existing in the original photo that was opened by my app (for example, non-standard XMP meta-data)
I tried to use the Apple's built-in meta-data read/write meta-data, with no success.
Is there a way to just copy all existing meta-data to a buffer, write it as-is and then change only specific entries?
Yes.
Use Adobe XMP SDK.
Read the metadata from the image when you open it using:
SXMPFiles myFile;
ok = myFile.OpenFile(filename, kXMP_UnknownFile, opts);
myFile.GetXMP(_meta); // _meta is a data member of the class that represents your photo (probably a subclass of NSDocument).
When saving the image, write the image content, then write _meta to the output file using SXMPFiles.PutXMP(...), and then set specific metadata entries that you like.
See Adobe XMP programming guide for more details about reading and writing XMP metadata.