mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-10-15 19:54:52 +08:00
fix reading nested array for page content
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Content;
|
||||
using Exceptions;
|
||||
using Filters;
|
||||
@@ -63,14 +61,13 @@
|
||||
{
|
||||
// ignored for now, is it possible? check the spec...
|
||||
}
|
||||
else if (contents is ArrayToken array)
|
||||
else if (DirectObjectFinder.TryGet<ArrayToken>(contents, pdfScanner, out var array))
|
||||
{
|
||||
var bytes = new List<byte>();
|
||||
|
||||
foreach (var item in array.Data)
|
||||
{
|
||||
var obj = item as IndirectReferenceToken;
|
||||
if (obj == null)
|
||||
if (!(item is IndirectReferenceToken obj))
|
||||
{
|
||||
throw new PdfDocumentFormatException($"The contents contained something which was not an indirect reference: {item}.");
|
||||
}
|
||||
@@ -88,8 +85,7 @@
|
||||
content = GetContent(bytes, cropBox, userSpaceUnit, isLenientParsing);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: this can be an array of stream objects... investigate
|
||||
{
|
||||
var contentStream = DirectObjectFinder.Get<StreamToken>(contents, pdfScanner);
|
||||
|
||||
if (contentStream == null)
|
||||
@@ -109,11 +105,6 @@
|
||||
|
||||
private PageContent GetContent(IReadOnlyList<byte> contentBytes, CropBox cropBox, UserSpaceUnit userSpaceUnit, bool isLenientParsing)
|
||||
{
|
||||
if (Debugger.IsAttached)
|
||||
{
|
||||
var txt = OtherEncodings.BytesAsLatin1String(contentBytes.ToArray());
|
||||
}
|
||||
|
||||
var operations = pageContentParser.Parse(new ByteArrayInputBytes(contentBytes));
|
||||
|
||||
var context = new ContentStreamProcessor(cropBox.Bounds, resourceStore, userSpaceUnit, isLenientParsing, pdfScanner, xObjectFactory);
|
||||
|
@@ -6,6 +6,36 @@
|
||||
|
||||
internal static class DirectObjectFinder
|
||||
{
|
||||
public static bool TryGet<T>(IToken token, IPdfTokenScanner scanner, out T tokenResult) where T : IToken
|
||||
{
|
||||
tokenResult = default(T);
|
||||
if (token is T t)
|
||||
{
|
||||
tokenResult = t;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(token is IndirectReferenceToken reference))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var temp = scanner.Get(reference.Data);
|
||||
|
||||
if (temp.Data is T tTemp)
|
||||
{
|
||||
tokenResult = tTemp;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (temp.Data is IndirectReferenceToken nestedReferenceToken)
|
||||
{
|
||||
return TryGet(nestedReferenceToken, scanner, out tokenResult);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static T Get<T>(IToken token, IPdfTokenScanner scanner) where T : IToken
|
||||
{
|
||||
if (token is T result)
|
||||
|
Reference in New Issue
Block a user