Skip to content

Commit ba8e1e1

Browse files
lofczBobLd
authored andcommitted
fix #1017
fix test name
1 parent 0754e7f commit ba8e1e1

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ $tf/
105105
_ReSharper*/
106106
*.[Rr]e[Ss]harper
107107
*.DotSettings.user
108+
.idea
108109

109110
# JustCode is a .NET coding add-in
110111
.JustCode
Binary file not shown.

src/UglyToad.PdfPig.Tests/Writer/PdfDocumentBuilderTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,24 @@ public void CanGeneratePageWithMultipleStream()
780780
}
781781
}
782782

783+
[Fact]
784+
public void CanCopyIssue1017()
785+
{
786+
using (var document = PdfDocument.Open(IntegrationHelpers.GetDocumentPath("_citUR2jB1_ay56u6vELzk.pdf")))
787+
{
788+
using (var pdfWriter = new PdfDocumentBuilder())
789+
{
790+
var page = document.GetPage(1);
791+
792+
var newPage = pdfWriter.AddPage(page.Width, page.Height);
793+
newPage.CopyFrom(page);
794+
795+
var b = pdfWriter.Build();
796+
Assert.NotEmpty(b);
797+
}
798+
}
799+
}
800+
783801
[Fact]
784802
public void CanCopyPage()
785803
{

src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -974,13 +974,16 @@ public PdfPageBuilder CopyFrom(Page srcPage)
974974

975975
gstateName = newName;
976976
}
977-
978-
if (!(gstate.Value is IndirectReferenceToken fontReferenceToken))
977+
978+
// According to PDF spec 32000-1:2008, section 8.4.5, ExtGState can contain both direct values and indirect references
979+
if (gstate.Value is IndirectReferenceToken fontReferenceToken)
979980
{
980-
throw new PdfDocumentFormatException($"Expected a IndirectReferenceToken for the XObject, got a {gstate.Value.GetType().Name}");
981+
pageGstateDictionary[gstateName] = documentBuilder.CopyToken(srcPage.pdfScanner, fontReferenceToken);
982+
}
983+
else
984+
{
985+
pageGstateDictionary[gstateName] = documentBuilder.CopyToken(srcPage.pdfScanner, gstate.Value);
981986
}
982-
983-
pageGstateDictionary[gstateName] = documentBuilder.CopyToken(srcPage.pdfScanner, fontReferenceToken);
984987
}
985988
}
986989

0 commit comments

Comments
 (0)