Skip to content

Commit fb76814

Browse files
Fix sample code based on improved usage of Image.Translate(). (#39)
The imaging code of the .NET and Java libraries has been updated significantly and now Image.Translate() takes coordinates as one would expect on the page. Whereas previously the values were based on internally applying the matrix multiplication backwards. Because of this change the sample needs to be updated to produce the correct output. Co-authored-by: Richard Gailiunas <[email protected]>
1 parent b6d4ae6 commit fb76814

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

ContentModification/ExtendedGraphicStates/ExtendedGraphicStates.cs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
41
using Datalogics.PDFL;
2+
using System;
53

64
/*
75
*
@@ -12,7 +10,7 @@
1210
*
1311
* This sample program shows how to use the Extended Graphic State object to add graphics parameters to an image.
1412
*
15-
* Copyright (c) 2007-2023, Datalogics, Inc. All rights reserved.
13+
* Copyright (c) 2007-2024, Datalogics, Inc. All rights reserved.
1614
*
1715
*/
1816

@@ -37,22 +35,34 @@ static void blendPage(Document doc, Image foregroundImage, Image backgroundImage
3735
gsText.FillColor = new Color(0, 0, 1.0);
3836
TextState ts = new TextState();
3937

38+
double spaceFactor = 18.0;
39+
double heightOffset = height - 88.0;
40+
4041
for (int i = 0; i < 16; i++)
4142
{
4243
Image individualForegroundImage = foregroundImage.Clone();
4344
Image individualBackgroundImage = backgroundImage.Clone();
4445

4546
GraphicState gs = individualForegroundImage.GraphicState;
4647
individualForegroundImage.Scale(0.125, 0.125);
47-
individualForegroundImage.Translate(800, 200 + height * (7 - i));
4848
individualBackgroundImage.Scale(0.125, 0.125);
49-
individualBackgroundImage.Translate(800, 200 + height * (7 - i));
5049

51-
// Halfway through, create 2nd column by shifting over and up
50+
spaceFactor = 18.0;
51+
if (i == 0)
52+
{
53+
spaceFactor = 0;
54+
}
55+
56+
//Halfway through, create 2nd column by shifting over and up
5257
if (i > 7)
5358
{
54-
individualForegroundImage.Translate(2400, height * 8);
55-
individualBackgroundImage.Translate(2400, height * 8);
59+
individualForegroundImage.Translate(400, heightOffset - (72.0 + spaceFactor) * (i - 8));
60+
individualBackgroundImage.Translate(400, heightOffset - (72.0 + spaceFactor) * (i - 8));
61+
}
62+
else
63+
{
64+
individualForegroundImage.Translate(100, heightOffset - (72.0 + spaceFactor) * i);
65+
individualBackgroundImage.Translate(100, heightOffset - (72.0 + spaceFactor) * i);
5666
}
5767

5868
docpage.Content.AddElement(individualBackgroundImage);
@@ -62,9 +72,14 @@ static void blendPage(Document doc, Image foregroundImage, Image backgroundImage
6272

6373
Matrix m = new Matrix();
6474
if (i > 7)
65-
m = m.Translate(480, 750 - ((i - 8) * 100)); // second column
75+
{
76+
m = m.Translate(480, heightOffset - (72.0 + spaceFactor) * (i - 8));// second column
77+
}
6678
else
67-
m = m.Translate(180, 750 - (i * 100)); // first column
79+
{
80+
m = m.Translate(180, heightOffset - (72.0 + spaceFactor) * i);// first column
81+
}
82+
6883
m = m.Scale(12.0, 12.0);
6984

7085
ExtendedGraphicState xgs = new ExtendedGraphicState();
@@ -193,7 +208,6 @@ static void Main(string[] args)
193208

194209
doc.EmbedFonts();
195210
doc.Save(SaveFlags.Full, sOutput);
196-
197211
}
198212
}
199213
}

0 commit comments

Comments
 (0)