Quick PDF Library ve PdfiumViewer'dan sgcPDF'ye Geçiş

Foxit, Quick PDF Library'yi 13 Aralık 2021'de kullanımdan kaldırdı ve PdfiumViewer deposu 2 Ağustos 2019'dan beri salt okunur. sgcPDF ikisinin de yerini alır: Delphi exe'nize derlenen saf Pascal ve WinForms için yönetilen C#, dağıtılacak PDF DLL'si yok. Bu kit, Quick PDF Library işlevlerini ve PdfiumViewer sınıflarını sgcPDF ile eşleştirir; kodlar derlenen ve kendi testlerini geçen iki örnekten alınmıştır.

Artık gelişmeyen bir PDF kütüphanesi üzerine kurulu uygulamalar

İki yaygın durum: Quick PDF Library ile PDF dosyaları oluşturan, birleştiren, dolduran ve işleyen bir Delphi uygulaması ve PdfiumViewer ile PDF dosyalarını gösteren bir WinForms uygulaması.

Quick PDF Library'den (Delphi)

Quick PDF Library (Debenu Quick PDF Library, sonra Foxit Quick PDF Library) bir kilit açma anahtarıyla DLL, ActiveX veya LIB olarak gelir ve "seçili" bir belge, sayfa, yazı tipi ve görüntüsü olan tek bir nesne üzerinde çalışır. sgcPDF, nesne modeli olan bir Pascal unit kümesidir: TsgcPDFDocument, TsgcPDFPage, TsgcPDFEditor ve TsgcPDFAcroForm, Delphi 7'den Delphi 13'e kadar.

PdfiumViewer'dan (WinForms)

PdfiumViewer, yerel PDFium kütüphanesini bir PdfViewer denetimi, bir PdfRenderer ve bir PdfDocument içinde sarar. PDF dosyalarını gösterir, arar, işler ve yazdırır. sgcPDF bunların yerine tek bir yönetilen denetim olan TsgcPDFViewerControl'ü koyar ve PdfiumViewer'da hiç olmayanı ekler: PDF dosyaları oluşturma, form doldurma, ek açıklama ekleme ve değişiklikleri kaydetme.

Quick PDF Library. Foxit duyurusu (2026-10-20'de okundu) şöyle diyor: "13 Aralık 2021'den itibaren Foxit aşağıdaki ürünleri kullanımdan kaldıracaktır" ve listedeki ilk ürün Foxit Quick PDF Library (All Platforms). Etkin Bakım ve Destek sözleşmesi olan müşterilere 13 Aralık 2022'ye kadar destek verildi: "Bu tarihten sonra ürün destek sonu durumuna geçecek ve artık desteklenmeyeceksiniz." Foxit'in önerdiği yedekler Windows, Mac, Linux, Android ve iOS için PDF SDK'ları, ActiveX SDK'sı ve .NET SDK paketidir.

PdfiumViewer. GitHub deposu (2026-10-20'de okundu) şunu gösteriyor: "Bu depo sahibi tarafından 2 Ağu 2019'da arşivlendi. Artık salt okunur." README şöyle açıklıyor: "Uzun zamandır buna gerçek anlamda zaman ayıramadım" ve "Bu projeyi düzgün destekleyecek durumda değilim." Ayrıca şunu da belirtiyor: "PdfiumViewer denetimi yerel PDFium kütüphanelerini gerektirir. Bunlar PdfiumViewer NuGet paketine dahil değildir." NuGet paketi en son 6 Kasım 2017'de güncellendi (sürüm 2.13.0) ve net20 hedefler.

Tek PDF Kütüphanesi, Kaynak Kodu Dahil

sgcPDF, sgcUI'nin PDF ürünüdür. Delphi'de ve .NET'te PDF dosyalarını oluşturur, düzenler, doldurur, imzalar, şifreler, işler ve gösterir.

Dağıtılacak PDF DLL'si yok

Delphi'de sgcPDF unit'leri exe'ye derlenir: dağıtılıp kaydedilecek DLL, ActiveX veya LIB yok, kilit açma anahtarı çağrısı da yok. .NET'te sgcPDF yönetilen C#'tır, bu yüzden pdfium.dll ve seçilecek bir x86 veya x64 yerel paketi yoktur: örnek AnyCPU olarak çalışır.

Bir nesne modeli

Her çağrı sayfa nesnesini veya dizinini alır, böylece Quick PDF Library'nin "seçili" durumu ortadan kalkar. İmpozisyon vektör form XObject'leri (AddPageAsForm, DrawForm, DrawFormInRect) kullanır, formlar AcroForm kullanır ve şifreleme AES-256'ya (emAES_256) kadar çıkar.

Düzenleyen bir görüntüleyici

TsgcPDFViewerControl genişliğe, sayfaya veya yüksekliğe sığdırır, görünümü döndürür, arar ve bir iletişim kutusuyla yazdırır; .NET'te PdfiumViewer gibi bir PrintDocument verir. Ayrıca form alanlarını doldurur (FormFilling), fareyle ek açıklama ekler (AnnotationTool) ve metin seçer. Yan görünümler: TsgcPDFThumbnailView, TsgcPDFOutlineView, TsgcPDFCommentsView.

sgcPDF tek başına satılır; Delphi ve C++ Builder'da tek geliştirici için €249'den, .NET için €249'den başlar, tam kaynak kodu ve 1 yıl güncellemeyle gelir ve sgcUI Enterprise ile All-Access paketinin parçasıdır. .NET paketleri aynı özelliklerle NuGet'te ücretsiz Community paketleri olarak da sunulur: esegece.sgcPDF.Community ve esegece.sgcPDF.WinForms.Community. sgcPDF ürün sayfasına bakın.

sgcPDF'de Quick PDF Library İşlevleri

Unit'ler sgcPDF_Types, sgcPDF_Fonts ve sgcPDF_Document; gerektiğinde ek olarak sgcPDF_Editor, sgcPDF_Encryption, sgcPDF_Renderer_GDI ve sgcPDF_Export. sgcPDF sayfa dizinleri 0'dan başlar.

Quick PDF Library sgcPDF
UnlockKeykodda çağrılacak bir şey yok
NewDocumentTsgcPDFDocument.Create, ardından AddPage (yeni bir belgenin siz ekleyene kadar sayfası yoktur)
NewPage, SetPageDimensions, SetPageSizeTsgcPDFDocument.AddPage(AWidth, AHeight): TsgcPDFPage, InsertPage(AIndex, AWidth, AHeight)
LoadFromFile, LoadFromStringTsgcPDFDocument.LoadFromFile, LoadFromStream, LoadFromBytes
parolalı LoadFromFileLoadFromFile öncesinde TsgcPDFDocument.SetPassword(APassword)
SaveToFile, SaveToStringTsgcPDFDocument.SaveToFile, SaveToStream, SaveIncremental
PageCountTsgcPDFDocument.PageCount; yalnızca dosya için sgcPDFGetPageCount(AFileName)
SelectPageTsgcPDFDocument.Pages[AIndex] (0'dan başlar, varsayılan özellik), GetPage(AIndex)
SetInformationTsgcPDFDocument.Info.Title, .Author, .Subject, .Keywords, .Creator, .Producer
AddStandardFont + SelectFont + SetTextSize + DrawTextTsgcPDFStandardFont (sfHelvetica, sfTimesRoman, sfCourier ve kalın ile italik varyantları) ile TsgcPDFPage.DrawText(AText, X, Y, AFont, AFontSize)
SetTextColor + DrawTextTsgcPDFPage.DrawTextColor(AText, X, Y, AFont, AFontSize, R, G, B) (bileşenler 0 ile 1 arasında)
AddTrueTypeFont + DrawTextTsgcPDFDocument.AddTrueTypeFont(AFontName, ABold, AItalic): Integer (veya AddTrueTypeFontFromFile), ardından TsgcPDFPage.DrawTextTT
DrawLine, DrawBoxTsgcPDFPage.DrawLine(X1, Y1, X2, Y2, ALineWidth), DrawRectangle(X, Y, W, H, ALineWidth), DrawRectangleFill
AddImageFromFile + SelectImage + DrawImageTsgcPDFDocument.AddImage(AFileName): Integer + TsgcPDFPage.DrawImageFromIndex(AIndex, X, Y, W, H), veya DrawImageFile(AFileName, X, Y, W, H)
GetPageTextTsgcPDFDocument.ExtractTextW(APageIndex), ExtractText, FindText; TsgcPDFEditor.ExtractAllText, SearchText
AddToFileList + MergeFileListsgcPDFMergeFiles([...], AOutputFile)
MergeDocumentTsgcPDFDocument.AppendDocument(ADoc), TsgcPDFEditor.MergeFrom(AFileName)
ExtractPageRanges, ExtractFilePagessgcPDFExtractPages(AInputFile, AOutputFile, ARange) ('1,3,5-9' gibi 1'den başlayan aralık dizesi), TsgcPDFEditor.ExtractPages(ARange, AOutputFileName)
DeletePagesTsgcPDFDocument.DeletePages(ARange), DeletePage(AIndex)
RotatePageTsgcPDFEditor.RotatePage(AIndex, ADegrees)
SetTransparency + DrawText (filigran)TsgcPDFEditor.AddWatermarkAllPages(TsgcPDFWatermarkOptions), AddWatermark, AddTransparentText
her sayfada DrawText (damga, üst bilgi, alt bilgi)TsgcPDFEditor.AddTextColor, AddHeaderText, AddFooterText, AddPageNumbers
RenderPageToDCTsgcPDFRendererGDI.RenderPage(ADC, ADocument.Parser, APage.PageDict, AWidth, AHeight); VCL görüntüleyicide TsgcPDFViewerControl.RenderPageToBitmap
RenderPageToFileTsgcPDFExporter.ExportPage(ADocument, APageIndex, AFileName) (BMP, PNG, JPEG), sgcPDFPageToImage(APDFFile, AImageFile, APageIndex, ADPI)
FormFieldCount, FindFormFieldByTitleTsgcPDFDocument.AcroForm.FieldCount, AcroForm.FindField(AName)
SetFormFieldValue, SetFormFieldValueByTitleAcroForm.FillField(AName, AValue), AcroForm.SetCheckBox(AName, AChecked), TsgcPDFEditor.FillFormField
GetFormFieldValueAcroForm.GetFieldValue(AName)
NewFormFieldAcroForm.AddTextField, AddCheckBox, AddComboBox, AddListBox, AddRadioGroup + AddRadioButton, AddButton, AddSignatureField
FlattenFormFieldAcroForm.FlattenFields, TsgcPDFEditor.FlattenForm
EncryptemAES_256, emAES_128, emRC4_128 veya emRC4_40 ile TsgcPDFDocument.SetEncryption(AMethod, AUserPassword, AOwnerPassword)
CapturePageTsgcPDFDocument.AddPageAsForm(ASource, APageIndex): Integer (sayfa kutusu, dikdörtgen veya ek açıklamalı aşırı yüklemeler)
DrawCapturedPageTsgcPDFPage.DrawForm(AFormIndex, X, Y, AScaleX, AScaleY, ARotation), DrawFormInRect(AFormIndex, ATarget, AKeepAspect, ARotation), DrawFormMatrix
GetPageBoxTsgcPDFPage.GetPageBox(ABox) (ppbTrimBox, ppbBleedBox, ...), TsgcPDFDocument.GetFormBBox
NewOutlineTsgcPDFEditor.AddBookmark(ATitle, APageIndex), AddBookmarkChild
AddLinkToPageTsgcPDFEditor.AddLinkAnnotation(APageIndex, ALeft, ABottom, ARight, ATop, ADestPage)
AddNoteAnnotationTsgcPDFEditor.AddTextAnnotation(APageIndex, ALeft, ABottom, ARight, ATop, AText)
SignFileTsgcPDFEditor.SignDocument(AOutputFile, ACertSubjectName, AReason, ALocation)
PrintDocumentVCL görüntüleyici TsgcPDFViewerControl.Print(AFromPage, AToPage, ATitle) iletişim kutusu olmadan yazdırır, PrintDialog(ATitle) yazıcı iletişim kutusunu (sayfa aralığı, kopya sayısı) gösterir ve yazdırır. FireMonkey görüntüleyici TsgcPDFViewerFMX, Windows ve macOS'ta aynı iki yönteme sahiptir.
SetMeasurementUnits(0), SetOrigin(0)varsayılan ve tek koordinat sistemi: nokta birimi, başlangıç sol altta; yardımcılar sgcPDFMMToPoints, sgcPDFRectMM

Delphi görüntüleyicilerinde ayrıca: yüksekliğe sığdırma yakınlaştırması (TsgcPDFViewerControl üzerinde zmFitHeight, TsgcPDFViewerFMX üzerinde fzmFitHeight, TsgcPDFViewer üzerinde ZoomFitHeight) ve görünüm döndürme (ViewRotation, RotateLeft, RotateRight); görünümü döndürür, belgeyi değiştirmez.

sgcPDF'de Yaygın Quick PDF Library İşleri

Her alıntı MigrateFromQuickPDF demosundan kopyalanmıştır; demo Delphi 7 (Win32) ve Delphi 13 (Win32 ve Win64) ile derlenir ve kendi testini geçer. Yorumlar, her satırın yerini aldığı Quick PDF Library çağrılarını belirtir.

uses yan tümcesi

Quick PDF Library içe aktarma unit'i ve DLL ortadan kalkar. Bu unit'ler demonun her işini kapsar:

frmMain.pas
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, ShellAPI,
  // sgc
  sgcPDF_Types, sgcPDF_Fonts, sgcPDF_Document, sgcPDF_Encryption,
  sgcPDF_Editor, sgcPDF_Renderer_GDI;

Metin, kutu ve görüntü içeren bir belge oluşturma

NewDocument, SetInformation, AddStandardFont, SelectFont, SetTextSize, SetTextColor, DrawText, DrawBox, AddImageFromFile, SelectImage, DrawImage ve SaveToFile çağrılarının yerini alır.

frmMain.pas
oDoc := TsgcPDFDocument.Create;
try
  // SetInformation(1, ...) / SetInformation(2, ...)
  oDoc.Info.Title := 'Created with sgcPDF';
  oDoc.Info.Author := 'Migration sample';
  // NewDocument creates page 1, sgcPDF adds every page explicitly
  oPage := oDoc.AddPage(CS_A4_WIDTH, CS_A4_HEIGHT);
  // AddStandardFont(4) + SelectFont + SetTextSize(28) + DrawText
  oPage.DrawText('Hello from sgcPDF', 72, 760, sfHelveticaBold, 28);
  // SetTextColor(r, g, b) + DrawText
  oPage.DrawTextColor('No DLL, pure Pascal.', 72, 725, sfHelvetica, 14,
    0.1, 0.3, 0.7);
  // SetLineColor + SetLineWidth + DrawBox(x, y, w, h, 0)
  oPage.DrawRectangle(72, 520, 260, 120, 1.5);
  // AddImageFromFile + SelectImage + DrawImage(x, y, w, h)
  vImage := oDoc.AddImage(OutFile('logo.bmp'));
  oPage.DrawImageFromIndex(vImage, 102, 540, 200, 80);
  oDoc.SaveToFile(OutFile('created.pdf'));
finally
  oDoc.Free;
end;

Bir sayfanın metnini çıkarma

LoadFromFile, PageCount, SelectPage ve GetPageText çağrılarının yerini alır. Sayfa dizininin 0'dan başladığına dikkat edin.

frmMain.pas
oDoc.LoadFromFile(OutFile('input_a.pdf'));
Log('Extract text: input_a.pdf has ' + IntToStr(oDoc.PageCount) +
  ' pages');
// SelectPage(2) + GetPageText(0): sgcPDF page indexes are 0-based
vText := string(oDoc.ExtractTextW(1));
Log(vText);

Birleştirme ve bölme

AddToFileList ile MergeFileList'in ve ExtractPageRanges veya ExtractFilePages çağrılarının yerini alır. Aralık dizeleri 1'den başlamaya devam eder.

frmMain.pas
sgcPDFMergeFiles([OutFile('input_a.pdf'), OutFile('input_b.pdf')],
  OutFile('merged.pdf'));
frmMain.pas
// 1-based range string, the same syntax as Quick PDF Library
sgcPDFExtractPages(OutFile('merged.pdf'), OutFile('pages_2-3.pdf'), '2-3');
// one file per page: split
sgcPDFExtractPages(OutFile('merged.pdf'), OutFile('page_4.pdf'), '4');

Her sayfaya filigran ve damga

Sayfalar üzerindeki bir döngüde SelectPage, SetTransparency, SetTextColor ve DrawText çağrılarının yerini alır.

frmMain.pas
oEditor.LoadFromFile(OutFile('input_a.pdf'));
vOptions.Text := 'CONFIDENTIAL';
vOptions.Font := sfHelveticaBold;
vOptions.FontSize := 72;
vOptions.Rotation := 45;
vOptions.Opacity := 0.3;
vOptions.R := 0.8;
vOptions.G := 0.1;
vOptions.B := 0.1;
oEditor.AddWatermarkAllPages(vOptions);
// a stamp in the top right corner of every page
for i := 0 to oEditor.Document.PageCount - 1 do
  oEditor.AddTextColor(i, 'APPROVED', 440, 800, sfHelveticaBold, 16,
    0.0, 0.5, 0.0);
oEditor.SaveToFile(OutFile('watermarked.pdf'));

Bir sayfayı aygıt bağlamına işleme

RenderPageToDC çağrısının yerini alır. İşleyici, yüklenen belgenin Parser nesnesini ve sayfanın PageDict nesnesini alır.

frmMain.pas
oDoc.LoadFromFile(OutFile('created.pdf'));
oPage := oDoc.Pages[0];
// 96 DPI: points are 1/72 inch
vScale := 96 / 72;
vW := Round(oPage.Width * vScale);
vH := Round(oPage.Height * vScale);
oBitmap.PixelFormat := pf24bit;
oBitmap.Width := vW;
oBitmap.Height := vH;
oBitmap.Canvas.Brush.Color := clWhite;
oBitmap.Canvas.FillRect(Rect(0, 0, vW, vH));
oRenderer.RenderPage(oBitmap.Canvas.Handle, oDoc.Parser, oPage.PageDict,
  vW, vH);
GdiFlush;
oBitmap.SaveToFile(OutFile('created_page1.bmp'));

Bir formu doldurma

FormFieldCount, FindFormFieldByTitle ve SetFormFieldValue çağrılarının yerini alır.

frmMain.pas
oDoc.LoadFromFile(OutFile('form.pdf'));
Log('Fill form: form.pdf has ' + IntToStr(oDoc.AcroForm.FieldCount) +
  ' fields');
oDoc.AcroForm.FillField('Customer', 'ACME Corporation');
oDoc.AcroForm.FillField('Amount', '1250.00');
oDoc.AcroForm.SetCheckBox('Paid', True);
oDoc.SaveToFile(OutFile('form_filled.pdf'));

AES-256 ile şifreleme ve parolayla açma

Encrypt ve parolalı LoadFromFile çağrılarının yerini alır.

frmMain.pas
oDoc.LoadFromFile(OutFile('input_a.pdf'));
oDoc.SetEncryption(emAES_256, CS_USER_PASSWORD, CS_OWNER_PASSWORD);
oDoc.SaveToFile(OutFile('encrypted.pdf'));
frmMain.pas
oDoc.SetPassword(CS_USER_PASSWORD);
oDoc.LoadFromFile(OutFile('encrypted.pdf'));
vText := string(oDoc.ExtractTextW(0));

2-up impozisyon

CapturePage, NewPage, SetPageDimensions ve DrawCapturedPage çağrılarının yerini alır. AddPageAsForm her kaynak sayfayı form XObject olarak tutar, böylece metin vektör ve seçilebilir kalır.

frmMain.pas
oSource.LoadFromFile(OutFile('merged.pdf'));
vHalf := CS_A4_HEIGHT / 2;
oSheet := nil;
for i := 0 to oSource.PageCount - 1 do
begin
  // a landscape A4 sheet for every 2 source pages
  if i mod 2 = 0 then
    oSheet := oTarget.AddPage(CS_A4_HEIGHT, CS_A4_WIDTH);
  // CapturePage
  vForm := oTarget.AddPageAsForm(oSource, i);
  // DrawCapturedPage, scaled to fit the left or the right half
  oSheet.DrawFormInRect(vForm, sgcPDFRect((i mod 2) * vHalf, 0,
    (i mod 2) * vHalf + vHalf, CS_A4_WIDTH), True);
end;
oTarget.SaveToFile(OutFile('imposed_2up.pdf'));

sgcPDF'de PdfiumViewer Sınıfları

Ad alanı esegece.sgcPDF, paket esegece.sgcPDF.WinForms. Sayfa dizinleri iki kütüphanede de 0'dan başlar.

PdfiumViewer sgcPDF .NET
PdfViewer (araç çubuğu ve yer imi bölmesi olan UserControl)TsgcPDFViewerControl; araç çubuğunu kendiniz oluşturun, yer imleri TsgcPDFOutlineView içinde
PdfRenderer (PdfViewer.Renderer)aynı TsgcPDFViewerControl
PdfViewer.Document = PdfDocument.Load(path)TsgcPDFViewerControl.LoadFromFile(path) (belgenin sahibi görüntüleyicidir), LoadFromStream veya Document = vDoc (serbest bırakmak size ait)
PdfDocument.Load(path, password)LoadFromFile öncesinde TsgcPDFDocument.SetPassword, ardından TsgcPDFViewerControl.Document = vDoc
PdfDocument.PageCountTsgcPDFViewerControl.PageCount (özellik), TsgcPDFDocument.PageCount() (yöntem)
PdfDocument.PageSizesTsgcPDFDocument.GetPage(i).Width ve .Height (nokta)
PdfRenderer.PageTsgcPDFViewerControl.PageIndex, GotoPage, NextPage, PrevPage, FirstPage, LastPage, olay OnPageChange
PdfViewerZoomMode.FitWidthZoomMode = TsgcPDFViewerZoomMode.zmFitWidth
PdfViewerZoomMode.FitHeightTsgcPDFViewerZoomMode.zmFitHeight
PdfViewerZoomMode.FitBestTsgcPDFViewerZoomMode.zmFitPage
Zoom (bir çarpan, 1.0 = %100)TsgcPDFViewerControl.Zoom (yüzde, 100 = %100, zmCustom ayarlar), ZoomIn, ZoomOut, zmActualSize, ZoomToRect
PdfRenderer.RotateLeft(), RotateRight()TsgcPDFViewerControl.RotateLeft(), RotateRight()
PdfRenderer.RotationTsgcPDFViewerControl.ViewRotation (TsgcPDFViewerRotation: pvr0, pvr90, pvr180, pvr270); PageRotation(i) gösterilen dönüşü döndürür
PdfDocument.Search(text, matchCase, wholeWord) + PdfRenderer.MarkersTsgcPDFViewerControl.FindText(AText, ACaseSensitive, AWholeWord) (vurgular ve kaydırır), FindNext, FindPrevious, SearchResults, GetSearchMatch(i), ClearSearch
PdfDocument.CreatePrintDocument() + PrintDialog veya PrintPreviewDialogTsgcPDFViewerControl.CreatePrintDocument(), aynı PrintDialog ve PrintPreviewDialog kodu için bir System.Drawing.Printing.PrintDocument döndürür. Tek çağrıda: PrintDialog(ATitle); iletişim kutusu olmadan: Print(AFromPage, AToPage, ATitle)
PdfDocument.Render(page, dpiX, dpiY, forPrinting)TsgcPDFViewerControl.RenderPageToBitmap(APageIndex, ref Bitmap, AZoomPercent, ADPI); görüntüleyici olmadan sgcPDF_Export.sgcPDFPageToImage veya TsgcPDFExporter.ExportPage
PdfDocument.GetPdfText(page)TsgcPDFDocument.ExtractTextW(APageIndex); karakter konumlarıyla TsgcPDFViewerControl.PageText(i); fareyle seçim SelectedText, CopyToClipboard
PdfDocument.BookmarksTsgcPDFOutlineView
PdfViewer.LinkClickTsgcPDFViewerControl.OnLinkClick, OpenLinksInBrowser
PdfDocument.Save(path)TsgcPDFDocument.SaveToFile, SaveIncremental(AFileName) (özgün baytları korur ve değişiklikleri ekler)
karşılığı yok: form doldurmaTsgcPDFViewerControl.FormFilling = true, OnFieldChange; kodda AcroForm.FillField, SetCheckBox, GetFieldValue, FindField
karşılığı yok: ek açıklamalarTsgcPDFDocument.Annotations.AddText, AddFreeText, AddHighlight, AddStamp, AddLine, AddSquare, AddCircle, ardından AnnotationsChanged(); fareyle AnnotationTool ve AnnotationEditing
karşılığı yok: PDF oluşturmaTsgcPDFDocument.AddPage, TsgcPDFPage.DrawText, DrawRectangle, AcroForm.AddTextField, AddCheckBox, SaveToFile

sgcPDF Görüntüleyicisiyle Bir PdfiumViewer Formu

Her alıntı MigrateFromPdfiumViewer demosundan kopyalanmıştır; demo Release olarak derlenir ve kendi testini geçer. Yorumlar, her bloğun yerini aldığı PdfiumViewer kodunu aktarır.

PdfViewer ve PdfRenderer yerine tek denetim

MainForm.cs
// PdfiumViewer: PdfViewer (UserControl with toolbar) and its PdfRenderer (the page
// surface, PdfViewer.Renderer) -> one control, TsgcPDFViewerControl
private TsgcPDFViewerControl FViewer;
MainForm.cs
FViewer = new TsgcPDFViewerControl();
FViewer.Parent = pnlViewer;
FViewer.Dock = DockStyle.Fill;
// PdfiumViewer: PdfRenderer.DisplayRectangleChanged / polling PdfRenderer.Page -> OnPageChange
FViewer.OnPageChange = DoPageChange;
// PdfiumViewer: none, PdfiumViewer renders form fields but cannot edit them.
// sgcPDF: the user types into text fields and toggles check boxes in the viewer
FViewer.FormFilling = true;
FViewer.OnFieldChange = DoFieldChange;
// PdfiumViewer: none. sgcPDF: AnnotationTool adds notes, highlights, shapes, ink
// and stamps with the mouse; AnnotationEditing moves, resizes and deletes them
FViewer.AnnotationAuthor = "sgcPDF demo";

Bir dosya açma

MainForm.cs
// PdfiumViewer: pdfViewer1.Document = PdfDocument.Load(AFileName)
// sgcPDF: the viewer loads and owns the document; to share a document you load
// yourself, assign it: FViewer.Document = vDoc (you dispose it)
FViewer.LoadFromFile(AFileName);
// PdfiumViewer: PdfViewer.ZoomMode = PdfViewerZoomMode.FitWidth
FViewer.ZoomMode = TsgcPDFViewerZoomMode.zmFitWidth;
// PdfiumViewer: PdfDocument.PageCount -> TsgcPDFViewerControl.PageCount
// (or TsgcPDFDocument.PageCount(), a method)
Log("Opened " + Path.GetFileName(AFileName) + ", " + sgcPDF_RTL.IntToStr(FViewer.PageCount) + " pages");

Yakınlaştırma modları ve görünüm döndürme

Genişliğe sığdır, sayfaya sığdır ve yüksekliğe sığdır birebir eşleşir. Yakınlaştırma çarpan yerine yüzdedir.

MainForm.cs
internal void FitWidth()
{
    // PdfiumViewer: PdfViewerZoomMode.FitWidth -> TsgcPDFViewerZoomMode.zmFitWidth
    FViewer.ZoomMode = TsgcPDFViewerZoomMode.zmFitWidth;
}

internal void FitPage()
{
    // PdfiumViewer: PdfViewerZoomMode.FitBest -> TsgcPDFViewerZoomMode.zmFitPage
    FViewer.ZoomMode = TsgcPDFViewerZoomMode.zmFitPage;
}

internal void FitHeight()
{
    // PdfiumViewer: PdfViewerZoomMode.FitHeight -> TsgcPDFViewerZoomMode.zmFitHeight
    FViewer.ZoomMode = TsgcPDFViewerZoomMode.zmFitHeight;
}

internal void RotateLeft()
{
    // PdfiumViewer: PdfRenderer.RotateLeft() -> TsgcPDFViewerControl.RotateLeft()
    // (ViewRotation turns the view only, the document is not changed)
    FViewer.RotateLeft();
}

internal void RotateRight()
{
    // PdfiumViewer: PdfRenderer.RotateRight() -> TsgcPDFViewerControl.RotateRight()
    FViewer.RotateRight();
}

internal void SetZoomPercent(double APercent)
{
    // PdfiumViewer: PdfRenderer.Zoom is a factor (1.0 = 100%);
    // TsgcPDFViewerControl.Zoom is a percentage (100 = 100%) and sets ZoomMode to zmCustom
    FViewer.Zoom = APercent;
}

Arama

MainForm.cs
// PdfiumViewer: PdfDocument.Search(text, matchCase, wholeWord) returns PdfMatches
// and the app adds PdfMarker objects to PdfRenderer.Markers to highlight them.
// sgcPDF: FindText highlights every match and scrolls to the first one,
// FindNext / FindPrevious move between them, GetSearchMatch(i) gives page and chars
if (!FViewer.FindText(AText, false, false))
{
    Log("Not found: " + AText);
    return 0;
}
for (int i = 0; i < FViewer.SearchResults; i++)
{
    TsgcPDFViewerSearchMatch vMatch = FViewer.GetSearchMatch(i);
    Log("Match " + sgcPDF_RTL.IntToStr(i + 1) + ": page " + sgcPDF_RTL.IntToStr(vMatch.PageIndex + 1) +
      ", char " + sgcPDF_RTL.IntToStr(vMatch.FirstChar));
}
return FViewer.SearchResults;

CreatePrintDocument ile yazdırma

PdfiumViewer yazdırma kodu biçimini korur: CreatePrintDocument(), bir PrintDialog veya PrintPreviewDialog için PrintDocument döndürür.

MainForm.cs
// PdfiumViewer: using (PrintDocument d = PdfDocument.CreatePrintDocument())
//   { PrintDialog dlg = new PrintDialog(); dlg.Document = d; if (dlg.ShowDialog() == OK) d.Print(); }
// sgcPDF: TsgcPDFViewerControl.CreatePrintDocument() returns the same kind of
// System.Drawing.Printing.PrintDocument, so the PdfiumViewer code stays as it is. It honours
// the page range (all, some pages, current page), copies and collate of its PrinterSettings.
// A shorter way: FViewer.PrintDialog(title) shows the dialog and prints in one call, and
// FViewer.Print(from, to, title) prints without a dialog (0-based pages, -1 = last page).
if (FViewer.PageCount == 0)
    return;
using (PrintDocument vDoc = FViewer.CreatePrintDocument())
using (PrintDialog vDialog = new PrintDialog())
{
    vDoc.DocumentName = "PdfiumViewer migration sample";
    vDialog.Document = vDoc;
    vDialog.AllowSomePages = true;
    vDialog.AllowCurrentPage = true;
    vDialog.UseEXDialog = true;
    vDoc.PrinterSettings.MinimumPage = 1;
    vDoc.PrinterSettings.MaximumPage = FViewer.PageCount;
    vDoc.PrinterSettings.FromPage = 1;
    vDoc.PrinterSettings.ToPage = FViewer.PageCount;
    if (vDialog.ShowDialog(this) == DialogResult.OK)
        vDoc.Print();
}
MainForm.cs
// PdfiumViewer: PrintPreviewDialog with PdfDocument.CreatePrintDocument()
// sgcPDF: the same with TsgcPDFViewerControl.CreatePrintDocument()
if (FViewer.PageCount == 0)
    return;
using (PrintDocument vDoc = FViewer.CreatePrintDocument())
using (PrintPreviewDialog vPreview = new PrintPreviewDialog())
{
    vPreview.Document = vDoc;
    vPreview.Width = 900;
    vPreview.Height = 700;
    vPreview.ShowDialog(this);
}

Bir sayfayı bitmap'e işleme

MainForm.cs
// PdfiumViewer: Image img = PdfDocument.Render(page, dpiX, dpiY, forPrinting)
// sgcPDF: RenderPageToBitmap(page, ref bitmap, zoomPercent, dpi); the bitmap passed
// in is disposed and replaced
Bitmap vBitmap = null;
FViewer.RenderPageToBitmap(APageIndex, ref vBitmap, 100, 150);
try
{
    vBitmap.Save(AFileName, ImageFormat.Png);
    Log("Page " + sgcPDF_RTL.IntToStr(APageIndex + 1) + " rendered at 150 dpi: " +
      sgcPDF_RTL.IntToStr(vBitmap.Width) + " x " + sgcPDF_RTL.IntToStr(vBitmap.Height) + " px, " +
      AFileName);
}
finally
{
    vBitmap.Dispose();
}
// without a viewer (server, batch): one call from file to image
sgcPDF_Export.sgcPDFPageToImage(FViewer.FileName, Path.ChangeExtension(AFileName, null) + "_file.png",
  APageIndex, 72);

Sayfa metni

MainForm.cs
// PdfiumViewer: PdfDocument.GetPdfText(page) returns the plain text of a page.
// sgcPDF: TsgcPDFDocument.ExtractTextW(page) is the same plain text, and
// TsgcPDFViewerControl.PageText(page) returns a TsgcPDFTextExtractor with the
// characters and their positions (GetTextWithPositions); the user can also select
// text with the mouse and copy it (SelectedText, CopyToClipboard)
string vText = FViewer.Document.ExtractTextW(APageIndex);
Log("Text of page " + sgcPDF_RTL.IntToStr(APageIndex + 1) + ": " + vText.Trim());
TsgcPDFTextExtractor vExtractor = FViewer.PageText(APageIndex);
if (vExtractor != null)
    Log("Characters with positions: " + sgcPDF_RTL.IntToStr(vExtractor.GetCharCount()));
return vText;

PdfiumViewer'ın ötesinde: form doldurma ve not ekleme

MainForm.cs
// PdfiumViewer: none (no AcroForm API). sgcPDF: AcroForm.FillField / SetCheckBox,
// then an incremental save keeps the original bytes and appends the change
TsgcPDFDocument vDoc = FViewer.Document;
if (vDoc.AcroForm.FindField("CustomerName") == null)
{
    Log("This document has no CustomerName field, open the generated sample");
    return;
}
vDoc.AcroForm.FillField("CustomerName", "ACME Ltd.");
vDoc.AcroForm.SetCheckBox("Approved", true);
FViewer.ClearCache();
FViewer.Invalidate();
vDoc.SaveIncremental(AFileName);
Log("Form filled and saved: " + AFileName);
MainForm.cs
// PdfiumViewer: none (annotations are only rendered). sgcPDF: the document's
// Annotations manager adds notes, free text, highlights, stamps, lines, shapes and
// ink; the viewer shows them after AnnotationsChanged
TsgcPDFDocument vDoc = FViewer.Document;
int vPage = FViewer.PageIndex;
TsgcPDFTextAnnotation vNote = vDoc.Annotations.AddText(vPage, 420, 760, 444, 784,
  "Migrated from PdfiumViewer to sgcPDF.");
vNote.Author = "sgcPDF demo";
vNote.SetColor(1.0, 0.9, 0.2);
vDoc.Annotations.AddHighlight(vPage, 72, 728, 330, 728, 72, 742, 330, 742);
FViewer.AnnotationsChanged();
vDoc.SaveIncremental(AFileName);
Log("Note and highlight added on page " + sgcPDF_RTL.IntToStr(vPage + 1) + ", saved: " + AFileName);

Adım Adım

Bir seferde bir işi veya bir formu taşıyın ve önceki ile sonraki çıktı dosyalarını karşılaştırın.

Delphi: Quick PDF Library'den

1

Unit'leri ekleyin

sgcPDF Source klasörünü veya kurulu paketi ekleyin ve Quick PDF Library içe aktarmasını sgcPDF_Types, sgcPDF_Fonts ve sgcPDF_Document ile değiştirin; gerektiğinde ek olarak sgcPDF_Editor, sgcPDF_Encryption ve sgcPDF_Renderer_GDI.

2

DLL'yi bırakın

DLL'yi veya ActiveX'i dağıtımdan, UnlockKey çağrısını koddan kaldırın.

3

Belge başına bir nesne

TQuickPDF nesnesini belge başına bir TsgcPDFDocument ile veya yükle, düzenle, kaydet işleri için bir TsgcPDFEditor ile değiştirin.

4

Sayfalar nesnedir

SelectPage ve çizim çağrılarını, AddPage veya Pages[i] ile alınan TsgcPDFPage üzerindeki çağrılarla değiştirin ve her sayfa numarasından 1 çıkarın.

5

Çağrıları eşleştirin

Yukarıdaki tabloyu kullanın. Standart yazı tipleri DrawText bağımsız değişkenidir; TrueType yazı tipleri AddTrueTypeFont ile bir kez eklenir ve DrawTextTT ile çizilir.

6

İmpozisyon

CapturePage ve DrawCapturedPage çağrılarını AddPageAsForm ve DrawForm veya DrawFormInRect ile değiştirin.

7

Çıktıyı karşılaştırın

Dönüştürülen işi çalıştırın ve dosyaları kontrol edin. Demonun kendi testi bir şablondur: her çıktıyı yeniden açar ve sayfa sayılarını, metni ve form değerlerini kontrol eder.

WinForms: PdfiumViewer'dan

1

Yerel parçaları kaldırın

PdfiumViewer paketini, her PdfiumViewer.Native.* paketini ve elle kopyalanmış tüm pdfium.dll dosyalarını, x86 ve x64 klasörleri dahil kaldırın. Proje AnyCPU'ya dönebilir.

2

sgcPDF'yi ekleyin

esegece.sgcPDF.WinForms (veya esegece.sgcPDF.WinForms.Community) paketini ekleyin; esegece.sgcPDF da gelir. Ardından using esegece.sgcPDF; ekleyin.

3

Denetimi değiştirin

PdfViewer veya PdfRenderer yerine bir TsgcPDFViewerControl (Dock = Fill) koyun ve kullandığınız araç çubuğu düğmelerini denetim üzerindeki çağrılar olarak yeniden oluşturun.

4

Belgeyi yükleyin

PdfDocument.Load ve Document = yerine LoadFromFile kullanın veya bir TsgcPDFDocument kendiniz yükleyip Document özelliğine atayın.

5

Üyeleri eşleştirin

Page özelliği PageIndex veya GotoPage olur, yakınlaştırma modları TsgcPDFViewerZoomMode ile eşleşir, yakınlaştırma çarpanı 100 ile çarpılır, Search FindText olur, Render RenderPageToBitmap olur.

6

Yazdırma kodunu koruyun

PdfiumViewer belgesi yerine görüntüleyici üzerinde CreatePrintDocument() çağırın; PrintDialog ve PrintPreviewDialog kodu kalır. Ya da PrintDialog(ATitle) kullanın.

7

Yeni parçaları açın

İsteğe bağlı: PdfiumViewer'ın sunamadığı FormFilling = true, AnnotationTool ve SaveIncremental.

Birebir Eşleşmeyenler

Geçişi planlamadan önce bunu okuyun.

Quick PDF Library

PdfiumViewer

MigrateFromQuickPDF ve MigrateFromPdfiumViewer

Her iki demo da kendi girdi dosyalarını üretir, bu yüzden harici PDF gerekmez ve ikisinin de kendi testi vardır.

Delphi: nerede

sgcUI yükleyicisi bunu Demos\PDF\Delphi\MigrateFromQuickPDF içine koyar: sgcPDF_Demo_MigrateFromQuickPDF.dpr, frmMain.pas, frmMain.dfm ve bir readme.html.

Delphi: nasıl çalıştırılır

.dpr dosyasını 7'den 13'e kadar herhangi bir Delphi'de açın (VCL, Win32 veya Win64), Generate sample inputs düğmesine, ardından herhangi bir düğmeye veya Run all düğmesine tıklayın. Çıktı exe'nin yanındaki output klasörüne gider.

Delphi: kendi testi

sgcPDF_Demo_MigrateFromQuickPDF.exe /selftest [folder] her işi çalıştırır, sonuçları kontrol eder ve SELFTEST OK ile biten selftest.log dosyasını yazar.

.NET: nerede

sgcUI .NET demolarında, sgcUI_Demos.sln çözümünün PDF\MigrateFromPdfiumViewer klasöründe: sgcPDF_Demo_MigrateFromPdfiumViewer.csproj, Program.cs ve MainForm.cs.

.NET: nasıl çalıştırılır

dotnet run --project demos\PDF\MigrateFromPdfiumViewer (Community sürümü için -p:SgcCommunity=true ekleyin), output\sample.pdf dosyasını yazıp açan Generate sample düğmesine, ardından herhangi bir düğmeye tıklayın.

.NET: kendi testi

sgcPDF_Demo_MigrateFromPdfiumViewer.exe /selftest [folder] örneği açar, gezinir, yakınlaştırır, yüksekliğe sığdırır, döndürür, arar, işler, bir baskı önizlemesinin sayfalarını sayar, metin çıkarır, formu doldurur, bir not ekler ve kaydedilen dosyaları yeniden açar. SELFTEST OK ile biten selftest.log dosyasını yazar.

Her iki kütüphaneye de adil olmak gerekirse: Quick PDF Library veya PdfiumViewer üzerine kurulu bir uygulama bugün dağıtıldığı yerde çalışmaya devam eder ve Foxit kendi PDF SDK'larını Quick PDF Library'nin halefleri olarak gösterir. PDF kodunun uygulamanıza derlenen Pascal veya C# kaynağı olmasını, dağıtılacak yerel bir PDF kütüphanesi olmamasını ve görüntüleyicinizin gösterdiği dosyaları ayrıca oluşturan, dolduran, ek açıklama ekleyen, imzalayan ve şifreleyen tek bir API'yi istediğinizde sgcPDF yoldur. Bileşenler ve sürümler için sgcPDF ürün sayfasına bakın.

En avantajlı seçenek: All-AccessTüm eSeGeCe ürünleri, Premium Destek dahil, yılda €1,059'dan itibaren.
All-Access fiyatlarına bakın

İlk PDF İşinizi Bugün Taşıyın

sgcPDF'li sgcUI'yi indirin veya NuGet'ten ücretsiz Community paketlerini ekleyin ve yanında MigrateFromQuickPDF ile MigrateFromPdfiumViewer demolarıyla ilk işinizi veya formunuzu taşıyın.