Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
4
Erster Beitrag:
vor 2 Jahren, 10 Monaten
Letzter Beitrag:
vor 2 Jahren, 10 Monaten
Beteiligte Autoren:
Curtis, Fabrice Harari

[WD19] How to print a multi page pdf.

Startbeitrag von Curtis am 06.04.2015 16:22

IF iConfigure() THEN
IMG_PrintCopy = sTempImageName

sBitmapInfo = BitmapInfo(sTempImageName)
IMG_PrintCopy..Width = ExtractString(sBitmapInfo, 2,TAB)
IMG_PrintCopy..Height = ExtractString(sBitmapInfo, 3,TAB)

FOR i = 1 _TO_ IMG_PrintCopy..NumberPage
IMG_PrintCopy..PageNumber = i
iPrintImage(IMG_PrintCopy,0,0,IMG_PrintCopy..Width,IMG_PrintCopy..Height)

IF i < IMG_PrintCopy..NumberPage THEN
iSkipPage()
END
END
iEndPrinting()
END

This code only prints the first page. If there are 4 pages it will print the first page 4 times. How should this be done. I found an old example at the link below, but there has to be a better way. Also, if I use the method below, the image quality gets worse when saving to another image format to print.


http://27130.foren.mysnip.de/read.php?27131,35151,35157#msg-35157

Antworten:


IF iConfigure() THEN
// Include the PDF in a temporary image
HExtractMemo(CustomerDoc,Doc,sTempFile)
IMG_PrintCopy = sTempFile

// Resize the image control
sBitmapInfo = BitmapInfo(sTempFile)
IMG_PrintCopy..Width = ExtractString(sBitmapInfo, 2,TAB)
IMG_PrintCopy..Height = ExtractString(sBitmapInfo, 3,TAB)

FOR i = 1 _TO_ IMG_PrintCopy..NumberPage
IMG_PrintCopy..PageNumber = i
sTempImage = sTempDir + ["\"] + i + "_pdf.jpg"

// // Save the image
dSaveImageJPEG(IMG_PrintCopy,sTempImage,100)

// Print the image
iPrintImage(sTempImage,0,0,IMG_PrintCopy..Width,IMG_PrintCopy..Height)

IF i < IMG_PrintCopy..NumberPage THEN
iSkipPage()
END
END
iEndPrinting()

// Delete the temporary images
FOR i = 1 _TO_ IMG_PrintCopy..NumberPage
sTempImage = sTempDir + ["\"] + i + "_pdf.jpg"
fDelete(sTempImage)
END

IMG_PrintCopy = ""
END


This code actually works fine and the quality is good, but it places a border around each page. Any idea how to get rid of that? Seems like a size paramater issue?

von Curtis - am 06.04.2015 17:31
Hi Curtis,

1rst, a remark. I think that you should do this:
// Resize the image control
sBitmapInfo = BitmapInfo(sTempFile)
IMG_PrintCopy..Width = ExtractString(sBitmapInfo, 2,TAB)
IMG_PrintCopy..Height = ExtractString(sBitmapInfo, 3,TAB)

before doing that:
IMG_PrintCopy = sTempFile

This will allow the image to be loaded AS IS, without any resizing that would create a lowering in quality.

2nd, about your question.... 2 things :
1. you are printing the image according to its original size:iPrintImage(sTempImage,0,0,IMG_PrintCopy..Width,IMG_PrintCopy..Height)
You should be printing according to the paper size, if you do not want any border
2. I do not see any code to modify the print driver margins... therefore, it is possible that your border is just that... And if it is the case, be aware that a lot of printer have what is a called a "technical" margin, which is an area where printing is not possible for technical reason (moving the paper, mostly)... So even if you set the margin to 0,0,ipagewidth,ipageheight, you may STILL have a border, the technical margin

Best regards

von Fabrice Harari - am 06.04.2015 18:05
Thanks.

iParameter(iPaperSize, iPaperSize_Letter) seems to make everything look better. I also made sure to remove the border from the IMG_PrintCopy control.

So there isn't a way to do this without saving each pdf page to a jpg file?

von Curtis - am 06.04.2015 19:59
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.