I have a property below named AWords.Rotated that tells me the rotation of the page. However, all my AWords coordinates are based on the rotation being 0.
I'd like to do a APage.Set_Rotation() call before I place content to ensure the Page in rotated upright. But this doesn't seem to work. I rotates the image part of the page but the content placement doesn't get rotated.
How can I modify the code below to allow for the proper placement of text regardless of the PDF page rotation. Again, I know before I make this call whether the PDF page is rotated or not. And the word coordinates I have are always based on a 0 rotation angle.
Also, am I using the IPXC_ContentCreator interface correctly in my loop of Words below? It seems to place the words very slowly. It seems like I'm placing one word at a time. Is there a way to place all the words at once.
Code: Select all
procedure TMyPDF.PlaceOCRWords(APageNum: Integer; AWords: TOCRWords; AOneTextObject: Boolean);
var
CC: IPXC_ContentCreator;
AContent: IPXC_Content;
AFont: IPXC_Font;
AText: String;
i, ADPI: Integer;
AFontSize, x, y: Double;
AInchesH, AInchesW, AHeight: Double;
APage: IPXC_Page;
AWord: TOCRWord;
begin
if Assigned(FDoc) and IsValidPageNumber(APageNum) then
begin
try
if (High(AWords.Items) = -1) and (Trim(AWords.WordsAsText) <> '') then
begin
AOneTextObject := True;
end;
ADPI := AWords.ImageDPI;
if (ADPI = 0) then ADPI := 300;
ADPI := Max(100, ADPI);
if (AWords.ImageWidth <= 100) then AWords.ImageWidth := Floor(8.5 * ADPI);
if (AWords.ImageHeight <= 100) then AWords.ImageHeight := Floor(11 * ADPI);
//ALWAYS CREATE PAGE STRAIGHT UP. WILL ROTATE IT BELOW
//Image size reflect original before any rotation
if (Abs(AWords.Rotated) = 90) or (Abs(AWords.Rotated) = 270) then
begin
AInchesW := AWords.ImageHeight / ADPI;
AInchesH := AWords.ImageWidth / ADPI;
end else
begin
AInchesH := AWords.ImageHeight / ADPI;
AInchesW := AWords.ImageWidth / ADPI;
end;
except
AInchesH := 11;
AInchesW := 8.5;
end;
AFont := FDoc.CreateNewFont('Arial', 0, 400);
APage := GetPage(APageNum); //Test Page is 612 x 792 points
for i := 0 to High(AWords.Items) do
begin
AWord := AWords.Items[i];
AText := AWord.Text;
AFontSize := AWord.FontSize;
x := X2P(AWord.Left, ADPI);
y := I2P(AInchesH) - X2P(AWord.Top + AWord.Height, ADPI);
CC := FDoc.CreateContentCreator;
CC.SetTextRenderMode(TRM_None); //TRM_None; //TRM_Fill
CC.SetFont(AFont);
CC.SetFontSize(AFontSize);
CC.SetStrokeColorRGB(RGB(0, 0, 0));
CC.ShowTextLine(x, y, PChar(AText), -1, STLF_Baseline); //Use Baseline
CC.Detach(AContent);
APage.PlaceContent(AContent, PlaceContent_After);
end;
//APage.Set_Rotation(AWords.Rotated);
APage := nil;
WriteToLog(Format('placed %d words on page %d', [High(AWords.Items) + 1, APageNum]));
end;
end;