iTextSharp convert to .pdf - change MIME Type - itext

Resolved:
This had nothing to do with iTextSharp. The culprit is XMPIE and how it renders pdfs.
I'm using iTextSharp to convert .pngs to pdfs.
Here's a snippet of code:
var image = iTextSharp.text.Image.GetInstance(imageBytes);
document.Add(image);
My question is: does this actually convert the .png to a .pdf? Does it change the Mime type?
I am trying to use the converted image in XMPIE, which does not support .pngs. The "conversion" seems to work -- meaning that I get a pdf that has my image on it. But when I try to display that image in xmpie it displays all blurred out and grey. The "conversion" works with .jpegs but not .pngs.
Is there another way to convert an image (.png) to a .pdf. My code just seems to add the image to the .pdf and doesn't actually change the mime type.

Related

How to manipulate all pages in a multi-page tiff image without converting it into list of single images in Pillow?

I would like to insert a small image to each page in a multi-page tiff using Pillow.
But this fails:
from PIL import Image, ImageSequence
stack = Image.open(r"D:\pillow_temp\stack_example.tif") # opens an rgb multi tiff
insert= Image.open("D:\pillow_temp\insert.tif") # opens a single page rgb multi tiff
for page in ImageSequence.Iterator(stack):
page.paste(insert,(0,0))
stack.save(r"D:\pillow_temp\out_fails.tif", format="TIFF", save_all=True)
Transforming the multi-page tiff to a list and saving one changed image first followed by appending the rest of the images works but doesn't feel proper.
pages= []
for page in ImageSequence.Iterator(stack):
page = page.copy()
page.paste(insert,(0,0))
pages.append(page)
pages[0].save(r"D:\pillow_temp\out_works.tif", format="TIFF", save_all=True, append_images=pages[1:])
Is there a way to manipulate the pages directly in the PIL.TiffImagePlugin.TiffImageFile object and call im.save("filename.tiff", format="TIFF", save_all=True) directly?
All help is appreciated.
https://pillow.readthedocs.io/en/stable/reference/ImageSequence.html?highlight=multi%20tiff%20iterator#the-iterator-class
https://pillow.readthedocs.io/en/stable/releasenotes/3.4.0.html?highlight=multitiff%20image%20save#save-multiple-frame-tiff

How to get the Elements of a pdf using iText java

I have trouble in getting a element from pdf i.e., Signature and I want to append signature image beside the Signature Field.
I found that it is not AcroField.

showing bullets, numbering and images in pdf

In an asp.net mvc-2 application I need to export a view to pdf. I am using itextsharp to generate pdf. In the application I have documents which contains different instructions with instruction title and different images attached to it. I need to export all the instructions under a document to pdf. The instruction title contains bullets and numbering. It is stored in the database in html format. Also the images attached to each instruction is stored in the db in byte format. My pdf contains a table with each row representing an instruction. I am facing two basic issues in generating pdf with these data :
When I try to show the title, it is shown with html tags. In the pdf I need to show the title with bullets and numbers(ie. as entered through the editor).
I need to show byte stream images attached to each instruction in the pdf.
See the first three paragraphs of my post here for the answer to your first problem.
For your second question, iTextSharp (and more to the point, the PDF format) supports several formats. For formats not supported you can use the .Net Framework to convert many of them to a usable format. (The easiest to work with is probably JPEG.)
See this post if you need to know hot to get raw bytes from a database. Once you've got bytes you can use iTextSharp.text.Image.GetInstance() which has (as of 5.1.1) 15 overloads including ones that takes raw bytes, a System.Drawing.Image and `System.IO.Stream'.

How to display image blob from postgres to VB 6?

I have an application written in VB6 and would like to know how I would display an image blob from postgres to VB6?
If the image blob is in one of several standard formats (BMP, JPEG, GIF, TIFF file format) you can use WIA 2.0 for this.
Get the blob as a Byte array, create a WIA.Vector object, assign the Byte array to the Vector.BinaryData property, then you can use the Vector.Picture property to retrieve a StdPicture object you can assign to an Image or PictureBox control.
This code can help if the image can be loaded to a picture box.
See the PictureFromByteStream() Function in Module1.bas

Making a PDF output in raster format instead of vector using itextsharp

I have written C# code to save product specifications to a PDF document using iTextSharp, mainly with PdfPTable and Chunks/Paragraphs in the PdfPCells. However, I have been told that the output is unacceptable due to the fact that you can highlight and copy the text from the document and document storage and retrieval server software that they are currently using does not support "Vector" based PDFs. I'm not exactly certain what the difference is between a raster pdf and and vector pdf. Basically, every page of the PDF Document should be an image so that the text can not be highlighted. Is there any way to do this without using the DirectContent? Below is an image, illustrating a portion of the PDF that was created, and how the text can be selected and copied, which is the incorrect functionality.
I would like to avoid directly writing to the canvas, unless there is a way to do this and still have itextsharp handle my formatting and proper paging.
The windows application PDF2R works well, but doesn't seem to offer any programmatic solutions. I have found libraries that stated that they do this sort of conversion, but are several thousand dollars. I'd like to work within my budget and use the itextsharp or something much cheaper than this.
I would suggest you try to generate an image using the System.Drawing class and then insert that into the PDF document.
Call this code on your PdfWriter object:
writer.SetEncryption(PdfWriter.STRENGTH40BITS, null, null, PdfWriter.AllowPrinting);
This won't prevent users from selecting text, but it will prevent them from copying and pasting it. Give it a try.