如何在pdf中嵌入图像?

时间:2021-06-29 21:10:45

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 ?

我从电子邮件的内容生成pdf文件,该电子邮件包含图像。但我想在pdf中添加静态图像。在pdf中添加静态图像的方法是什么?

4 个解决方案

#1


-1  

i think that this will be helpfull to you http://www.tek-tips.com/viewthread.cfm?qid=1194867

我认为这对你有所帮助http://www.tek-tips.com/viewthread.cfm?qid=1194867

#2


1  

That depends on how you create the PDF. Usually (when drawing to a CGPDFContext) you use normal Quartz drawing functions to add an image.

这取决于您如何创建PDF。通常(绘制到CGPDFContext时)使用普通的Quartz绘图函数来添加图像。

#3


1  

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);
}

#4


0  

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.

我用PS和Word解决了类似的问题。这个简单的脚本打开Word并将图像插入到新文档中。然后,您可以手动将文档另存为PDF或其他格式。这也可以自动化,但我更喜欢让Word打开以检查它并在保存之前进行少量编辑。

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.

这个脚本对于摆脱旧杂志非常有用。只需将要保留的页面扫描到单个文件夹中的图像文件,运行脚本,然后将文档另存为Kindle的PDF文件。

$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]

#1


-1  

i think that this will be helpfull to you http://www.tek-tips.com/viewthread.cfm?qid=1194867

我认为这对你有所帮助http://www.tek-tips.com/viewthread.cfm?qid=1194867

#2


1  

That depends on how you create the PDF. Usually (when drawing to a CGPDFContext) you use normal Quartz drawing functions to add an image.

这取决于您如何创建PDF。通常(绘制到CGPDFContext时)使用普通的Quartz绘图函数来添加图像。

#3


1  

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);
}

#4


0  

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.

我用PS和Word解决了类似的问题。这个简单的脚本打开Word并将图像插入到新文档中。然后,您可以手动将文档另存为PDF或其他格式。这也可以自动化,但我更喜欢让Word打开以检查它并在保存之前进行少量编辑。

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.

这个脚本对于摆脱旧杂志非常有用。只需将要保留的页面扫描到单个文件夹中的图像文件,运行脚本,然后将文档另存为Kindle的PDF文件。

$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]