converting image to pdf using fpdf library reduces clarity of pdf content - fpdf

I have trying to convert image to pdf using mpdf library,everything works well but the clarity of content is missing in pdf generated.The image i have been trying will have dynamic width and height.If i fixed width and height,then some of the pdf's content are expanding ,some are missing content.
$pdf = new FPDF();
$pdf->AddPage();
$pdf->Image('uploads/'.$imagefile_name,10,10,200,250);
$pdf->Output('F', 'uploads/' . $file_name, true);
I have tried different codes,can anyone help me so that width and height is set dynamically without missing clarity

Related

html2canvas, only half of image is drawn or not draw some image

I am using html2canvas to capture entire of webpage but got problem some image can not draw or draw half of image. See my attachments.
This is my code
var config = {
proxy: base_url + "proxy",
logging: true
};
html2canvas(document.body, config).then(function (canvas) {
my_image = canvas.toDataURL("image/jpeg");
resolve(true);
});
I tried html2canvas 1.0.0-rc.1 and html2canvas 1.0.0-rc.5 but not luck.
Also try set image timeout option, also try to remove some html element to make sure html page not too large but same result.
This is origin image
This is the capture result (please don't mind the line in image, I just added it)
Any help!
After all, I found problem is max canvas height around 16.000px, my canvas went to 30.000px height.
So I split to many parts and store it.

pdfStamper.AcroFields.SetField dont keep appearance settings

I use iTextSharp 5.5.13 to create pdf file with text AcroFields and in a second step edit the pdf filling the AcroFields with some values.
For some fields i have to set a character spacing, so i use CreateAppearance method. this is the code:
var appearance = writer.DirectContent.CreateAppearance(box.Width, box.Height);
appearance.SetFontAndSize(baseFont, obj.FontSize);
appearance.SetColorFill(new iTextSharp.text.BaseColor(obj.Color));
appearance.SetCharacterSpacing(obj.CharSpacing);
formField.DefaultAppearanceString = appearance;
formField.SetAppearance(iTextSharp.text.pdf.PdfAnnotation.APPEARANCE_NORMAL, appearance);
writer.AddAnnotation(formField);
this code produce expected pdf result with fine character spacing in editable fields.
The problem is when i edit the pdf to fill AcroFields with:
pdfStamper.FormFlattening = true;
pdfStamper.AcroFields.GenerateAppearances = true;
pdfStamper.AcroFields.SetField(fieldName, fieldValue);
the resulting flattened pdf does not mantain the appearence character spacing...
What's wrong with my code?
Thanks
For generating text field appearances iText 5.x only uses the font, font size, and color information from the DA default appearance string (and the color information only if set using the g, rg, or k instructions), cf. the AcroFields method SplitDAelements which is used to extract information from the DA string.
So the iText 5.x appearance generation is quite limited and in particular does not support character spacing.
A possible work-around is for you to explicitly create all the appearances in your own code.

Writing to absolute position while using direct content

I am creating a pdf-document. First I add a table and some Texts to the PdfWriter. Now I want to add a costum template (including images and texts): I have to get the direct Content, which ist a layer over the PdfWriter-layer:
over= PdfWriter.getDirectContent();
I want to set the template exactly after the content on PdfWriter-layer.
I can use
writer.getVerticalPosition(true)
for my calculation of y-Position on PdfWriter-layer.
This way I can add the costum template to the upper layer at that position. Now back to PdfWriter-layer how can I set the position of PdfWriter-layer after the tempalte on over-layer?!
Can somebody help?
Thanks in advance.
Mixing content added with document.add() and direct content us always a delicate operation. You need to know the height of the custom template and then add some white space that matches that height. However: what are you going to do if the content of the custom template doesn't match the page?
I would advise against your plans, and I would recommend another approach.
I am assuming that your custom template is a PdfTemplate object. In that case, you can wrap this object inside an Image object, and use document.add() to add the template.
See for instance: Changing Font on PDF Rotated Text
In this example, we create a PdfTemplate with a bar code and some text:
PdfTemplate template = canvas.createTemplate(rect.getWidth(), rect.getHeight() + 10);
ColumnText.showTextAligned(template, Element.ALIGN_LEFT,
new Phrase("DARK GRAY", regular), 0, rect.getHeight() + 2, 0);
barcode.placeBarcode(template, BaseColor.BLACK, BaseColor.BLACK);
We want to add this template to a document with document.add(), so we wrap the template inside an Image object:
Image image = Image.getInstance(template);
We can now add this image to the document:
document.add(image);
Afterwards, we can add extra content:
Paragraph p3 = new Paragraph("SMALL", regular);
p3.setAlignment(Element.ALIGN_CENTER);
document.add(p3);
That content is added under the template at the right position. You don't need to worry anymore about getting the Y position with getVerticalPosition() and you don't need to worry about setting the Y position after adding the template. If the template doesn't fit on the current page, it will automatically be moved to the next page.
Important: Maybe you are worried about the resolution of your template. You shouldn't be. If the template consists of vector data, wrapping that data inside an Image object won't change it into raster data. The vector data will be preserved. This is important in the bar code example, because you don't want the quality of your bar code to deteriorate by making it a raster image.

Using itext and jfreechart need to create image for legendtitle alone

Can you please help me to get Image for legendtitle alone ?
I am using pieplot3d & doing customization and later I create legendtitle(plot
when I use draw method
legend.draw(graphics2d,rectangle2d
graphics2.dispose
Image.getInstance(template
I am using jfreechart with Itext & doing as mention below
add image to document or PdfCell its empty.
My requirment is to show plot/chart in seperate cell/table & legend in seperate cell table so that when there is change in size of legenditems size of chart wont change.
Please help.

extract pdf formatting

hi guys working on a app which main work is pdf editing.
i understand Apple doesn't provide any api for editing the pdf. but my requirements are like that.
so i thought of extracting the whole contents of the pdf file and create a new pdf after editing. now i need to know how to extract the pdf formatting (header, footer, images, highlighting.,,)
im using Tj operators to extract the pdf text. which operators should i use to extract the other informations of pdf file.
thanks in advance.
Images are painted on the page using the Do operator. Its operand is the image name in the resources dictionary. The Do operator also paints form XObjects (self contained vector graphics) and these are stored also in the resources dictionary. The Subtype key in the image/form XObject dictionary gives you the object type: "Image" for images and "Form" for form XObjects.
The other elements are plain vector graphics and text, the PDF files do not have headers, footers, paragraphs, etc as standalone objects. What you see visually as a page header, inside the PDF file is just plain text painted at the top of the page.
Highlights can be plain semi-transparent yellow rectangles (these are no different from other rectangles on the page) or highlight annotations (these are available in page's Annots array).