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!
![]() |
How to set the background color |
Post Reply ![]() |
Author | |
wjbons ![]() Beginner ![]() Joined: 17 Jun 10 Status: Offline Points: 17 |
![]() ![]() ![]() ![]() ![]() Posted: 01 Nov 10 at 8:44AM |
Hi,
How can I change the background color (normal white) of a loaded pdf document?
|
|
![]() |
|
Dimitry ![]() Team Player ![]() Joined: 18 Feb 10 Status: Offline Points: 37 |
![]() ![]() ![]() ![]() ![]() |
The most common way to set page background color is just to DrawBox() of specified color on it. Here is code snippet that may be useful for you:// QPL: TQuickPDF;
var
colordialog: TColorDialog; begin
colordialog := TColorDialog.Create(nil); if not(colordialog.Execute) then Exit; with QPL do
begin SetOrigin(1); SetFillColor(GetRValue(colordialog.Color)/255, GetGValue(colordialog.Color)/255, GetBValue(colordialog.Color)/255); DrawBox(0, 0, PageWidth, PageHeight, 1); end; colordialog.Free; end;
|
|
Regards,
Dmitry |
|
![]() |
|
wjbons ![]() Beginner ![]() Joined: 17 Jun 10 Status: Offline Points: 17 |
![]() ![]() ![]() ![]() ![]() |
Next code shows what i do (visual studio 2010)
I see that i get a blank area returned, but no color.
Second the box is drawn on top of all content but i do not want to harm the document anyway, i just want to change the background color for all pages...
QP = New PDFLibrary("C:\...\QuickPDFDLL0722.dll")
Result = QP.UnlockKey(LicenseKey) If Result = 1 ThenDim T As Long = Now.Ticks
QP.LoadFromFile( "c:\somefile.pdf") Dim w As Integer = QP.PageWidth() Dim h As Integer = QP.PageHeight()QP.SetOrigin(1) QP.SetFillColor(225, 115, 115) QP.DrawBox(0, 0, w, h, 1) Dim Output() As Byte = QP.RenderPageToString(96, 0, 5) 'png Dim byteStream As IO.MemoryStream = New IO.MemoryStream(Output) Dim Img As New BitmapImageImg.BeginInit() Img.StreamSource = byteStream Img.EndInit() Dim Pic As New Image Pic.Source = Img Pic.Stretch = Stretch.None |
|
![]() |
|
Dimitry ![]() Team Player ![]() Joined: 18 Feb 10 Status: Offline Points: 37 |
![]() ![]() ![]() ![]() ![]() |
While defining colors in QuickPDF Library the values should belong to the range
from 0 to 1, where 0 indicates 0% and 1 indicates 100% of the color. So the code will look like:
QP.SetFillColor(225/255, 115/255, 115/255)
|
|
Regards,
Dmitry |
|
![]() |
|
samuelms ![]() Beginner ![]() Joined: 10 Feb 12 Location: United States Status: Offline Points: 2 |
![]() ![]() ![]() ![]() ![]() |
Just be careful about integer division! :) Perhaps... |
|
![]() |
|
AndrewC ![]() Moderator Group ![]() ![]() Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
![]() ![]() ![]() ![]() ![]() |
Depending on the PDF file this could be quite difficult. You would need to somehow inject the drawing commands for coloured rectangle into the contentstream. The are a couple of ways.
Assuming a 1 page document, here is some pseudocode that might work. QP.LoadFromFile QP.NewPage QP.SelectPage(1) id = QP.CapturePage() QP.SetFillColor(1,0,0) QP.DrawBox(0,0,QP.PageWidth(), QP.PageHeight(), 1) QP.DrawCapturedPage(id ... QP.SaveToFile Some PDF files may draw their own WHITE rectangle as a background before they start drawing so I will not be possible for all PDF files. You might find it easier to let QPL perfrorm the RenderPageToString and then use GDI+ and VB.NET to convert all white pixels to your background colour. Thiis would work reasonably well for most PDF files. Andrew.
|
|
![]() |
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