I'm trying to create a PDF from the scratch using GemBoxPdf
using (var document = new PdfDocument())
{
// Add a page.
var page = document.Pages.Add();
page.Rotate = 90;
// Write a text.
using (var formattedText = new PdfFormattedText())
{
formattedText.Append("Hello World!");
page.Content.DrawText(formattedText, new PdfPoint(100, 700));
}}
I'd like to change the size of the page to be able to set it as A1,A2,A3 or A4 or custom size
I've tried to set the cropBox but it does not work.
I've seen another questions of how to do it with spreedsheet but using its PrintOptions I am also unable to change its size
How do I modify the page size ?
Thanks
Related
I'm interested in seeing if I can modify some XMP within an image file. I'm using the following code:
var items = MetadataExtractor.ImageMetadataReader.ReadMetadata(_filename);
foreach (var item in items)
{
if(item.Name == "XMP")
{
var y = new XmpCore.Impl.XmpMeta();
var xmp = item as MetadataExtractor.Formats.Xmp.XmpDirectory;
foreach(var xd in xmp.XmpMeta.Properties)
{
if(xd.Path == "drone-dji:AbsoluteAltitude")
{
var alt = Convert.ToDecimal(xd.Value.Substring(1,xd.Value.Length-1));
alt -= 100;
xmp.XmpMeta.SetProperty(xd.Namespace, xd.Path, alt.ToString());
}
}
xmp.SetXmpMeta(xmp.XmpMeta);
}
}
I know I'm missing something breathtakingly obvious but I don't know this library well enough to figure it out.
No exceptions come up but when I open up the file the XMP field is still the same. When I iterate thru the xmp properties after I set the property it does reflect correctly but when I end the program the file stays the same. I'm sure there's something to do with writing back to the image path but I have no idea where in this library I do that. Any help would be greatly appreciated.
MetadataExtractor doesn't support modifying files. You can update the data structure, as you show, but there's no way to write those changes back to your original file.
I am making an app that started with the CEFSharp minimal example code and I am using ChromeTabs in Wpf. I have my CEFSharp diverting popup windows into tabs correctly but I am having an issue grabbing the URL of these dynamic CEFSharp windows. For some reason AddressChanged is not exposed for these dynamic windows. I have tried to make use of LoadingStateChanged to place the URL in a textbox but that creates all new issues with the threads. I have spent the past few days trying to get this to work and it is driving me crazy. This is how my new tab is created but it does not expose AddressChanged event.
int counttabs = tbControlRCI.Items.Count-1;
string popURL;
popURL = popup_request;
tbControlRCI = this.etTabCntrlRCI;
//here we should open a new tab and place a new rcibrowser in it and give it the url
RCIBrowser = new ChromiumWebBrowser(popURL);
RCIBrowser.Name = "RCIBrow_" + counttabs;
string shorturl = popURL.Substring(popURL.LastIndexOf("/"), popURL.Length - popURL.LastIndexOf("/"));
ChromeTabs.ChromeTabItem newTabItem = new ChromeTabs.ChromeTabItem
{
Header = shorturl,
Name = "RCITab_" + counttabs,
Content = RCIBrowser
};
LifespanHandler lifeRCI = new LifespanHandler();
RCIBrowser.LifeSpanHandler = lifeRCI;
lifeRCI.popup_request += life_popup_request;
tbControlRCI.Items.Add(newTabItem);
tbControlRCI.SelectedIndex = tbControlRCI.Items.Count - 1;
My XAML only has a ChromeTabsControl that I place all of these dynamic Tabs and Browsers into.
Can anyone show the error of my ways?
EDIT:
Ok, thanks amaitland, I have tried a few different ways to do that and it just does not update for some reason. All I need is a textbox to show the address the Browser is on, so one way is fine. So I tried this:
Binding b = new Binding();
b.Mode = BindingMode.OneWay;
b.Path = new PropertyPath("Address");
b.ElementName = "RCIBrowser";
txtbxRCI.SetBinding(TextBox.TextProperty, b);
Thanks a bunch,
Hometownnerd
I want to convert the pdf file into images. I am using ImageMagick for image conversion in cakePHP.
When I take a PDF with a single page, its gets converted into image but the problem is when I take a PDF with multiple pages, then only the last page of the document is getting converted to image, instead of all pages.
How can I fix this?
This is the code I have.
public function convertToImage() {
$this->layout = "ajax";
$uploadfile=APP.WEBROOT_DIR.DS.'files'.DS.$this->request->data['f'];
$uploaddir=APP.WEBROOT_DIR.DS.'files'.DS.'images'.DS;
$im = new imagick();
$im->setResolution(80,80);
$im->readimage($uploadfile);//."[0]");
$im->setImageFormat('jpeg');
$image_name = $this->request->data['f'].".jpg";
$imageprops = $im->getImageGeometry();
if ($imageprops['width'] <= 1275 && $imageprops['height'] <= 1650) {
// don't upscale
} else {
$im->resizeImage(1275,1650, imagick::FILTER_LANCZOS, 0.9, true);
}
$im->writeImage($uploaddir .$image_name);
$im->clear();
$im->destroy();exit;
}
You can access each page by
$im->readimage($uploadfile."[".$pageNumber."]");
With imagemagick you can also read how many pages there are in a pdf:
$document = new Imagick('document.pdf');
$document->getNumberImages();
With this number you can iterate over each page and save an image.
As stated here: http://php.net/manual/en/class.imagick.php#111197 the pointer of imagemagick is set to the last page when used with pdfs.
So, I have a LoaderMax instance loading images from various URLs. I want to add all loaded images to an array.
Here's my code:
var photosArray:Array = new Array(5);
var imageLoadingQueue:LoaderMax = new LoaderMax({name:"mainQueue", onComplete:completeHandler});
for (var g:uint=0; g<5; g++)
{
imageLoadingQueue.append(new ImageLoader("/img" + g + ".jpg", {name:"photo", container:photosArray[g], noCache:false, smoothing:true, width:126, height:126, scaleMode:"proportionalOutside"}));
}
imageLoadingQueue.load();
private function completeHandler(e:LoaderEvent):void
{
trace("finished loading pictures!");
//the next two lines will return an error (saying that photosArray[1] is null)
stage.addChild(photosArray[1]);
photosArray[1].x = 250;
}
A few problems:
If I set the container of the image being loaded to the Array, it won't work. I'm not being able to access the image inside the array because it says it's null.
If I set the container of the image being loaded to "this" (using the container property when appending a new ImageLoader) and, on the completeHandler, set my array equal to event.target.content, it kinda works (but it's not the ideal). The problem is that, by doing so, the images are appearing on the stage as they are loaded, and I do no want them to do so.
Any help would be heavily appreciated.
Thanks!!
David is correct, but I also wanted to mention that the LoaderMax's "content" is actually an array of all of its children's content, so you could just use that for simplicity. Keep in mind that ImageLoaders automatically create a Sprite (technically called a "ContentDisplay") to drop the image into so you probably don't need to create ANOTHER Sprite (a container for the container).
var photos:Array = imageLoadingQueue.content;
stage.addChild(photos[1]);
The other nice thing is that it creates the ContentDisplay Sprites immediately, even before any content is loaded into them, so you can place them and size them however you want while (or before or after) loading occurs.
The container needs to be a DisplayObjectContainer. ImageLoader will try to add the image to the container using addChild(), so obviously this won't work with an empty array. Create a new Sprite for each image and add it into the array first:
for (var g:uint=0; g<5; g++)
{
photosArray[g] = new Sprite();
imageLoadingQueue.append(new ImageLoader("/img" + g + ".jpg", {name:"photo", container:photosArray[g], noCache:false, smoothing:true, width:126, height:126, scaleMode:"proportionalOutside"}));
}
I have a till roll printer and I want to print on it. I don't need paging but I do need to adjust the page size instead. No matter what code I use the printer page size always uses the settings in the Printer Preferences.
PrinterSettings ps = new PrinterSettings();
ps.DefaultPageSettings.PaperSize = new PaperSize("rec", 200, 900);
System.Windows.Controls.PrintDialog printDialog = new PrintDialog();
MyPaginator paginator = new MyPaginator(print);
paginator.PageSize = new Size(200, 900);
printDialog.PrintDocument(paginator, "My Receipt");
I'm using a DocumentPaginator as I thought this would allow be to be more specific about the page I wanted to print.
How can I set the page size?