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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - How to set the background color
  FAQ FAQ  Forum Search   Register Register  Login Login

How to set the background color

 Post Reply Post Reply
Author
Message
wjbons View Drop Down
Beginner
Beginner


Joined: 17 Jun 10
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote wjbons Quote  Post ReplyReply Direct Link To This Post Topic: How to set the background color
    Posted: 01 Nov 10 at 8:44AM
Hi,
How can I change the background color (normal white) of a loaded pdf document?
Back to Top
Dimitry View Drop Down
Team Player
Team Player


Joined: 18 Feb 10
Status: Offline
Points: 37
Post Options Post Options   Thanks (0) Thanks(0)   Quote Dimitry Quote  Post ReplyReply Direct Link To This Post Posted: 01 Nov 10 at 6:19PM

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
Back to Top
wjbons View Drop Down
Beginner
Beginner


Joined: 17 Jun 10
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote wjbons Quote  Post ReplyReply Direct Link To This Post Posted: 02 Nov 10 at 10:41AM
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 Then

Dim 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 BitmapImage

Img.BeginInit()

Img.StreamSource = byteStream

Img.EndInit()

Dim Pic As New Image

Pic.Source = Img

Pic.Stretch = Stretch.None

Back to Top
Dimitry View Drop Down
Team Player
Team Player


Joined: 18 Feb 10
Status: Offline
Points: 37
Post Options Post Options   Thanks (0) Thanks(0)   Quote Dimitry Quote  Post ReplyReply Direct Link To This Post Posted: 02 Nov 10 at 1:36PM
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
Back to Top
samuelms View Drop Down
Beginner
Beginner


Joined: 10 Feb 12
Location: United States
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote samuelms Quote  Post ReplyReply Direct Link To This Post Posted: 15 Jul 12 at 4:02AM
Just be careful about integer division!  :)

Perhaps...

QP.SetFillColor(225/255.0f, 115/255.0f, 115/255.0f)
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 16 Jul 12 at 5:01AM
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.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store