如何在pdf中嵌入图像?

发布于 2025-01-04 01:56:24 字数 80 浏览 0 评论 0原文

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

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

無心 2025-01-11 01:56:24

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

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

匿名的好友 2025-01-11 01:56:24

你可以这样做:

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

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);
}
罪#恶を代价 2025-01-11 01:56:24

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

该脚本对于删除旧杂志很有用。只需将要保留的页面扫描到单个文件夹中的图像文件中,运行脚本,然后将文档另存为适用于 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]

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]
初见 2025-01-11 01:56:24

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文