Reputation: 2935
i m generating a pdf file from the contents of email and that email contains an image. But i wanted to add that image static in that pdf. what could be the way of adding a static image in pdf ?
Upvotes: 0
Views: 1887
Reputation: 3357
I solved a similar problem using PS and Word. This simple script opens Word and inserts images into a new doc. Then you can manually save the doc as a PDF or other formats. This can be automated too, but I prefer to leave Word open to inspect it and make minor edits before saving.
This script is useful for getting rid of old magazines. Just scan the pages you want to keep to image files in a single folder, run the script, then save the doc as a PDF for your Kindle.
$letterWidth = 612
$letterHeight = 792
$topMargin = 0
$bottomMargin = 0
$leftMargin = 0
$rightMargin = 0
function Main([string] $dir)
{
$files = dir $dir
$doc, $selection = OpenWordDoc
foreach ($file in $files)
{
$par = $doc.Paragraphs.Add()
$par.SpaceAfter = 0
$par.Alignment = 1
$pic = $par.Range.InlineShapes.AddPicture($file.FullName)
ScaleImage $pic
}
}
function ScaleImage($pic)
{
$hScale = ($letterWidth - $leftMargin - $rightMargin) / $pic.Width
$vScale = ($letterHeight - $topMargin - $bottomMargin) / $pic.Height
$scale = [Math]::Min($hScale, $vScale) * 100
$pic.ScaleHeight = $pic.ScaleWidth = $scale
}
function OpenWordDoc()
{
$word = new-object -ComObject "word.application"
$word.Visible = $True
$doc = $word.documents.Add()
$doc.PageSetup.TopMargin = $topMargin
$doc.PageSetup.BottomMargin = $bottomMargin
$doc.PageSetup.LeftMargin = $leftMargin
$doc.PageSetup.RightMargin = $rightMargin
$doc, $word.Selection
}
. Main $args[0]
Upvotes: 0
Reputation: 1693
You can do like this :
-(void) CreatePdf
{
NSInteger currentY = HEIGHT;
NSString *logoFileName = @"logo.jpg";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *saveDirectory = [paths objectAtIndex:0];
NSString *logoFilePath = [saveDirectory stringByAppendingPathComponent:logoFileName];
currentY = [self getAbsoluteY:currentY :70];
UIImage *logoImage = [UIImage imageWithContentsOfFile:logoFilePath];
CGContextDrawImage(pdfContext, CGRectMake(paddingLeft, currentY, 100, 70), [logoImage CGImage]);
}
-(NSInteger)getAbsoluteY:(NSInteger)currY: (NSInteger)space
{
return (currY - space);
}
Upvotes: 1
Reputation: 81868
That depends on how you create the PDF. Usually (when drawing to a CGPDFContext) you use normal Quartz drawing functions to add an image.
Upvotes: 1
Reputation: 44
i think that this will be helpfull to you http://www.tek-tips.com/viewthread.cfm?qid=1194867
Upvotes: -1