Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
![]() |
Reading a PDF and Drawing the same PDF .. |
Post Reply
|
| Author | |
oliveira
Beginner
Joined: 16 Apr 10 Location: Brasil Status: Offline Points: 3 |
Post Options
Thanks(0)
Quote Reply
Topic: Reading a PDF and Drawing the same PDF ..Posted: 16 Apr 10 at 12:49PM |
|
Hi
I am using QuickPDF and get the example in "http://www.quickpdf.org/forum/span-classhighlightextract-span-text-and-images-and-insert-into-new-pdf_topic1308_post5993.html?KW=extract#5993", but my new document stay different the old document. I am thinking that problem is the fonts.. Can I help me? This is my real problem : 1º I have a document pdf IMAGE. OK 2º I need to read this document and make a OCR . OK 3º I extract the text the document and save this text in BLOB in SqlSErver. OK 4º I need read the BLOB and draw another PDF. PROBLEM The new document is diferent the old document. Why? When I draw the new document, and after I open with acrobat or foxit, for example.. Select a text, copy and paste, there is a problem with this selection.. For example, I select and copy in clipboard "PODER JUDICIÁRIO" when I cut the result is "PODE R JUDICIÁRI O" What´s happen? Sorry my english.. Thanks |
|
![]() |
|
Ingo
Moderator Group
Joined: 29 Oct 05 Status: Offline Points: 3530 |
Post Options
Thanks(0)
Quote Reply
Posted: 16 Apr 10 at 8:52PM |
|
Hi!
I think without the code nobody can help you 'cause all help will begin with "perhaps" or "it could be..." ;-) You should save the complete pdf as a string in the blob and not only the real text (like you've written). After this you should load the complete blob-content with LoadFromString (or stream). It's described in the reference... Please read my post "QuickPDF... The first steps" in the general section. Sorry but i can't understand these portugiese or spanish error messages... Cheers and welcome here, Ingo Edited by Ingo - 16 Apr 10 at 8:53PM |
|
![]() |
|
oliveira
Beginner
Joined: 16 Apr 10 Location: Brasil Status: Offline Points: 3 |
Post Options
Thanks(0)
Quote Reply
Posted: 16 Apr 10 at 9:19PM |
|
Hello Ingo Sorry my english .. eheheh This is the code.. i open the file ORIGINAL.PDF get the text and draw in a new file GERADO.PDF. Perhaps, the file GERADO.PDF is different the ORIGINAL.PDF. When i open the file GERADO.PDF in acrobat or foxit, select a tex, copy and cut..doesn't work For example.. there is a text "PODER JUDICIÁRIO" if i select this text, copy and cut in notepad.. the result is "PODE R JUDICIÁRI O" with spaces.. I need read a PDF and produce the same pdf.... procedure TfTestePDF.Button3Click(Sender: TObject); var FH: Integer; PR: Integer; SL: TStringList; Data: string; Font: string; Color: string; aColor: TColor; Size: string; X1, Y1, X2, Y2, X3, Y3, X4, Y4: string; Text: string; X, I: Integer; IL: Integer; PageNum: Integer; ImageData: string; ImageLeft, ImageTop, ImageWidth, ImageHeight: Double; QP : TspQuickPDF; //slFont : TStringList; fontsFoundCount: Integer; nFont: Integer; fontControl: TStringList; fontExists: Boolean; StandardFont : Integer; begin QP := TspQuickPDF.CreateUnlocked; try QP.LoadFromFile('C:\Temp\PDF\ORIGINAL.pdf'); // Open the file in direct access mode and store the file handle FH := (QP.DAOpenFile(PChar(Utf8ToAnsi('C:\Temp\PDF\ORIGINAL.pdf')), '')); // Start a new document QP.NewDocument; //for PageNum := 1 to QP.DAGetPageCount(FH) do for PageNum := 2 to 2 do begin // Specify that images should be compressed QP.CompressImages(1); // Get a page reference to the current page PR := QP.DAFindPage(FH, PageNum); // Create a string list to hold the text data SL := TStringList.Create; fontControl := TStringList.Create; try SL.Text := Utf8ToAnsi(QP.DAExtractPageText(FH, PR, 4)); // Add each block of text to the new document for X := 0 to SL.Count - 1 do begin Data := SL[X]; Font := Copy(Data, 1, Pos('#', Data) - 2); Delete(Data, 1, Length(Font) + 1); Color := Copy(Data, 1, Pos(',', Data) - 1); Delete(Data, 1, Length(Color) + 1); Size := Copy(Data, 1, Pos(',', Data) - 1); Delete(Data, 1, Length(Size) + 1); X1 := Copy(Data, 1, Pos(',', Data) - 1); Delete(Data, 1, Length(X1) + 1); Y1 := Copy(Data, 1, Pos(',', Data) - 1); Delete(Data, 1, Length(Y1) + 1); X2 := Copy(Data, 1, Pos(',', Data) - 1); Delete(Data, 1, Length(X2) + 1); Y2 := Copy(Data, 1, Pos(',', Data) - 1); Delete(Data, 1, Length(Y2) + 1); X3 := Copy(Data, 1, Pos(',', Data) - 1); Delete(Data, 1, Length(X3) + 1); Y3 := Copy(Data, 1, Pos(',', Data) - 1); Delete(Data, 1, Length(Y3) + 1); X4 := Copy(Data, 1, Pos(',', Data) - 1); Delete(Data, 1, Length(X4) + 1); Y4 := Copy(Data, 1, Pos(',', Data) - 1); Delete(Data, 1, Length(Y4) + 1); Text := Copy(Data, 2, Length(Data) - 2); // Replace the utf-8 encoded TM symbol with the // PDF WinAnsi character code if Pos(#226#132#162, Text) > 0 then Text := StringReplace(Text, #226#132#162, #153, [rfReplaceAll]); fontExists := false; for I := 0 to fontControl.Count - 1 do begin if (fontControl.Strings = Font) then fontExists := true; end; If (not fontExists) then begin nFont := QP.AddTrueTypeFont(Font, 0); fontControl.Add(Font); end; if QP.SelectFont(nFont) = 1 then begin // Set the text size QP.SetTextSize(StrToFloat(StringReplace(Size, '.', ',', [rfReplaceAll]))); // Draw the text, shift up by the font's "descent" value QP.DrawText(StrToFloat(StringReplace(X1, '.', ',', [rfReplaceAll])), StrToFloat(StringReplace(Y1, '.', ',', [rfReplaceAll])) - QP.GetTextDescent, Text); end; end; finally SL.Free; fontControl.Free; end; // Find all the images on the page IL := QP.DAGetPageImageList(FH, PR); // Loop through all the images for X := 1 to QP.DAGetImageListCount(FH, IL) do begin // Read the image data ImageData := QP.DAGetImageDataToString(FH, IL, X); // Add the image data to the new document QP.AddImageFromString(ImageData, 0); // Determine the location and size of the image on the page ImageLeft := QP.DAGetImageDblProperty(FH, IL, X, 501); ImageTop := QP.DAGetImageDblProperty(FH, IL, X, 502); ImageWidth := QP.DAGetImageDblProperty(FH, IL, X, 503) - QP.DAGetImageDblProperty(FH, IL, X, 501); ImageHeight := QP.DAGetImageDblProperty(FH, IL, X, 502) - QP.DAGetImageDblProperty(FH, IL, X, 508); // Draw the image onto the new document's page QP.DrawImage(ImageLeft, ImageTop, ImageWidth, ImageHeight); end; // End image loop end; // Save the file QP.SaveToFile('C:\Temp\PDF\GERADO'+ '.pdf'); // Remove the document QP.RemoveDocument(QP.SelectedDocument); finally FreeAndNil(QP); end; end;
|
|
![]() |
|
oliveira
Beginner
Joined: 16 Apr 10 Location: Brasil Status: Offline Points: 3 |
Post Options
Thanks(0)
Quote Reply
Posted: 16 Apr 10 at 9:20PM |
|
Hi..
I can send the file original.pdf for you.. thanks
|
|
![]() |
|
Ingo
Moderator Group
Joined: 29 Oct 05 Status: Offline Points: 3530 |
Post Options
Thanks(0)
Quote Reply
Posted: 16 Apr 10 at 9:22PM |
|
Only my first look ...
You're mixing DA- and non-DA-functions. This won't work. Cheers, Ingo |
|
![]() |
|
Post Reply
|
|
|
Tweet
|
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store