【问题标题】:iOS pdf with image encoded as ccitt图像编码为 ccitt 的 iOS pdf
【发布时间】:2018-05-01 09:53:28
【问题描述】:

有没有人使用过将图像编码为 ccitt 的 PDF。 我使用 Xamarin,几乎所有的 pdf 似乎都可以工作。但是这种编码似乎很困难。该应用程序适用于 iOS。 页面大小正确但完全空白。

var pageRect = _page.GetBoxRect(CGPDFBox.Media);
pageRect.Size = new CGSize(pageRect.Size.Width, pageRect.Size.Height);
//pageRect.Origin = CGPointZero;

UIGraphics.BeginImageContext(pageRect.Size);
CGContext context = UIGraphics.GetCurrentContext();

//White BG
context.SetFillColor(1.0f, 1.0f, 1.0f, 1.0f);
context.FillRect(pageRect);
context.SaveState();

// Next 3 lines makes the rotations so that the page look in the right direction
context.TranslateCTM(0.0f, pageRect.Size.Height);
context.ScaleCTM(1.0f, -1.0f);
CGAffineTransform transform = _page.GetDrawingTransform(CGPDFBox.Media, pageRect, 0, true);
context.ConcatCTM(transform);

context.DrawPDFPage(_page);
context.RestoreState();

UIImage img = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();

return img;

_page 是CGPDFPage 对象。

或者有人有从 PDF 文件中获取图像的 sn-p 吗? DrawPDFPage 是我认为无法处理此 pdf 的问题。 swift或c中的片段没问题

更新 我在我的应用程序中默认使用CATiledLayer。这将在部分(图块)中呈现 pdf,因此大 pdf 将显示部分而不是等待很长时间。 我发现当设置编码时,上面的代码会起作用,因为它会先渲染完整的pdf然后显示在屏幕上。

CATiledLayer 在这种情况下不起作用并显示空/空白页面。 我现在的搜索是寻找CGPDFDocumentCGPDFPage 将返回我的元数据以便我能够查看编码的方式。 有人体验过吗?

【问题讨论】:

  • 试试这个tool来帮助你创建图像,这个solution也许也有帮助。
  • @ColeXia-MSFT 感谢您的建议。但是,这不起作用,因为它与上述相同。整个页面的绘图一次可以正确使用编码,但不能部分(图块)。你知道如何获取 pdf 页面的元数据吗?

标签: c# ios swift xamarin


【解决方案1】:

经过长时间的调试,我找到了解决方案。 CTM 已经在 ConcatCTM 中完成 我不知道到底是什么,这是我的结果:

// fill with white background
context.SetFillColor(1f, 1f, 1f, 1f);
context.FillRect(Bounds);
context.SaveState();

var pageRect = _page.GetBoxRect(CGPDFBox.Media);
context.TranslateCTM(0, Bounds.Height);
context.ScaleCTM(1, -1);

//get the affine transform that defines where the PDF is drawn
var affineTransform = _page.GetDrawingTransform(CGPDFBox.Media, layer.Bounds, 0, true);
//concatenate the pdf transform with the CTM for display in the view
context.ConcatCTM(affineTransform);

context.DrawPDFPage(_page);
context.RestoreState();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-05
    • 2016-02-24
    • 1970-01-01
    • 2020-10-21
    • 2012-12-22
    • 2011-07-16
    • 2018-02-28
    • 1970-01-01
    相关资源
    最近更新 更多