Iphone 如何在pdf中嵌入图像?
我正在从电子邮件的内容生成一个pdf文件,该电子邮件包含一个图像。但我想在pdf中添加静态图像。在pdf中添加静态图像的方法是什么 我认为这将对您有所帮助这取决于您如何创建PDF。通常(当绘制到CGPDFContext时),您可以使用普通的Quartz绘制功能来添加图像。您可以这样做:Iphone 如何在pdf中嵌入图像?,iphone,image,pdf-generation,xcode4.2,Iphone,Image,Pdf Generation,Xcode4.2,我正在从电子邮件的内容生成一个pdf文件,该电子邮件包含一个图像。但我想在pdf中添加静态图像。在pdf中添加静态图像的方法是什么 我认为这将对您有所帮助这取决于您如何创建PDF。通常(当绘制到CGPDFContext时),您可以使用普通的Quartz绘制功能来添加图像。您可以这样做: -(void) CreatePdf { NSInteger currentY = HEIGHT; NSString *logoFileName = @"logo.jpg"; NSArray *
-(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);
}
我用PS和Word解决了一个类似的问题。这个简单的脚本打开Word并将图像插入到新文档中。然后您可以手动将文档保存为PDF或其他格式。这也可以自动化,但我更喜欢让Word保持打开状态以检查它,并在保存之前进行小的编辑 这个脚本对处理旧杂志很有用。只需扫描要保存在单个文件夹中的图像文件的页面,运行脚本,然后将文档另存为PDF供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]
我认为OP讨论的是以编程方式生成PDF,而不是通过GUI界面。thaks进行回放。我用过你的密码。但是我得到了错误:CGContextDrawImage:invalid context 0x34b1c8d“pdfContext的值应该是多少?因为我在上下文中遇到错误,即无效上下文。感谢重播。我使用了Hardik建议的相同代码。但是我得到了一个错误-“:CGContextDrawImage:invalid context”。请提供解决方案。谢谢。您应该首先提供如何从邮件中创建PDF的代码。