mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-07-16 03:29:17 +08:00
Merge pull request #541 from fnatzke/Fix540
Fix 540 Copy page with inline image.
This commit is contained in:
commit
88aaddcf26
BIN
src/UglyToad.PdfPig.Tests/Integration/Documents/ssm2163.pdf
Normal file
BIN
src/UglyToad.PdfPig.Tests/Integration/Documents/ssm2163.pdf
Normal file
Binary file not shown.
@ -11,6 +11,8 @@
|
||||
using System.Collections.Generic;
|
||||
using Tests.Fonts.TrueType;
|
||||
using Xunit;
|
||||
using System;
|
||||
using UglyToad.PdfPig.Graphics.Operations.InlineImages;
|
||||
|
||||
public class PdfDocumentBuilderTests
|
||||
{
|
||||
@ -167,6 +169,9 @@
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public void CanWriteSinglePageStandard14FontHelloWorld()
|
||||
{
|
||||
@ -1138,6 +1143,45 @@
|
||||
Assert.True(tw.WroteCrossReferenceTable);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanCopyInLineImage()
|
||||
{
|
||||
var docPath = IntegrationHelpers.GetDocumentPath("ssm2163.pdf");
|
||||
|
||||
using (var docOrig = PdfDocument.Open(docPath))
|
||||
{
|
||||
|
||||
// Copy original document with inline images into pdf bytes for opening and checking.
|
||||
PdfDocumentBuilder pdfBuilder = new PdfDocumentBuilder();
|
||||
var numberOfPages = docOrig.NumberOfPages;
|
||||
for (int pageNumber = 1; pageNumber <= numberOfPages; pageNumber++)
|
||||
{
|
||||
var sourcePage = docOrig.GetPage(pageNumber);
|
||||
pdfBuilder.AddPage(sourcePage.Width, sourcePage.Height).CopyFrom(sourcePage);
|
||||
}
|
||||
var pdfBytes = pdfBuilder.Build();
|
||||
|
||||
|
||||
using (var docCopy = PdfDocument.Open(pdfBytes))
|
||||
{
|
||||
var pageNum = 7;
|
||||
var origPage = docOrig.GetPage(pageNum);
|
||||
var copyPage = docCopy.GetPage(pageNum);
|
||||
|
||||
var opsOrig = origPage.Operations.Where(v => v.Operator == BeginInlineImageData.Symbol).Select(v => (BeginInlineImageData)v).ToArray();
|
||||
var opCopy = copyPage.Operations.Where(v => v.Operator == BeginInlineImageData.Symbol).Select(v => (BeginInlineImageData)v).ToArray();
|
||||
|
||||
var dictOrig = opCopy.Select(v => v.Dictionary).ToArray();
|
||||
var dictCopy = opCopy.Select(v => v.Dictionary).ToArray();
|
||||
|
||||
var exampleCopiedDictionary = dictCopy.FirstOrDefault();
|
||||
|
||||
Assert.NotNull(exampleCopiedDictionary);
|
||||
Assert.True(exampleCopiedDictionary.Count>0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteFile(string name, byte[] bytes, string extension = "pdf")
|
||||
{
|
||||
try
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Tokens;
|
||||
using UglyToad.PdfPig.Writer;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
@ -41,6 +42,16 @@
|
||||
/// <inheritdoc />
|
||||
public void Write(Stream stream)
|
||||
{
|
||||
var tokenWriter = TokenWriter.Instance;
|
||||
foreach (var item in Dictionary)
|
||||
{
|
||||
var name = item.Key;
|
||||
var value = item.Value;
|
||||
|
||||
stream.WriteText($"{name} ");
|
||||
tokenWriter.WriteToken(value, stream);
|
||||
stream.WriteNewLine();
|
||||
}
|
||||
stream.WriteText(Symbol);
|
||||
stream.WriteNewLine();
|
||||
}
|
||||
|
@ -80,6 +80,11 @@
|
||||
'%'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Single global instance
|
||||
/// </summary>
|
||||
public static TokenWriter Instance { get; } = new TokenWriter();
|
||||
|
||||
/// <summary>
|
||||
/// Writes the given input token to the output stream with the correct PDF format and encoding including whitespace and line breaks as applicable.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user